// ==UserScript== // @name 自用bilibili脚本 // @namespace mimiko/bilibili // @version 0.0.10 // @description 吧啦吧啦 // @author Mimiko // @license MIT // @match *://*.bilibili.com/* // @grant GM.addStyle // @grant GM.registerMenuCommand // grant GM.xmlHttpRequest // @downloadURL none // ==/UserScript== (() => { if (window.top !== window.self) return; const Monkey = GM; const cache = new Map(); const asBangumiMain = () => { asPlayerMain(); hideEl('#review_module'); Monkey.addStyle('.bpx-player-container { box-shadow: none !important; }'); }; const asCommonMain = () => { hideEl('#internationalHeader .nav-link-item:last-of-type'); }; const asIndexLive = async () => { hideEl('.player-area-ctnr'); await getEl('video'); removeEl('.player-area-ctnr'); }; const asIndexMain = async () => { hideEl('.contact-help', '#reportFirst2', '#reportFirst3', '#bili_live', '#bili_guochuang', '#bili_manga'); await getEl('#elevator .item.sortable'); Monkey.addStyle([ '#elevator { opacity: 0.1; transition: opacity 0.3s; }', '#elevator:hover { opacity: 1; }', ].join('\n')); hideElByText('#elevator .item.sortable', '直播'); hideElByText('#elevator .item.sortable', '国创'); hideElByText('#elevator .item.sortable', '漫画'); }; const asLive = () => { const path = window.location.pathname; if (path === '/') return asIndexLive(); if (parseInt(path.substring(1), 10)) return asRoomLive(); }; const asMain = () => { asCommonMain(); const path = window.location.pathname; if (path === '/') return asIndexMain(); if (path.startsWith('/video/BV')) return asVideoMain(); if (path.startsWith('/bangumi/play/')) return asBangumiMain(); }; const asPlayerMain = async () => { hideEl('.bilibili-player-electric-panel', '.bilibili-player-ending-panel', '.bilibili-player-video-hint'); await turnWide(); await sleep(50); focusPlayer(); }; const asRoomLive = () => { removeEl('#my-dear-haruna-vm'); hideEl('#room-background-vm'); }; const asVideoMain = () => { asPlayerMain(); hideEl('.bilibili-player-video-popup-vote', '.bilibili-player-score'); Monkey.addStyle('.bilibili-player { box-shadow: none !important; }'); }; const focusPlayer = async () => (await getEl('video', 'bwp-video')).scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center', }); const getEl = (...listSelector) => new Promise(resolve => { const fn = () => listSelector.some(selector => { const $el = document.querySelector(selector); if (!$el) return false; window.clearInterval(timer); resolve($el); return true; }); const timer = window.setInterval(fn, 50); fn(); }); const hideEl = (...listSelector) => Monkey.addStyle(listSelector.map(selector => `${selector} { display: none !important; }`).join('\n')); const hideElByText = (selector, text) => { const $listNode = Array.from(document.querySelectorAll(selector)) .filter($it => $it.textContent?.trim() === text); $listNode.forEach($it => $it.style.display = 'none'); }; const main = () => { route(); watch(); }; const removeEl = (selector) => document.querySelectorAll(selector).forEach($it => $it.remove()); const route = () => { const host = window.location.host.split('.')[0]; if (host === 'www') return asMain(); if (host === 'live') return asLive(); }; const sleep = (time) => new Promise(resolve => setTimeout(resolve, time)); const turnWide = async () => { const isWide = document.body.classList.contains('player-mode-widescreen'); if (isWide) return; const $btn = await getEl('.bilibili-player-video-btn-widescreen', '.squirtle-video-widescreen'); $btn.click(); }; const watch = () => { cache.set('location', window.location.href); window.setInterval(() => { if (window.location.href === cache.get('location')) return; cache.set('location', window.location.href); route(); }, 1e3); }; main(); })();