// ==UserScript== // @name 今日热榜界面简化 // @namespace http://tampermonkey.net/ // @version 2.4.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 // @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 = `
${title}
背景色
卡片色
文字色

卡片圆角
卡片高度

`; document.body.insertAdjacentHTML('beforeend', _html); // 插入网页末尾 setTimeout(function () { // 延迟 100 毫秒,避免太快 // 关闭按钮 点击事件 document.querySelector('.today_SettingClose').onclick = function () { this.parentElement.parentElement.parentElement.remove(); document.querySelector('.today_SettingStyle').remove(); } // 点击周围空白处 = 点击关闭按钮 document.querySelector('.today_SettingBackdrop_2').onclick = function (event) { if (event.target == this) { document.querySelector('.today_SettingClose').click(); }; } // 选取背景色 document.getElementById("pickColor_BackgroundColor").addEventListener("change", function (e) { if (e.target.tagName == "INPUT") { addStyle("body {background-color: " + e.target.value + " !important;}", "setColorStyle"); GM_setValue("today_BackgroundColor_value", e.target.value); backgroundColor = e.target.value; } }) // 选取卡片色 document.getElementById("pickColor_CardColor").addEventListener("change", function (e) { if (e.target.tagName == "INPUT") { addStyle(".cc-cd {background-color: " + e.target.value + " !important;}", "setColorStyle"); GM_setValue("today_CardColor_value", e.target.value); cardColor = e.target.value; } }) // 选取文字色 document.getElementById("pickColor_TextColor").addEventListener("change", function (e) { if (e.target.tagName == "INPUT") { addStyle(".cc-cd-cb .cc-cd-cb-l .cc-cd-cb-ll .t {color:" + e.target.value + "} .cc-cd-cb .cc-cd-cb-l .cc-cd-cb-ll .s {color:" + e.target.value + "} .cc-cd-cb .cc-cd-cb-l .cc-cd-cb-ll .s.h {color:" + e.target.value + "} .cc-cd-cb .cc-cd-cb-l .cc-cd-cb-ll .e {color:" + e.target.value + "} .cc-cd-if .i-h {color:" + e.target.value + "} .cc-cd-if .i-o {color:" + e.target.value + "} .cc-cd-lb>span, .cc-cd-sb-st {color:" + e.target.value + "}", "setColorStyle"); GM_setValue("today_TextColor_value", e.target.value); textColor = e.target.value; } }) // 重置背景色和卡片色和文字色 document.getElementById("resetColor").onclick = function () { GM_setValue("today_BackgroundColor_value", null); GM_setValue("today_CardColor_value", null); document.getElementById("pickColor_BackgroundColor").value = "#000000"; document.getElementById("pickColor_CardColor").value = "#000000"; document.getElementById("pickColor_TextColor").value = "#000000"; removeStyle('setColorStyle'); } // 设置卡片圆角 document.getElementById("today_CardRadius_box").addEventListener("mousedown", f1, false) function f1() { document.getElementById("today_CardRadius_box").addEventListener("mousemove", f2, false); document.getElementById("today_CardRadius_box").addEventListener("click", f2, false); } function f2(e) { cardRadius = document.getElementById("today_CardRadius").value; GM_setValue("today_CardRadius_value", cardRadius); setStyle(".cc-cd {border-radius:" + cardRadius + "px !important;}", "setRadiusStyle"); } document.getElementById("today_CardRadius_box").addEventListener("mouseup", function (e) { document.getElementById("today_CardRadius_box").removeEventListener("mousemove", f2, false); }) // 重置卡片圆角 document.getElementById("resetRadius").onclick = function () { GM_setValue("today_CardRadius_value", null); document.getElementById("today_CardRadius").value = "100"; removeStyle('setRadiusStyle'); } // 设置卡片高度 document.getElementById("today_CardHeight_box").addEventListener("mousedown", f12, false) function f12() { document.getElementById("today_CardHeight_box").addEventListener("mousemove", f22, false); document.getElementById("today_CardHeight_box").addEventListener("click", f22, false); } function f22(e) { cardHeight = document.getElementById("today_CardHeight").value; GM_setValue("today_CardHeight_value", cardHeight); setStyle(".nano {height:" + cardHeight + "px !important;}", "setHeightStyle"); } document.getElementById("today_CardHeight_box").addEventListener("mouseup", function (e) { document.getElementById("today_CardHeight_box").removeEventListener("mousemove", f22, false); }) // 重置卡片高度 document.getElementById("resetHeight").onclick = function () { GM_setValue("today_CardHeight_value", 300); document.getElementById("today_CardHeight").value = "300"; removeStyle('setHeightStyle'); } // 双列显示和四列显示 document.getElementById("twoLineShow").onclick = function () { changeLineShow(2); twoLineStyle(); } document.getElementById("fourLineShow").onclick = function () { changeLineShow(4); fourLineStyle(); } }, 100) } })();