(function () { 'use strict'; if (window.__DBC_SITE_V281__) return; window.__DBC_SITE_V281__ = true; const html = document.documentElement; const body = document.body; const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; function currentFile() { const value = window.location.pathname.split('/').pop(); return value || 'index.html'; } function resolvedUrl(link) { try { return new URL(link.getAttribute('href'), window.location.href); } catch { return null; } } function markRelease() { const release = body.dataset.dbcRelease || html.dataset.dbcRelease || 'v3.0.0'; html.dataset.dbcRelease = release; body.dataset.dbcRelease = release; body.classList.add('v281-enhanced'); const footer = document.querySelector('footer.site-footer'); if (footer) footer.dataset.dbcRelease = release; } function markLinkSemantics() { const file = currentFile(); document.querySelectorAll('a[href]').forEach(function (link) { const url = resolvedUrl(link); if (!url) return; const external = url.origin !== window.location.origin && url.protocol !== 'file:'; if (external) { link.dataset.v281External = 'true'; if (link.target === '_blank') { const rel = new Set((link.getAttribute('rel') || '').split(/\s+/).filter(Boolean)); rel.add('noopener'); link.setAttribute('rel', Array.from(rel).join(' ')); } return; } link.dataset.v281Local = 'true'; const targetFile = url.pathname.split('/').pop() || 'index.html'; if (targetFile === file && !url.hash && link.closest('.footer-directory')) { link.setAttribute('aria-current', 'page'); } const label = link.textContent.replace(/\s+/g, ' ').trim(); if (!link.getAttribute('aria-label') && /^(?:了解更多|查看详情|进入|阅读更多|More)$/i.test(label)) { const container = link.closest('article, li, section, div'); const heading = container && container.querySelector('h2, h3, strong'); if (heading) { const context = heading.textContent.replace(/\s+/g, ' ').trim(); if (context && context !== label) link.setAttribute('aria-label', `${label}:${context}`); } } }); } function rerouteSharedFooterLoops() { const file = currentFile(); const cta = document.querySelector('.formal-footer-cta'); if (!cta) return; const routes = { 'about.html': { match: 'about.html', href: 'about-brands.html', cn: '查看业务生态', en: 'View business ecosystem' }, 'contact.html': { match: 'contact.html', href: '#intent-options', cn: '选择合作方向', en: 'Choose a collaboration path' }, 'sample.html': { match: 'sample.html', href: 'contact.html#routing-rules', cn: '查看后续对接规则', en: 'View follow-up routing' }, 'resources.html': { match: 'resources.html', href: 'knowledge-compliance-map.html', cn: '查看资料使用边界', en: 'Review document-use boundaries' } }; const route = routes[file]; if (!route) return; const link = Array.from(cta.querySelectorAll('a[href]')).find(function (candidate) { return candidate.getAttribute('href').split('#')[0] === route.match; }); if (!link) return; link.href = route.href; link.textContent = route.cn; link.dataset.navCn = route.cn; link.dataset.navEn = route.en; link.dataset.v281Rerouted = 'true'; link.removeAttribute('aria-current'); } function centreCurrentPathStep() { const current = document.querySelector('.v281-path [data-v281-current]'); const list = current && current.closest('ol'); if (!current || !list || list.scrollWidth <= list.clientWidth + 2) return; const left = current.offsetLeft - (list.clientWidth - current.offsetWidth) / 2; list.scrollTo({ left: Math.max(0, left), behavior: reducedMotion ? 'auto' : 'smooth' }); } function refreshHashTarget() { if (!window.location.hash) return; let id = ''; try { id = decodeURIComponent(window.location.hash.slice(1)); } catch { id = window.location.hash.slice(1); } const target = id && document.getElementById(id); if (!target) return; target.dataset.v281HashTarget = 'true'; window.setTimeout(function () { target.removeAttribute('data-v281-hash-target'); }, reducedMotion ? 40 : 900); } function hashTarget(url) { if (!url || !url.hash) return null; const targetFile = url.pathname.split('/').pop() || 'index.html'; if (targetFile !== currentFile()) return null; let id = ''; try { id = decodeURIComponent(url.hash.slice(1)); } catch { id = url.hash.slice(1); } return id ? document.getElementById(id) : null; } function installSamePageAnchorRouting() { document.addEventListener('click', function (event) { if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; const link = event.target.closest && event.target.closest('a[href]'); if (!link || (link.target && link.target !== '_self') || link.hasAttribute('download')) return; const url = resolvedUrl(link); const target = hashTarget(url); if (!target) return; event.preventDefault(); const next = `${window.location.pathname}${window.location.search}${url.hash}`; if (window.location.hash === url.hash) window.history.replaceState(null, '', next); else window.history.pushState(null, '', next); target.scrollIntoView({ behavior: reducedMotion ? 'auto' : 'smooth', block: 'start' }); refreshHashTarget(); }); } function settleInitialHash() { if (!window.location.hash) return; window.addEventListener('load', function () { window.setTimeout(function () { const target = hashTarget(window.location); if (target) target.scrollIntoView({ behavior: 'auto', block: 'start' }); }, 220); }, { once: true }); } markRelease(); rerouteSharedFooterLoops(); markLinkSemantics(); centreCurrentPathStep(); refreshHashTarget(); installSamePageAnchorRouting(); settleInitialHash(); window.addEventListener('hashchange', refreshHashTarget, { passive: true }); })();