// ==UserScript== // @name BT4G访问 // @author wangzijian0@vip.qq.com // @description 绕过国内网络限制访问BT4G // @version 1.0.1.20250404 // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAr0lEQVR4AU3OIQyDMBQE0D8vEHNIHHYO3WQGV6+m5hVekEzUizokDleBrqisboKqReB/bw0ZsJMvucsRrEpIjCMEXXYW6YJQ1X072VPoJZW2o17xI2pbOS7T38b7pha47QJTKRvM2QBtQvTRxwvwKXoTDfiEtX6K0cVDiGHKVm7zCmZOnAiMoa6EmyIyAYQsurg1fhh8HgsZkBC0LB9Nca9FR9gFiN7NLgI7gPm4wV+0DtHUd8v4dgAAAABJRU5ErkJggg== // @match *://bt4gprx.com/* // @match *://*.bt4g.com/* // @match *://bt4g.com/* // @grant GM_xmlhttpRequest // @grant GM_getValue // @grant GM_setValue // @namespace https://greasyfork.org/users/1453515 // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 兼容不同用户脚本管理器的API差异 const GM_xhr = typeof GM !== 'undefined' && GM.xmlHttpRequest ? GM.xmlHttpRequest : GM_xmlhttpRequest; if (!GM_xhr) { console.error('BT4G访问: 当前用户脚本管理器不支持GM.xmlHttpRequest或GM_xmlhttpRequest'); return; } // 检查当前域名是否属于 BT4G 相关站点 const isBT4G = /^(.*\.)?bt4g(prx)?\.com$/.test(window.location.hostname); if (isBT4G) { const proxyUrl = 'https://api.allorigins.win/raw?url=' + encodeURIComponent(window.location.href); try { GM_xhr({ method: 'GET', url: proxyUrl, timeout: 15000, onload: function(response) { if (response.status >= 200 && response.status < 300) { document.open(); document.write(response.responseText); document.close(); } else { showError(`代理请求失败,状态码: ${response.status}`); } }, onerror: function(error) { console.error('BT4G访问代理失败:', error); showError('代理访问失败,请检查网络或更换代理服务!'); }, ontimeout: function() { showError('代理请求超时,请重试或检查网络连接'); } }); } catch (e) { console.error('BT4G访问: 请求发送失败', e); showError('脚本执行出错,请检查控制台日志'); } } function showError(message) { // 创建更友好的错误提示界面 const errorDiv = document.createElement('div'); errorDiv.style.position = 'fixed'; errorDiv.style.top = '0'; errorDiv.style.left = '0'; errorDiv.style.right = '0'; errorDiv.style.backgroundColor = '#ffebee'; errorDiv.style.color = '#c62828'; errorDiv.style.padding = '15px'; errorDiv.style.zIndex = '9999'; errorDiv.style.textAlign = 'center'; errorDiv.style.fontFamily = 'Arial, sans-serif'; errorDiv.style.boxShadow = '0 2px 5px rgba(0,0,0,0.2)'; errorDiv.innerHTML = ` BT4G访问错误: ${message} `; const retryBtn = errorDiv.querySelector('button'); retryBtn.onclick = function() { errorDiv.remove(); window.location.reload(); }; document.body.appendChild(errorDiv); } })();