// ==UserScript== // @name 吾爱破解桌面版优化 // @namespace http://tampermonkey.net/ // @version 2025-03-18 // @description 为吾爱破解的桌面版网页增加一些便利性功能 // @author wcx19911123 // @match https://www.52pojie.cn/* // @icon https://www.google.com/s2/favicons?sz=64&domain=52pojie.cn // @grant none // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 是否开启调试模式的开关 let debug = false; // 调试函数 let dgb = function(){ debug && [...arguments].forEach(o => console.log(o)); }; // 监听某件事,符合条件就做另一件事的函数 let doWhenThen = function(when, then, duration){ let start = new Date().getTime(); let eventId = setInterval(function(){ if(duration && new Date().getTime() - start > duration){ clearInterval(eventId); return; } 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', '|桌面版优化')); // 添加全局CSS的函数 let addGlobalCSS = function(id, css){ let style = document.querySelector(`#wcx19911123_${id}_CSS`); if(!style){ document.querySelector('head').insertAdjacentHTML('beforeend', ``); } }; // 该脚本的全部功能菜单一览 let settings = { 'hideTop2GatesAnd1Tool': '隐藏页面最顶端的入门和工具', 'hideSubPageBannerText': '隐藏分区版头说明内容', 'hideSubPageTopThreads': '隐藏分区版头所有置顶帖', 'hidePersonalSignature': '隐藏详情页的个人签名', 'autoCheckin': '自动打卡签到', 'autoFoldFreeRating': '自动收起详情贴内的免费评分', }; // 读取该脚本的设置的函数 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', `
`); } 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; }`); } if(setting.hidePersonalSignature){ addGlobalCSS('hidePersonalSignature', ` td.plc.plm div.sign{ display: none !important; }`); } if(setting.autoCheckin){ doWhenThen(function(){ dgb('autoCheckin'); let scoreBtn = document.querySelector('#extcreditmenu'); if(!scoreBtn){ return null; } let checkinBtn = scoreBtn.previousElementSibling.previousElementSibling; if(checkinBtn.tagName !== 'a' || checkinBtn.firstChild.src.indexOf('static/image/common/qds.png') == -1){ return null; } return checkinBtn; }, function(btn){ btn.click(); }, 1000 * 10); } if(setting.autoFoldFreeRating){ window.wcx19911123_already_fold_rate_list = window.wcx19911123_already_fold_rate_list || new Set(); let id = o => o.getAttribute('onclick').match(/\d+/)?.[0]; let has = id => window.wcx19911123_already_fold_rate_list.has(id); let add = o => window.wcx19911123_already_fold_rate_list.add(id(o)); doWhenThen(function(){ let rateList = document.querySelectorAll('table.ratl a.y.xi2.op'); if(!rateList){ return null; } rateList = [...rateList].filter(o => o.innerHTML.indexOf('收起') > -1 && !has(id(o))); rateList.forEach(o => add(o)); return rateList; }, function(aList){ aList.forEach(o => o.click()); }); } })();