From f3bdb07e3d64c51959262978e9f61809f75323f8 Mon Sep 17 00:00:00 2001 From: rain <982766701@qq.com> Date: Fri, 24 Jul 2026 18:19:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=B7=B3=E8=BD=AC=E6=97=B6?= =?UTF-8?q?=E6=89=93=E5=BC=80=E6=96=B0=E7=AA=97=E5=8F=A3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.js | 83 ++++++++++++++++++++++++++++++++ html/apply.html | 2 +- html/c.html | 8 +-- html/chongzhi.html | 2 +- html/fabumianfeiwenzhang.html | 6 +-- html/fufei.html | 2 +- html/jine.html | 6 +-- html/login.html | 2 +- html/mianfei.html | 6 +-- html/mianfeishoucang.html | 2 +- html/open-browser.html | 5 +- html/reg.html | 7 +-- html/repwd.html | 2 +- html/social-callback.html | 4 +- html/tixian.html | 2 +- html/tixianlist.html | 2 +- html/tuiguang.html | 2 +- html/upgrade.html | 1 + html/usercenter.html | 18 +++---- public/js/fufei-3dyjs-publish.js | 4 +- utils/ApiClient.js | 6 +-- utils/CommonUtil.js | 6 +-- 22 files changed, 132 insertions(+), 46 deletions(-) diff --git a/config.js b/config.js index f709997..47e6b80 100644 --- a/config.js +++ b/config.js @@ -33,3 +33,86 @@ window.CURRENT_ENV = (function () { // 获取当前环境配置 window.CURRENT_CONFIG = window.ENV[window.CURRENT_ENV]; + +window.NavigationUtil = (function (window, document) { + const blockedProtocols = /^(?:javascript|data|vbscript|mailto|tel):/i; + + function shouldOpenInNewTab(anchor) { + const href = (anchor.getAttribute('href') || '').trim(); + + return href && href !== '#' && !href.startsWith('#') && + !anchor.hasAttribute('download') && !blockedProtocols.test(href); + } + + function prepareAnchor(anchor) { + if (!anchor || anchor.tagName !== 'A' || !shouldOpenInNewTab(anchor)) { + return; + } + + if (anchor.target !== '_blank') { + anchor.target = '_blank'; + } + + const relTokens = (anchor.getAttribute('rel') || '').split(/\s+/).filter(Boolean); + + if (!relTokens.includes('noopener')) { + anchor.setAttribute('rel', [...relTokens, 'noopener'].join(' ')); + } + } + + function prepareAnchors(root) { + if (root.nodeType === 1 && root.matches('a[href]')) { + prepareAnchor(root); + } + + root.querySelectorAll('a[href]').forEach(prepareAnchor); + } + + function installLinkTargeting() { + prepareAnchors(document); + + new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + if (mutation.type === 'attributes') { + prepareAnchor(mutation.target); + return; + } + + mutation.addedNodes.forEach((node) => { + if (node.nodeType === 1) { + prepareAnchors(node); + } + }); + }); + }).observe(document.documentElement, { + subtree: true, + childList: true, + attributes: true, + attributeFilter: ['href', 'target', 'download'] + }); + } + + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', installLinkTargeting, { once: true }); + } else { + installLinkTargeting(); + } + + return { + open(url) { + const destination = String(url || '').trim(); + + if (!destination) { + return null; + } + + const openedWindow = window.open(destination, '_blank', 'noopener'); + + if (openedWindow) { + openedWindow.opener = null; + } + + return openedWindow; + } + }; +})(window, document); diff --git a/html/apply.html b/html/apply.html index 683ecf7..f197ec6 100644 --- a/html/apply.html +++ b/html/apply.html @@ -373,7 +373,7 @@ "资料上传成功,请等待审核通过", { icon: 1, time: 1800 }, function () { - window.location.href = "usercenter.html"; + NavigationUtil.open("usercenter.html"); } ); } else { diff --git a/html/c.html b/html/c.html index c8af7fb..b443123 100644 --- a/html/c.html +++ b/html/c.html @@ -3,12 +3,12 @@ + 神彩算 - 免费文章收藏 - @@ -137,7 +137,7 @@ ); }); } else { - window.location.href = "login.html"; + NavigationUtil.open("login.html"); return; } } @@ -157,7 +157,7 @@ function loadCollections() { const token = localStorage.getItem("token"); if (!token) { - window.location.href = "login.html"; + NavigationUtil.open("login.html"); return; } diff --git a/html/chongzhi.html b/html/chongzhi.html index 21a70c2..fe89e64 100644 --- a/html/chongzhi.html +++ b/html/chongzhi.html @@ -246,7 +246,7 @@ }, ); } else { - window.location.href = "login.html"; + NavigationUtil.open("login.html"); } } diff --git a/html/fabumianfeiwenzhang.html b/html/fabumianfeiwenzhang.html index 18205e0..a833845 100644 --- a/html/fabumianfeiwenzhang.html +++ b/html/fabumianfeiwenzhang.html @@ -254,7 +254,7 @@ "您还不是实习或正式专家,暂不能发布文章。", { title: "暂无权限" }, function () { - window.location.href = "apply.html"; + NavigationUtil.open("apply.html"); }, ); return; @@ -284,7 +284,7 @@ }); return; } - window.location.href = targetHref; + NavigationUtil.open(targetHref); }); }); }); @@ -525,7 +525,7 @@ "发布成功,请等待审核", { icon: 1, time: 1600 }, function () { - window.location.href = "index.html"; + NavigationUtil.open("index.html"); }, ); } else { diff --git a/html/fufei.html b/html/fufei.html index 64e3a36..c571303 100644 --- a/html/fufei.html +++ b/html/fufei.html @@ -217,7 +217,7 @@ function logout() { localStorage.removeItem("token"); - window.location.href = "login.html"; + NavigationUtil.open("login.html"); } function renderLoginState() { diff --git a/html/jine.html b/html/jine.html index a2a0c55..a7efa05 100644 --- a/html/jine.html +++ b/html/jine.html @@ -210,7 +210,7 @@ { btn: ["去登录", "取消"] }, function (index) { layui.layer.close(index); - window.location.href = "login.html"; + NavigationUtil.open("login.html"); }, ); }); @@ -566,11 +566,11 @@ ApiClient.post(ApiClient.API.authLogout, {}) .then(function () { localStorage.removeItem("token"); - window.location.href = "login.html"; + NavigationUtil.open("login.html"); }) .catch(function () { localStorage.removeItem("token"); - window.location.href = "login.html"; + NavigationUtil.open("login.html"); }); } diff --git a/html/login.html b/html/login.html index 1f3f2a9..d8b8579 100644 --- a/html/login.html +++ b/html/login.html @@ -316,7 +316,7 @@ } function redirectAfterLogin() { - window.location.href = getLoginRedirectUrl(); + NavigationUtil.open(getLoginRedirectUrl()); } function bindReferralThenRedirect() { diff --git a/html/mianfei.html b/html/mianfei.html index 2dad52e..ae637f1 100644 --- a/html/mianfei.html +++ b/html/mianfei.html @@ -497,7 +497,7 @@ { icon: 3, title: "提示" }, function (index) { layui.layer.close(index); - window.location.href = "login.html"; + NavigationUtil.open("login.html"); }, ); return; @@ -533,7 +533,7 @@ { icon: 3, title: "提示" }, function (index) { layui.layer.close(index); - window.location.href = "login.html"; + NavigationUtil.open("login.html"); }, ); return; @@ -671,7 +671,7 @@ { icon: 3, title: "提示" }, function (index) { layui.layer.close(index); - window.location.href = "login.html"; + NavigationUtil.open("login.html"); }, ); return; diff --git a/html/mianfeishoucang.html b/html/mianfeishoucang.html index 72d46d3..22d90c3 100644 --- a/html/mianfeishoucang.html +++ b/html/mianfeishoucang.html @@ -223,7 +223,7 @@ function checkLogin() { if (!CommonUtil.getAuthToken()) { - window.location.href = "login.html"; + NavigationUtil.open("login.html"); return; } diff --git a/html/open-browser.html b/html/open-browser.html index 580fca7..322e07a 100644 --- a/html/open-browser.html +++ b/html/open-browser.html @@ -41,6 +41,7 @@ color: #111827; } +
@@ -59,9 +60,9 @@ if (!inApp && location.search.indexOf(prefix) === 0) { const target = location.search.slice(prefix.length); if (target && target.charAt(0) === "/" && target.indexOf("//") !== 0) { - location.replace(target); + NavigationUtil.open(target); } } - \ No newline at end of file + diff --git a/html/reg.html b/html/reg.html index 851b1f3..76cd639 100644 --- a/html/reg.html +++ b/html/reg.html @@ -712,14 +712,15 @@ function redirectAfterRegister(hasToken) { if (hasToken) { - window.location.href = + NavigationUtil.open( typeof CommonUtil !== "undefined" ? CommonUtil.siteHref("/index.html") - : "index.html"; + : "index.html", + ); return; } - window.location.href = "login.html"; + NavigationUtil.open("login.html"); } function finishRegisterSuccess(res) { diff --git a/html/repwd.html b/html/repwd.html index c1ddbaf..9d497e7 100644 --- a/html/repwd.html +++ b/html/repwd.html @@ -529,7 +529,7 @@ "密码重置成功,即将前往登录", { icon: 1, time: 1200 }, function () { - window.location.href = "login.html"; + NavigationUtil.open("login.html"); }, ); return; diff --git a/html/social-callback.html b/html/social-callback.html index a6d6122..bfb1f25 100644 --- a/html/social-callback.html +++ b/html/social-callback.html @@ -176,7 +176,7 @@ function redirectHome() { setStatus("登录成功,正在跳转...", false); window.setTimeout(() => { - window.location.replace(homeUrl()); + NavigationUtil.open(homeUrl()); }, 500); } @@ -238,7 +238,7 @@ clearAccountBindMode(); setStatus("微信绑定成功,正在返回个人中心...", false); window.setTimeout(() => { - window.location.replace(returnUrl); + NavigationUtil.open(returnUrl); }, 500); } diff --git a/html/tixian.html b/html/tixian.html index 296a614..14fff39 100644 --- a/html/tixian.html +++ b/html/tixian.html @@ -312,7 +312,7 @@ function checkLogin() { const token = CommonUtil.getAuthToken ? CommonUtil.getAuthToken() : localStorage.getItem("token"); if (!token) { - window.location.href = "login.html"; + NavigationUtil.open("login.html"); return; } $("#notLoggedInBox").addClass("tx-hidden"); diff --git a/html/tixianlist.html b/html/tixianlist.html index 8706051..dafdcde 100644 --- a/html/tixianlist.html +++ b/html/tixianlist.html @@ -235,7 +235,7 @@ function checkLogin() { const token = CommonUtil.getAuthToken ? CommonUtil.getAuthToken() : localStorage.getItem("token"); if (!token) { - window.location.href = "login.html"; + NavigationUtil.open("login.html"); return; } $("#notLoggedInBox").addClass("tl-hidden"); diff --git a/html/tuiguang.html b/html/tuiguang.html index f51055c..345ff5c 100644 --- a/html/tuiguang.html +++ b/html/tuiguang.html @@ -355,7 +355,7 @@ }, ); } else { - window.location.href = "login.html"; + NavigationUtil.open("login.html"); } } diff --git a/html/upgrade.html b/html/upgrade.html index 3949628..7e9baf0 100644 --- a/html/upgrade.html +++ b/html/upgrade.html @@ -256,6 +256,7 @@ } } +
diff --git a/html/usercenter.html b/html/usercenter.html index cba3845..8b9cc75 100644 --- a/html/usercenter.html +++ b/html/usercenter.html @@ -112,26 +112,26 @@ @@ -530,7 +530,7 @@ if (state.isApplying) { $applyBtn.removeAttr("onclick"); } else { - $applyBtn.attr("onclick", "window.location.href = 'apply.html'"); + $applyBtn.attr("onclick", "NavigationUtil.open('apply.html')"); } } @@ -695,7 +695,7 @@ { btn: ["去登录", "取消"] }, function (index) { layui.layer.close(index); - window.location.href = "login.html"; + NavigationUtil.open("login.html"); }, ); }); @@ -757,7 +757,7 @@ }); localStorage.removeItem("token"); setTimeout(function () { - window.location.href = "login.html"; + NavigationUtil.open("login.html"); }, 1500); }, ); @@ -812,11 +812,11 @@ ApiClient.post(ApiClient.API.authLogout, null, { headers: CommonUtil.authHeaders() }) .then(function (res) { localStorage.removeItem("token"); - window.location.href = "login.html"; + NavigationUtil.open("login.html"); }) .catch(function () { localStorage.removeItem("token"); - window.location.href = "login.html"; + NavigationUtil.open("login.html"); }); } diff --git a/public/js/fufei-3dyjs-publish.js b/public/js/fufei-3dyjs-publish.js index 8e7f247..d5746a9 100644 --- a/public/js/fufei-3dyjs-publish.js +++ b/public/js/fufei-3dyjs-publish.js @@ -22,7 +22,7 @@ const $ = layui.$; title: "暂无权限", }, function () { - window.location.href = "fabumianfeiwenzhang.html"; + NavigationUtil.open("fabumianfeiwenzhang.html"); }, ); return; @@ -754,7 +754,7 @@ const $ = layui.$; throw new Error(res.msg || "发布失败"); } layer.msg("发布成功", { icon: 1, time: 1200 }, function () { - window.location.href = "usercenter.html"; + NavigationUtil.open("usercenter.html"); }); }) .catch(function (error) { diff --git a/utils/ApiClient.js b/utils/ApiClient.js index 4adf7b2..6687e7b 100644 --- a/utils/ApiClient.js +++ b/utils/ApiClient.js @@ -173,7 +173,7 @@ const ApiClient = { if (!response.ok) { if (response.status === 401) { localStorage.removeItem('token'); - window.location.href = 'login.html'; + NavigationUtil.open('login.html'); } throw new Error(`HTTP ${response.status}: ${response.statusText}`); } @@ -331,10 +331,10 @@ const ApiClient = { if (/\/(login|reg|repwd)\.html$/i.test(path)) return; const returnUrl = window.location.pathname + window.location.search; const loginPath = '/login.html?redirect=' + encodeURIComponent(returnUrl); - window.location.href = + NavigationUtil.open( typeof CommonUtil !== 'undefined' && CommonUtil.siteHref ? CommonUtil.siteHref(loginPath) - : ((window.CURRENT_ENV === 'development' ? '/html/login.html?redirect=' : '/login.html?redirect=') + encodeURIComponent(returnUrl)); + : ((window.CURRENT_ENV === 'development' ? '/html/login.html?redirect=' : '/login.html?redirect=') + encodeURIComponent(returnUrl))); }, buildUrl(url, params) { diff --git a/utils/CommonUtil.js b/utils/CommonUtil.js index e00e0dc..508e602 100644 --- a/utils/CommonUtil.js +++ b/utils/CommonUtil.js @@ -110,7 +110,7 @@ const CommonUtil = { { btn: ['去登录', '取消'] }, function (index) { layui.layer.close(index); - window.location.href = 'login.html'; + NavigationUtil.open('login.html'); } ); }); @@ -1178,7 +1178,7 @@ const CommonUtil = { } const authUrl = this.extractWechatAuthUrl(res); if (!authUrl) throw new Error('后端未返回微信授权地址'); - window.location.href = authUrl; + NavigationUtil.open(authUrl); }) .catch((error) => { const message = error.message || '微信登录暂不可用,请稍后再试'; @@ -1325,7 +1325,7 @@ const CommonUtil = { } const authUrl = this.extractWechatAuthUrl(res); if (!authUrl) throw new Error('后端未返回微信授权地址'); - window.location.href = authUrl; + NavigationUtil.open(authUrl); }) .catch((error) => { const message = error.message || '微信绑定暂不可用,请稍后再试';