pixiv 自動查看差分和評論

pixiv 自動點擊圖片的查看全部和評論的瀏覽更多按鈕

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         pixiv 自動查看差分和評論
// @namespace    pixiv 自動查看差分和評論
// @version      8.0.1
// @description  pixiv 自動點擊圖片的查看全部和評論的瀏覽更多按鈕
// @author       fmnijk
// @match        https://www.pixiv.net/*
// @icon         https://www.google.com/s2/favicons?domain=pixiv.net
// @grant        none
// @license      MIT
// ==/UserScript==

/* $ and $$ */
const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document);

/*----force listen to locationchange work start----*/
history.pushState = ( f => function pushState(){
    var ret = f.apply(this, arguments);
    window.dispatchEvent(new Event('pushstate'));
    window.dispatchEvent(new Event('locationchange'));
    return ret;
})(history.pushState);

history.replaceState = ( f => function replaceState(){
    var ret = f.apply(this, arguments);
    window.dispatchEvent(new Event('replacestate'));
    window.dispatchEvent(new Event('locationchange'));
    return ret;
})(history.replaceState);

window.addEventListener('popstate',()=>{
    window.dispatchEvent(new Event('locationchange'))
});
/*----force listen to locationchange work end----*/

function keeptrying(times, delay) {
    if(times == 0){
        return false;
    }

    if (!window.location.href.includes('/artworks/')) {
        return false;
    }

    // All keywords to match
    // 測試: https://www.pixiv.net/artworks/44298467
    const keywords = [
        /*多張插圖*/
        '查看全部', '查看全部', 'See all', 'すべて見る', '모두 보기',
        /*超長簡介(閱讀後續)*/
        '閱讀後續', '查看后续', 'Continue Reading', '続きを読む', '이어서 읽기',
        /*超長評論(閱讀後續) 和簡介一樣*/
        // '閱讀後續', '查看后续', 'Continue Reading', '続きを読む', '이어서 읽기',
        /*顯示更多評論(瀏覽更多)*/
        '瀏覽更多', '浏览更多', 'See more', 'もっと見る', '더보기',
        /*評論的評論(查看回復)*/
        '查看回復', '查看回复', 'Display Replies', '返信を見る', '답변 보기',

        /*忘了*/
        '查看歷史', '查看历史',
    ];

    // Click all buttons that match keywords
    function clickButtonsWithKeywords() {
        const buttons = $$('main > section > div > div button');
        buttons.forEach(button => {
            const text = button.textContent.trim();
            console.log(text);
            if (keywords.includes(text)) {
                button.click();
            }
        });
    }

    clickButtonsWithKeywords();

    setTimeout(( () => keeptrying(times - 1, delay) ), delay);
}

(window.onload = function () {
    'use strict';
    keeptrying(50, 200);
    window.addEventListener('locationchange', function (){
        keeptrying(50, 200);
    })
})();