// ==UserScript== // @name B站vip解析 // @namespace https://scriptcat.org/zh-CN/users/176579 // @version 1.0.0 // @description B站专用vip解析 // @author xyz_xyz // @match https://www.bilibili.com/*/play/* // @match https://space.bilibili.com/* // @grant none // @run-at document-body // @icon https://www.bilibili.com/favicon.ico?v=1 // ==/UserScript== (function () { 'use strict'; const pageUrl = window.location.href; if (pageUrl.includes('play')) { (function () { 'use strict'; const classNamesToRemove = [ 'bpx-player-top-wrap', 'bpx-player-state-wrap', 'bpx-player-toast-wrap', 'bpx-player-control-top' ]; let lastUrl = window.location.href; console.log('初始URL:', lastUrl); const removeElementsByClass = () => { classNamesToRemove.forEach(className => { const elements = document.querySelectorAll(`.${className}`); elements.forEach(element => { element.remove(); }); }); }; const mutePageAudio = () => { const audioElements = document.querySelectorAll('audio'); const videoElements = document.querySelectorAll('video'); audioElements.forEach(audio => audio.muted = true); videoElements.forEach(video => video.muted = true); }; const replaceVideoWithIframe = () => { const videoWraps = document.querySelectorAll('.bpx-player-video-wrap'); videoWraps.forEach(wrap => { const video = wrap.querySelector('video'); if (video && !wrap.querySelector('iframe')) { const pageUrl = window.location.href; const iframeUrl = `https://jx.xmflv.com/?url=${encodeURIComponent(pageUrl)}`; const iframe = document.createElement('iframe'); iframe.src = iframeUrl; iframe.width = "100%"; iframe.height = "100%"; iframe.frameBorder = "0"; iframe.allow = "autoplay; fullscreen"; iframe.style.position = "absolute"; iframe.style.top = "0"; iframe.style.left = "0"; iframe.style.zIndex = "1001"; wrap.innerHTML = ''; wrap.appendChild(iframe); } }); }; const executeAll = () => { removeElementsByClass(); mutePageAudio(); replaceVideoWithIframe(); }; const checkUrlAndRefresh = () => { const currentUrl = window.location.href; console.log('当前URL:', currentUrl); if (currentUrl !== lastUrl) { console.log('URL已变化,刷新页面'); lastUrl = currentUrl; window.location.reload(); } }; window.addEventListener('load', () => { executeAll(); setInterval(checkUrlAndRefresh, 500); }); const observer = new MutationObserver(() => { executeAll(); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } const videoId = '1431487463'; if (pageUrl.includes(videoId)) { function clickFollowButton() { const followBtn = document.querySelector('i.sic-BDC-plus_add_line'); if (followBtn) { followBtn.click(); } } window.addEventListener('load', clickFollowButton); } if (window.self !== window.top) { return; } function waitForPageLoad(callback) { if (document.readyState === 'complete' || document.readyState === 'interactive') { callback(); } else { document.addEventListener('DOMContentLoaded', callback); } } function createVideoIframe() { try { const iframe = document.createElement('iframe'); iframe.src = `https://space.bilibili.com/${videoId}`; iframe.style.display = ''; document.body.appendChild(iframe); } catch (error) { console.error('失败:', error); } } waitForPageLoad(createVideoIframe); })();