// ==UserScript== // @name 自用bilibili脚本 // @namespace mimiko/bilibili // @version 0.0.7 // @description 吧啦吧啦 // @author Mimiko // @license MIT // @match *://*.bilibili.com/* // @grant GM.addStyle // @downloadURL none // ==/UserScript== (() => { if (window.top !== window.self) return; let cacheLocation = window.location.href; const asBangumiMain = () => { asPlayerMain(); hide('#review_module'); true && GM.addStyle('.bpx-player-container { box-shadow: none !important; }'); }; const asCommonMain = () => { hide('#internationalHeader .nav-link-item:last-of-type'); }; const asIndexLive = () => { hide('.player-area-ctnr'); const timer = window.setInterval(() => { const $video = document.querySelector('video'); if (!$video) return; window.clearInterval(timer); remove('.player-area-ctnr'); }, 50); }; const asIndexMain = () => { hide('.contact-help'); hide('#reportFirst2'); hide('#reportFirst3'); hide('#bili_live'); hide('#bili_guochuang'); hide('#bili_manga'); const timer = window.setInterval(() => { const $item = document.querySelector('#elevator .item.sortable'); if (!$item) return; window.clearInterval(timer); hideByText('#elevator .item.sortable', '直播'); hideByText('#elevator .item.sortable', '国创'); hideByText('#elevator .item.sortable', '漫画'); }, 50); }; 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 = () => { hide('.bilibili-player-electric-panel'); hide('.bilibili-player-ending-panel'); hide('.bilibili-player-video-hint'); const timer = window.setInterval(() => { focusPlayer(); if (!turnWide()) return; window.clearInterval(timer); }, 50); }; const asRoomLive = () => { remove('#my-dear-haruna-vm'); hide('#room-background-vm'); }; const asVideoMain = () => { asPlayerMain(); hide('.bilibili-player-video-popup-item'); true && GM.addStyle('.bilibili-player { box-shadow: none !important; }'); }; const focusPlayer = () => { const $video = document.querySelector('video') || document.querySelector('bwp-video'); if (!$video) return; $video.scrollIntoView(); window.setTimeout(() => $video.scrollIntoView(), 100); }; const hide = (selector) => GM.addStyle(`${selector} { display: none !important; }`); const hideByText = (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 remove = (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 turnWide = () => { const isWide = document.body.classList.contains('player-mode-widescreen'); if (isWide) return true; const $btn = document.querySelector('.bilibili-player-video-btn-widescreen') || document.querySelector('.squirtle-video-widescreen'); if (!$btn) return false; $btn.click(); return true; }; const watch = () => { window.setInterval(() => { if (window.location.href === cacheLocation) return; cacheLocation = window.location.href; route(); }, 1e3); }; main(); })();