pixiv 自動查看差分和評論

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

// ==UserScript==
// @name         pixiv 自動查看差分和評論
// @namespace    pixiv 自動查看差分和評論
// @version      7.7.4
// @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;
    }

    /*插圖*/
    //$('.sc-emr523-0.guczbC > .sc-emr523-2.drFRmD')?.click();
    let e = $('.sc-emr523-0.guczbC > .sc-emr523-2.drFRmD');
    let E = ['查看全部', '모두 보기', 'See all', 'すべて見る'];
    if(E.includes(e?.innerText)){
        e?.click();
    }
    /*簡介*/
    $('.sc-eyxzap-2.bVdNcl > .sc-eyxzap-3.exhRUC')?.click();
    /*評論*/
    $('.sc-4a5gah-0.EdYfe > .sc-4a5gah-1.kHyYuA')?.click();
    /*超長評論(閱讀後續)*/
    $('.sc-eyxzap-2.jnWuRo > .sc-eyxzap-3.iTqlwf')?.click();
    /*評論的評論*/
    $('.sc-4a5gah-0.iuLyik > .sc-4a5gah-1.kHyYuA')?.click();

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

(window.onload = function () {
    'use strict';

    keeptrying(100, 50);

    window.addEventListener('locationchange', function (){
        keeptrying(100, 50);
    })
})();