// ==UserScript== // @name 今日热榜界面简化 // @namespace http://tampermonkey.net/ // @version 2.4.2.2 // @description 仅适用于未登录状态的主界面(摸鱼向,仅为简化) 自定义背景颜色 卡片颜色 文字颜色 卡片圆角 卡片高度 修改了图标和标题 自定义卡片布局 去广告 // @author Yesaye // @match *://tophub.today/ // @icon https://www.google.com/s2/favicons?domain=tophub.today // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // @grant GM_openInTab // @grant GM_getValue // @grant GM_setValue // @grant GM_notification // @run-at document-start // @license MIT // @downloadURL none // ==/UserScript== (function () { // 页面样式 let style = ` .abcdefg{display: none;}. bc > :nth-child(-n+2) {display: none;} .nano{transition: all 500ms;} #appbar {display: none !important;} #tabbar {display: none !important;} .cq {display: none !important;} .alert {display: none !important;} .eb-fb {display: none !important;} .c-d {padding: 0px !important;} .cc-cd-lb>img {display: none !important;} .cc-cd-lb>span, .cc-cd-sb-st {font-weight:1 !important;color:#666666} .cc-cd {transition: all 500ms;margin-bottom:1%} body {transition: all 500ms; padding: 20px 0 0 0} .mp::after {border-bottom:none} .cc-cd-ih {border-bottom:none} .cc-cd-if {border-top:none} .bc > div:nth-child(-n+2) {display: none;} .bc-tc {display:none} .bc-cc {padding-bottom: 0;padding-top:0} `; addStyle(style, "setTotalStyle"); style = ""; var backgroundColor = GM_getValue("today_BackgroundColor_value") var cardColor = GM_getValue("today_CardColor_value") var textColor = GM_getValue("today_TextColor_value") var cardRadius = GM_getValue("today_CardRadius_value"); var cardHeight = GM_getValue("today_CardHeight_value"); var lingShowNum = GM_getValue("today_LineShow_value"); if (backgroundColor != null) { style += "body {background-color: " + backgroundColor + " !important;}"; } if (cardColor != null) { style += ".cc-cd {background-color: " + cardColor + " !important;}"; } if (textColor != null) { style += ".cc-cd-cb .cc-cd-cb-l .cc-cd-cb-ll .t {color:" + textColor + "} .cc-cd-cb .cc-cd-cb-l .cc-cd-cb-ll .s {color:" + textColor + "} .cc-cd-cb .cc-cd-cb-l .cc-cd-cb-ll .s.h {color:" + textColor + "} .cc-cd-cb .cc-cd-cb-l .cc-cd-cb-ll .e {color:" + textColor + "} .cc-cd-if .i-h {color:" + textColor + "} .cc-cd-if .i-o {color:" + textColor + "} .cc-cd-lb>span, .cc-cd-sb-st {color:" + textColor + "}"; } addStyle(style, "setColorStyle"); style = ""; if (cardRadius != null) { style += ".cc-cd {border-radius:" + cardRadius + "px !important;}"; } if (cardHeight != null) { style += ".nano {height:" + cardHeight + "px !important;}"; } addStyle(style, "setRadiusStyle"); addStyle(style, "setHeightStyle"); if (lingShowNum != null) { changeLineShow(lingShowNum); } // 更换图标 changeFavicon("https://www.baidu.com/favicon.ico"); // 更换标题 document.title = "百度一下"; function addStyle(style, clazz) { let style_Add = document.createElement('style'); style_Add.className = clazz; if (document.lastChild) { document.lastChild.appendChild(style_Add).textContent = style; } else { // 避免网站加载速度太慢的备用措施 let timer1 = setInterval(function () { // 每 10 毫秒检查一下 html 是否已存在 if (document.lastChild) { clearInterval(timer1); // 取消定时器 document.lastChild.appendChild(style_Add).textContent = style; } }); } } function setStyle(style, clazz) { // 先删掉原来的 removeStyle(clazz); addStyle(style, clazz); } function removeStyle(clazz) { document.querySelectorAll('.' + clazz).forEach((v) => { v.remove() }); } // 更换图标 function changeFavicon(link) { let $favicon = document.querySelectorAll('link[rel*="icon"]'); // If a element already exists, // change its href to the given link. if ($favicon && $favicon.length != 0) { $favicon.forEach(x => { x.href = link; }) } else { $favicon = document.createElement("link"); $favicon.rel = "icon"; $favicon.href = link; document.head.appendChild($favicon); } }; // 更改卡片布局 function changeLineShow(num) { var lineShowNum = (100 - num) / num; GM_setValue("today_LineShow_value", num); setStyle(".cc-cd {width: " + lineShowNum + "% !important;}", "setLineShowStyle"); if (num == 2) { twoLineStyle(); } if (num == 4) { fourLineStyle(); } } function twoLineStyle() { var style = "#twoLineShow {color: #ffffff; background: #37c375; border: none; border-radius: 5px; margin: 2px 0 2px 2px; cursor: pointer;}"; removeStyle("setFourLineButtonStyle"); setStyle(style, "setTwoLineButtonStyle"); } function fourLineStyle() { var style = "#fourLineShow {color: #ffffff; background: #37c375; border: none; border-radius: 5px; margin: 2px 0 2px 2px; cursor: pointer;}"; removeStyle("setTwoLineButtonStyle"); setStyle(style, "setFourLineButtonStyle"); } // 菜单 var menu_ALL = [ ['today_ChangeColor', '主题', '修改页面主题样式', ''] ], menu_ID = []; for (let i = 0; i < menu_ALL.length; i++) { // 如果读取到的值为 null 就写入默认值 if (GM_getValue(menu_ALL[i][0]) == null) { GM_setValue(menu_ALL[i][0], menu_ALL[i][3]) }; } registerMenuCommand(); // 注册脚本菜单 function registerMenuCommand() { if (menu_ID.length > menu_ALL.length) { // 如果菜单ID数组多于菜单数组,说明不是首次添加菜单,需要卸载所有脚本菜单 for (let i = 0; i < menu_ID.length; i++) { GM_unregisterMenuCommand(menu_ID[i]); } } for (let i = 0; i < menu_ALL.length; i++) { // 循环注册脚本菜单 menu_ALL[i][3] = GM_getValue(menu_ALL[i][0]); GM_registerMenuCommand(`${menu_ALL[i][1]}`, function () { menu_setting('checkbox', menu_ALL[i][1], menu_ALL[i][2], [menu_ALL[i + 1], menu_ALL[i + 2], menu_ALL[i + 3], menu_ALL[i + 4]]) }); } } // 脚本设置 function menu_setting(type, title, tips, menu) { let _html = `