Greasy Fork

Greasy Fork is available in English.

吾爱破解桌面版优化

为吾爱破解的桌面版网页增加一些便利性功能

当前为 2025-03-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         吾爱破解桌面版优化
// @namespace    http://tampermonkey.net/
// @version      2025-03-17
// @description  为吾爱破解的桌面版网页增加一些便利性功能
// @author       wcx19911123
// @match        https://www.52pojie.cn/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=52pojie.cn
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    let debug = false;
    let dgb = function(){
        debug && [...arguments].forEach(o => console.log(o));
    };
    let doWhenThen = function(when, then){
        let eventId = setInterval(function(){
            let exists = typeof when == 'function' ? when() : when;
            dgb(exists);
            if(exists){
                clearInterval(eventId);
            }else{
                return;
            }
            dgb('then!!');
            exists = then(exists);
        },100);
    };
    doWhenThen(() => document.querySelector('#g_upmine'), o => dgb(o) || o.insertAdjacentHTML('afterend', '<span class="pipe">|</span><a href="javascript:void(0)" onclick="wcx19911123_open_menu();">桌面版优化</a>'));
    let addGlobalCSS = function(id, css){
        let style = document.querySelector(`#wcx19911123_${id}_CSS`);
        if(!style){
            document.querySelector('head').insertAdjacentHTML('beforeend', `<style id="wcx19911123_${id}_CSS">${css}</style>`);
        }
    };
    let settings = {
        'hideTop2GatesAnd1Tool': '隐藏页面最顶端2个入门1个工具',
        'hideSubPageBannerText': '隐藏分区版头说明内容',
        'hideSubPageTopThreads': '隐藏分区版头所有置顶帖',
    };
    let readSetting = function(){
        let setting = localStorage.getItem('wcx19911123_setting');
        if(setting){
            setting = JSON.parse(setting);
        }
        return setting || {};
    };
    window.wcx19911123_open_menu = function(obj){
        addGlobalCSS('menuTop', `
#wcx19911123_open_menu_top{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #fff;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    z-index: 999;
}
#wcx19911123_open_menu_top.close{
    display: none !important;
}`);
        let menuDiv = document.querySelector('#wcx19911123_open_menu_top');
        if(!menuDiv){
            window.wcx19911123_setting = readSetting();
            document.querySelector('body').insertAdjacentHTML('beforeend', `<div id="wcx19911123_open_menu_top">
        <h1>桌面版优化设置</h1>
        ${[...Object.keys(settings)].map(o=>`<input type="checkbox" ${window.wcx19911123_setting[o]?'checked=checked':''} onclick="javascript:window.wcx19911123_setting['${o}']=this.checked;"/>${settings[o]}<br/>`).join('')}
        <input type="button" value="保存" onclick="wcx19911123_saveSetting();"/>
        <input type="button" value="取消" onclick="javascript:document.querySelector('#wcx19911123_open_menu_top').classList.add('close')"/>
</div>`);
        }
        menuDiv?.classList?.remove('close');
    };
    window.wcx19911123_saveSetting = function(){
        localStorage.setItem('wcx19911123_setting', JSON.stringify(window.wcx19911123_setting));
        location.reload();
    }
    let setting = readSetting();
    if(setting.hideTop2GatesAnd1Tool){
        addGlobalCSS('hideTop2GatesAnd1Tool', `
#toptb{
    display: none !important;
}`);
    }
    if(setting.hideSubPageBannerText){
        addGlobalCSS('hideSubPageBannerText', `
#ct > div > div.bm.bml.pbn > div.bm_c.cl.pbn{
    display: none !important;
}`);
    }
    if(setting.hideSubPageTopThreads){
        addGlobalCSS('hideSubPageTopThreads', `
#threadlisttableid tbody[id^=stickthread_]{
    display: none !important;
}`);
    }
})();