(() => { 'use strict'; const root = document.documentElement; if (!root.matches('[data-v770-release="fullsite-logic-visual-quality-v7.7.0"]')) return; const currentFile = decodeURIComponent(location.pathname.split('/').pop() || 'index.html').toLowerCase(); const primaryTitles = Object.freeze({ 'index.html': { zh: 'DBC 世界杯竞猜官网|新材料应用创新平台 · BIOTEN 博碳生物', en: 'DBC | Advanced-Material Application Platform · BIOTEN' }, 'about.html': { zh: '关于世界杯竞猜官网|新材料创新与产业应用平台', en: 'About DBC | New Material Innovation & Industrial Application Platform' }, 'bioten-platform.html': { zh: 'BIOTEN 博碳生物|PHA 生物基水性功能乳液平台', en: 'BIOTEN | PHA Bio-Based Waterborne Functional Emulsion Platform' }, 'bioten.html': { zh: 'BIOTEN 博碳包装|纸基包装阻隔系统工程', en: 'BIOTEN Packaging | Barrier Systems Engineering for Fiber-Based Packaging' }, 'bioten-lab.html': { zh: 'BIOTEN 开发者|问题定义、联合开发与证据协同', en: 'BIOTEN Developer | Problem Definition, Joint Development and Evidence Coordination' }, 'news.html': { zh: '新闻与洞察|材料科技进展与产业实践|DBC 世界杯竞猜官网', en: 'News & Insights | Materials Progress and Industry Practice | DBC' }, 'patent-evidence.html': { zh: '研发与专利技术资产|材料与产品创新|DBC · BIOTEN', en: 'R&D and Patent Technology Assets | Material & Product Innovation | DBC · BIOTEN' } }); function pageLanguage() { return root.dataset.lang === 'en' || root.lang.toLowerCase().startsWith('en') ? 'en' : 'zh'; } function setLocalizedText(element, value) { if (!element.children.length) { if (element.textContent !== value) element.textContent = value; return; } const directText = [...element.childNodes].find((node) => node.nodeType === Node.TEXT_NODE && node.nodeValue.trim()); if (directText && directText.nodeValue.trim() !== value) directText.nodeValue = `${value} `; } function stabilizeBilingualState() { if (!document.body?.matches('[data-en-ready="true"], [data-en-ready=""]')) return; const language = pageLanguage(); const key = language === 'en' ? 'navEn' : 'navCn'; document.querySelectorAll('[data-nav-cn][data-nav-en]').forEach((element) => { const value = element.dataset[key]; if (typeof value === 'string') setLocalizedText(element, value); }); document.querySelectorAll('[data-aria-cn][data-aria-en]').forEach((element) => { const value = element.dataset[language === 'en' ? 'ariaEn' : 'ariaCn']; if (typeof value === 'string') element.setAttribute('aria-label', value); }); document.querySelectorAll('[data-alt-cn][data-alt-en]').forEach((element) => { const value = element.dataset[language === 'en' ? 'altEn' : 'altCn']; if (typeof value === 'string') element.setAttribute('alt', value); }); const title = primaryTitles[currentFile]?.[language]; if (title && document.title !== title) document.title = title; document.querySelectorAll('footer.site-footer .footer-directory').forEach((navigation) => { navigation.setAttribute('aria-label', language === 'en' ? 'Website footer navigation' : '网站页脚导航'); }); document.querySelectorAll('[data-v7111-footer-toggle]').forEach((button) => { const heading = button.dataset[key] || button.textContent.trim(); button.setAttribute('aria-label', language === 'en' ? `${heading} footer directory` : `${heading}页脚目录`); }); } function scheduleBilingualStabilization() { stabilizeBilingualState(); requestAnimationFrame(stabilizeBilingualState); [90, 320, 900].forEach((delay) => window.setTimeout(stabilizeBilingualState, delay)); } function safeId(text, index) { const normalized = String(text || '') .trim() .toLowerCase() .replace(/[^a-z0-9\u3400-\u9fff]+/g, '-') .replace(/^-+|-+$/g, '') .slice(0, 42); return `article-section-${normalized || index + 1}`; } function enhanceArticleReading() { const body = document.body; if (!body.matches('.v750-site[data-v750-page="article"]')) return; const article = document.querySelector('.news-article, .news-original-article'); const chineseBody = document.querySelector('.news-body[data-v750-original-cn]'); const content = chineseBody?.querySelector('.news-content'); if (!article || !chineseBody || !content) return; const headings = [...content.querySelectorAll(':scope > h2')]; headings.forEach((heading, index) => { if (!heading.id) heading.id = safeId(heading.textContent, index); }); if (headings.length > 1) { const details = document.createElement('details'); details.className = 'v770-article-toc'; const summary = document.createElement('summary'); summary.textContent = root.dataset.lang === 'en' ? 'Article outline' : '文章目录'; const list = document.createElement('ol'); headings.forEach((heading) => { const item = document.createElement('li'); const link = document.createElement('a'); link.href = `#${heading.id}`; link.textContent = heading.textContent.trim(); item.append(link); list.append(item); }); details.append(summary, list); chineseBody.parentNode.insertBefore(details, chineseBody); } const progress = document.createElement('div'); progress.className = 'v770-reading-progress'; progress.setAttribute('aria-hidden', 'true'); const bar = document.createElement('span'); progress.append(bar); document.body.append(progress); let ticking = false; const update = () => { const rect = article.getBoundingClientRect(); const articleTop = window.scrollY + rect.top; const distance = Math.max(1, article.scrollHeight - window.innerHeight); const ratio = Math.min(1, Math.max(0, (window.scrollY - articleTop) / distance)); bar.style.width = `${ratio * 100}%`; ticking = false; }; const requestUpdate = () => { if (ticking) return; ticking = true; requestAnimationFrame(update); }; addEventListener('scroll', requestUpdate, { passive: true }); addEventListener('resize', requestUpdate, { passive: true }); update(); } function markScrollableRegions() { const candidates = document.querySelectorAll([ '.v281-path ol', '.dv2-local-nav__inner', '.dev740-engine__rail', '.dv21-domain-stages', '.v750-index-controls', '.resources-page-nav' ].join(',')); const inspect = () => { candidates.forEach((element) => { const scrollable = element.scrollWidth > element.clientWidth + 4; element.toggleAttribute('data-v770-scrollable', scrollable); if (scrollable && !element.hasAttribute('tabindex')) element.tabIndex = 0; }); }; inspect(); addEventListener('resize', inspect, { passive: true }); } function addLanguageBoundary() { const chineseOnlyForms = new Set([ 'contact-intent-paper-sample.html', 'sample.html', 'sample_antux.html', 'sample_casu.html', 'sample_dpu.html' ]); if (!chineseOnlyForms.has(currentFile)) return; const main = document.querySelector('main'); if (!main || main.querySelector('.v770-language-boundary')) return; const note = document.createElement('p'); note.className = 'v770-language-boundary'; note.setAttribute('role', 'note'); note.textContent = '项目申请流程当前以中文收集;英文项目可通过 Contact 页面联系专业团队。 · This intake form currently collects project information in Chinese; English enquiries can be routed through Contact.'; main.prepend(note); } function normalizeExternalLinks() { document.querySelectorAll('a[href^="http"]').forEach((link) => { try { const target = new URL(link.href, location.href); if (target.origin !== location.origin) { const rel = new Set((link.getAttribute('rel') || '').split(/\s+/).filter(Boolean)); rel.add('noopener'); rel.add('noreferrer'); link.setAttribute('rel', [...rel].join(' ')); } } catch (_) { // Invalid external links are reported by static QA; do not mutate them here. } }); } function init() { document.body.classList.add('v770-quality-ready'); enhanceArticleReading(); markScrollableRegions(); addLanguageBoundary(); normalizeExternalLinks(); scheduleBilingualStabilization(); } document.addEventListener('dbc:languagechange', scheduleBilingualStabilization); document.addEventListener('dbc:translations-loaded', scheduleBilingualStabilization); const languageObserver = new MutationObserver((mutations) => { if (mutations.some((mutation) => mutation.attributeName === 'lang' || mutation.attributeName === 'data-lang')) { scheduleBilingualStabilization(); } }); languageObserver.observe(root, { attributes: true, attributeFilter: ['lang', 'data-lang'] }); if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init, { once: true }); } else { init(); } })();