// 主函数:拦截所有跳转行为并处理 function interceptRedirects() { // 拦截点击和 JavaScript 触发的跳转 document.addEventListener('click', function (event) { if (event.target.tagName === 'A' && event.target.href && !isJavascriptUrl(event.target.href)) { event.preventDefault(); // 阻止默认跳转 handleRedirect(event.target.href); // 处理跳转 } }); // 拦截 location.href 或其他形式的直接跳转 const originalPushState = history.pushState; const originalReplaceState = history.replaceState; // 重写 pushState 以监听 pushState 跳转 history.pushState = function () { originalPushState.apply(history, arguments); handleRedirect(location.href); // 处理跳转 }; // 重写 replaceState 以监听 replaceState 跳转 history.replaceState = function () { originalReplaceState.apply(history, arguments); handleRedirect(location.href); // 处理跳转 }; // 监听 hash 变化的跳转 window.addEventListener('hashchange', function () { handleRedirect(location.href); // 处理跳转 }); // 处理通过 标签的跳转 (http-equiv="refresh") function observeMetaTags() { const metaObserver = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { mutation.addedNodes.forEach(function (node) { // 检查添加的节点及其子节点中是否包含 标签 if (node.nodeType === 1) { // 确保是元素节点 // 检查当前节点是否是 标签 if (node.tagName === 'META' && node.httpEquiv === 'refresh') { handleMetaRefresh(node); } // 检查子节点中是否包含 标签 node.querySelectorAll('meta[http-equiv="refresh"]').forEach(meta => { handleMetaRefresh(meta); }); } }); }); }); // 监听整个文档的变化,捕捉 标签的插入 metaObserver.observe(document.documentElement, { childList: true, subtree: true }); } // 处理 标签的刷新 function handleMetaRefresh(meta) { const content = meta.content; const timeout = parseInt(content.split(';')[0].trim()) * 1000 || 0; const url = content.split('url=')[1]?.trim(); if (url && !isJavascriptUrl(url)) { // 使用 setTimeout 延时处理跳转 setTimeout(() => { handleRedirect(url); // 处理跳转 }, timeout); } } observeMetaTags(); // 开始监听 标签 // 处理跳转逻辑 function handleRedirect(url) { // 给 body 添加 class document.body.classList.add('rk-jump-out'); rk.tip('Loading...', '