整理資訊

整理 Pixiv 資訊

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         整理資訊
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  整理 Pixiv 資訊
// @author       BeenYan
// @match        https://www.pixiv.net/artworks/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=pixiv.net
// @grant        GM_addStyle
// @license      GPL
// ==/UserScript==

GM_addStyle(`
#ctm-info {
    width: 100%;
    height: 13rem;
    color: #eee;
    background: #1F1F1F;
}
`);

function setContent(node) {
    const title = document.querySelector('h1').textContent;
    const content = [...document.querySelector('h1').nextElementSibling.children[0].children[0].childNodes].map(node => node.nodeName === 'BR'? '\n': node.textContent).join('');
    const tag = [...document.querySelectorAll('.gtm-new-work-tag-event-click')].map(x => '#' + x.text).join(' ');

    node.value = `${title}\n\n${content}\n\n${tag}`;
}

(() => {
    const textArea = document.createElement('textarea');
    textArea.id = 'ctm-info';

    const observer = new MutationObserver(() => setContent(textArea));
    const asideObserver = new MutationObserver((mutations, owner) => {
        let image = document.querySelector('.gtm-expand-full-size-illust');
        if (image === null) return;

        console.log('Watch start', image);
        observer.observe(image, {
            childList: true,
            attributes: true,
        });

        const sections = document.querySelectorAll('section');
        setContent(textArea);
        sections[sections.length - 2].append(textArea);
        asideObserver.disconnect();
    });

    asideObserver.observe(document.body, { childList: true });
})();