// ==UserScript== // @name 简单的青柠起始页优化 // @namespace https://bbs.tampermonkey.net.cn/ // @version 0.3.0 // @description 默认去掉青柠起始页的页脚,使用 alt + t 控制搜索框的显示隐藏 使用alt + g切换时钟显示隐藏,变量全局存储,不需要每次打开都关闭或者显示了 alt+b 显示隐藏 B站热搜 // @author Hei // @match *://limestart.cn/* // @grant GM_setClipboard // @grant unsafeWindow // @grant GM_xmlhttpRequest // @grant GM_addStyle // @connect api.bilibili.com // @require https://lib.baomitu.com/jquery/1.12.4/jquery.min.js // ==/UserScript== (function () { 'use strict'; // 基础依赖 const _mainKey = 'easy_limestart' const ls = { set(key, val) { let easy_limestart_obj = window.localStorage.getItem(_mainKey); if (!easy_limestart_obj) { easy_limestart_obj = {} } else { easy_limestart_obj = JSON.parse(easy_limestart_obj) } easy_limestart_obj[key] = val; window.localStorage.setItem(_mainKey, JSON.stringify(easy_limestart_obj)) }, get(key, defaultVal = null) { let easy_limestart_obj = window.localStorage.getItem(_mainKey); if (!easy_limestart_obj) { easy_limestart_obj = {} return defaultVal } else { easy_limestart_obj = JSON.parse(easy_limestart_obj) } const val = easy_limestart_obj[key]; if (val !== undefined) { return JSON.parse(val) } return defaultVal } } //消息弹窗 const Message = { info(msg) { const delay = 2000; //多少毫秒后隐藏 const greetingContainer = document.createElement("div") greetingContainer.id = "greetingContainer" const greetingBox = document.createElement("div") greetingBox.id = "greetingBox" greetingBox.textContent = msg greetingContainer.append(greetingBox) document.body.append(greetingContainer) greetingContainer.offsetLeft; // reflow greetingBox.style.opacity = 1 greetingBox.style.transform = `translateY(0)` setTimeout(() => { greetingBox.style.opacity = 0; greetingBox.style.transform = `translateY(-100%)`; greetingBox.addEventListener("transitionend", () => { greetingContainer.remove(); }) greetingBox.addEventListener("webkitTransitionEnd", () => { greetingContainer.remove(); }) }, delay) } } // 加载B站热搜 // 去除脚标 const timer = setInterval(() => { const footer = document.querySelector("footer.brief"); if (footer) { footer.style.display = 'none' clearInterval(timer) } }, 500); /** * 显示/隐藏搜索框 */ function showSearchCb() { const searchSuggestionContainer = document.getElementById("searchSuggestionContainer"); const menuSearchEng = document.getElementById("menuSearchEng"); const searchEl = document.getElementById("searchBar"); if (searchEl) { searchEl.style.display = showSearch ? 'block' : 'none'; } if (searchSuggestionContainer) { searchSuggestionContainer.style.display = showSearch ? 'block' : 'none'; } if (menuSearchEng) { menuSearchEng.style.display = showSearch ? 'block' : 'none'; } } let showSearch = ls.get("showSearch"); showSearchCb(); // 显示/隐藏时间框 let showTimer = ls.get("showTimer", true) function showTimerCb() { const timeContainer = document.getElementById("timeContainer"); if (timeContainer) { timeContainer.style.display = showTimer ? 'block' : 'none'; } } showTimerCb() let showBilibili = false; //B站热搜显示 function showBlibiliTrending(init = false) { // style="display: block; opacity: 1;" // style="display: block; opacity: 1; transform: none;" const dialog = `
` if (init) { GM_addStyle(`.cover2 { z-index: 100; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,.35); display: none; opacity: 0; transition: .25s; perspective: 1000px; }`) $(document.body).append(dialog); $(".cover2.easy-limestart .btnClose").hover(() => { $(".cover2.easy-limestart .popUp").css({ display: "block", opacity: 1, transform: 'rotate3d(1, 1, 0, 5deg)' }) }, () => { $(".cover2.easy-limestart .popUp").css({ display: "block", opacity: 1, transform: 'none' }) }) $(".cover2.easy-limestart .btnClose").click(() => { showBilibili = false; $(".cover2.easy-limestart").fadeOut(100) }) } else { showBilibili = !showBilibili; if (showBilibili) { const getRow = (show_name, keyword) => { return `` } GM_xmlhttpRequest({ url: "https://api.bilibili.com/x/web-interface/wbi/search/square?limit=10&platform=web", method: "get", onload: (data) => { const { data: { trending: { list, title, top_list } }, code, message } = JSON.parse(data.response); // console.log(code, message) if (code != 0) { Message.info(message) } else { $(".cover2.easy-limestart .pCaptionBar").text(title) // console.log(list, title, top_list) const rowList = [] for (const idx in list) { const { show_name, keyword, icon } = list[idx]; const row = getRow(show_name, keyword) rowList.push(row) } $(".cover2.easy-limestart .pContent").html(rowList.join("")) } } }) $(".cover2.easy-limestart").css({ display: "block", opacity: 1 }) $(".cover2.easy-limestart .popUp").css({ display: "block", opacity: 0, transform: 'rotate3d(1, 1, 0, 50deg)' }).offset(); $(".cover2.easy-limestart .popUp").css({ display: "block", opacity: 1, transform: 'none' }) } else { $(".cover2.easy-limestart").fadeOut(100) } } } showBlibiliTrending(true); // 增加键盘事件 document.body.addEventListener("keydown", (e) => { if (e.altKey && e.key.toLowerCase() === 't') { showSearch = !showSearch; showSearchCb() Message.info(showSearch ? "显示搜索框" : '隐藏搜索框') ls.set("showSearch", showSearch) } if (e.altKey && e.key.toLowerCase() === 'g') { showTimer = !showTimer; showTimerCb() Message.info(showTimer ? "显示时间" : '隐藏时间') ls.set("showTimer", showTimer) } if (e.altKey && e.key.toLowerCase() === 'b') { showBlibiliTrending() } }); console.log('start') })();