整理資訊

整理 Pixiv 資訊

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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 });
})();