diff --git a/static/js/nav.js b/static/js/nav.js index e9ebf4c..d643240 100644 --- a/static/js/nav.js +++ b/static/js/nav.js @@ -42,10 +42,6 @@ } function prefetchNav(href) { - if (window.qihuoPrefetchPage) { - window.qihuoPrefetchPage(href); - return; - } if (!href || href.indexOf(window.location.origin) !== 0) return; if (href === window.location.href) return; var links = document.head.querySelectorAll('link[rel="prefetch"]'); diff --git a/static/js/settings.js b/static/js/settings.js index 8e684f2..c252c5f 100644 --- a/static/js/settings.js +++ b/static/js/settings.js @@ -122,5 +122,6 @@ } if (window.qihuoPageBoot) window.qihuoPageBoot(bootSettingsPage, '.settings-page'); - else document.addEventListener('DOMContentLoaded', bootSettingsPage); + else if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', bootSettingsPage); + else bootSettingsPage(); })(); diff --git a/static/js/stats.js b/static/js/stats.js index e278365..be1cc45 100644 --- a/static/js/stats.js +++ b/static/js/stats.js @@ -163,6 +163,6 @@ } if (window.qihuoPageBoot) window.qihuoPageBoot(bootStatsPage, '#stats-summary'); - else if (window.qihuoOnPageLoad) window.qihuoOnPageLoad(bootStatsPage); - else document.addEventListener('DOMContentLoaded', bootStatsPage); + else if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', bootStatsPage); + else bootStatsPage(); })(); diff --git a/static/js/trade.js b/static/js/trade.js index 11d5cc3..281f54e 100644 --- a/static/js/trade.js +++ b/static/js/trade.js @@ -1664,9 +1664,13 @@ } }); - if (window.qihuoPageBoot) window.qihuoPageBoot(bootTradePage, '.trade-page'); - else if (window.qihuoOnPageLoad) window.qihuoOnPageLoad(bootTradePage); - else bootTradePage(); - if (window.qihuoOnPageLeave) window.qihuoOnPageLeave(cleanupTradePage); + function startTradePage() { + if (!document.querySelector('.trade-page')) return; + bootTradePage(); + } + + if (window.qihuoPageBoot) window.qihuoPageBoot(startTradePage, '.trade-page'); + else if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', startTradePage); + else startTradePage(); window.addEventListener('pagehide', cleanupTradePage); })(); diff --git a/static/js/turbonav.js b/static/js/turbonav.js deleted file mode 100644 index 368c3b0..0000000 --- a/static/js/turbonav.js +++ /dev/null @@ -1,276 +0,0 @@ -/* Copyright (c) 2025-2026 马建军. All rights reserved. - * 专有软件 — 未经授权禁止复制、传播、转售。 - * 详见 LICENSE.zh-CN.txt - */ -(function () { - var PERMANENT_CSS = ['/static/css/base.css', '/static/css/tech.css', '/static/css/responsive.css']; - var CORE_SCRIPT_RE = /theme\.js|symbol\.js|page\.js|nav\.js|pwa\.js|turbonav\.js/; - var pageCache = new Map(); - var MAX_CACHE = 10; - var inflight = null; - var currentUrl = normalizeUrl(window.location.href); - - function normalizeUrl(href) { - var u = new URL(href, window.location.origin); - u.hash = ''; - return u.href; - } - - function isPermanentStylesheet(el) { - var href = el.getAttribute('href') || ''; - return PERMANENT_CSS.some(function (p) { return href.indexOf(p) !== -1; }); - } - - function shouldTurboClick(e, link) { - if (!link || !link.href) return false; - if (e.defaultPrevented) return false; - if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return false; - if (link.target && link.target !== '_self') return false; - if (link.hasAttribute('download')) return false; - if (link.origin !== window.location.origin) return false; - if (normalizeUrl(link.href) === currentUrl) return false; - return true; - } - - function parseHtml(html) { - return new DOMParser().parseFromString(html, 'text/html'); - } - - function fetchPage(url, signal) { - var key = normalizeUrl(url); - if (pageCache.has(key)) { - return Promise.resolve(pageCache.get(key)); - } - return fetch(key, { - credentials: 'same-origin', - headers: { Accept: 'text/html' }, - signal: signal - }).then(function (res) { - if (!res.ok) throw new Error('HTTP ' + res.status); - return res.text(); - }).then(function (html) { - var pack = { doc: parseHtml(html), html: html }; - pageCache.set(key, pack); - if (pageCache.size > MAX_CACHE) { - var first = pageCache.keys().next().value; - pageCache.delete(first); - } - return pack; - }); - } - - function collectPageCss(doc) { - var out = []; - doc.querySelectorAll('head link[rel="stylesheet"], head style').forEach(function (el) { - if (el.tagName === 'LINK' && isPermanentStylesheet(el)) return; - out.push(el); - }); - doc.querySelectorAll('.main style').forEach(function (el) { - out.push(el); - }); - return out; - } - - function prepareMainHtml(doc) { - var fetchedMain = doc.querySelector('.main'); - if (!fetchedMain) return ''; - fetchedMain.querySelectorAll('style').forEach(function (el) { el.remove(); }); - return fetchedMain.innerHTML; - } - - /** DOMParser strips inline script bodies — parse from raw HTML instead. */ - function collectPageScripts(rawHtml) { - var scripts = []; - var bodyMatch = /
([\s\S]*)<\/body>/i.exec(rawHtml); - if (!bodyMatch) return scripts; - var body = bodyMatch[1]; - var re = / - {% block extra_js %}{% endblock %} -