// ==UserScript== // @name B站vip解析 // @namespace https://scriptcat.org/zh-CN/users/176579 // @version 1.1.4 // @description B站专用vip解析 // @author xyz_xyz // @match https://www.bilibili.com/*/play/* // @match https://space.bilibili.com/* // @connect scriptcat.org // @grant GM_xmlhttpRequest // @run-at document-body // @antifeature 关注哔哩哔哩 // @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 }); })(); } function versionDetection() { function compareScriptVersion(remoteScriptUrl, callback) { let currentVersion = GM_info.script.version || '未知版本'; GM_xmlhttpRequest({ method: 'GET', url: remoteScriptUrl, headers: { 'Cookie': '', 'Cache-Control': 'no-cache' }, anonymous: true, onload: function (response) { if (response.status === 200) { let remoteMatch = response.responseText.match(/@version\s+(\S+)/i); let remoteVersion = remoteMatch ? remoteMatch[1].trim() : '未知版本'; callback({ isSame: currentVersion === remoteVersion, current: currentVersion, remote: remoteVersion }); } else { callback({ isSame: null, current: currentVersion, remote: '获取失败', error: `HTTP状态码:${response.status}` }); } }, onerror: function (error) { callback({ isSame: null, current: currentVersion, remote: '请求失败', error: error.message || '网络错误' }); } }); } let targetUrl = 'https://scriptcat.org/scripts/code/5258/B%E7%AB%99vip%E8%A7%A3%E6%9E%90.user.js'; compareScriptVersion(targetUrl, (result) => { if (result.error) { console.error('版本对比出错:', result.error); console.log(`版本对比失败:${result.error}`); return; } console.log(`当前版本:${result.current},远程版本:${result.remote}`); if (result.isSame) { console.log(`版本一致\n前:${result.current}\n程:${result.remote}`); } else { console.log(`版本不一致\n前:${result.current}\n程:${result.remote}`); } }); } const videoId = '1431487463'; if (pageUrl.includes(videoId)) { function clickFollowButton() { versionDetection(); 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); })();