(() => {
'use strict';
const html = document.documentElement;
if (html.dataset.v7318BiotenGovernance !== 'professional-platform-r2') return;
const heroTitleZh = '让 PHA 水性功能乳液,\n 成为可设计、可验证的\n 产业材料。';
const heroTitleEn = 'Making PHA-based\n waterborne functional emulsions\n designable and verifiable\n for industrial applications.';
const observedNavigationSurfaces = new WeakSet();
let scheduled = false;
let readingAnchor = null;
const setAttribute = (element, name, value) => {
if (element && element.getAttribute(name) !== value) element.setAttribute(name, value);
};
const isEnglish = () => /^en\b/i.test(html.dataset.lang || html.lang || '');
function syncLanguageUrl(language) {
const pageHistory = window.history;
if (!pageHistory?.replaceState) return;
const url = new URL(window.location.href);
const next = /^en\b/i.test(language || '') ? 'en' : 'zh';
if (url.searchParams.get('lang') === next) return;
url.searchParams.set('lang', next);
pageHistory.replaceState(pageHistory.state, '', `${url.pathname}${url.search}${url.hash}`);
}
function navigationSurfaces() {
return [...document.querySelectorAll([
'#dbc-global-navigation',
'.dbc-desktop-mega-panel',
'[id^="dbc-desktop-mega-"]',
].join(','))];
}
function syncNavigationInert() {
for (const surface of navigationSurfaces()) {
const closed = surface.hidden
|| surface.getAttribute('aria-hidden') === 'true'
|| (!surface.classList.contains('is-open') && surface.matches('.dbc-desktop-mega-panel, [id^="dbc-desktop-mega-"]'));
surface.inert = closed;
if (!observedNavigationSurfaces.has(surface)) {
observedNavigationSurfaces.add(surface);
new MutationObserver(syncNavigationInert).observe(surface, {
attributes: true,
attributeFilter: ['aria-hidden', 'hidden', 'class'],
});
}
}
}
function captureReadingPosition() {
const headerBottom = document.querySelector('.site-header')?.getBoundingClientRect().bottom || 0;
const line = headerBottom + 24;
const sections = [...document.querySelectorAll('main#main-content > section')];
const intersecting = sections.filter((section) => {
const rect = section.getBoundingClientRect();
return rect.top <= line && rect.bottom > line;
});
const element = intersecting.at(-1)
|| sections.find((section) => section.getBoundingClientRect().top > line)
|| null;
readingAnchor = element ? { element, top: element.getBoundingClientRect().top, capturedAt: performance.now() } : null;
html.dataset.v7318ReadingAnchor = element?.id || 'none';
html.dataset.v7318ReadingAnchorTop = readingAnchor ? readingAnchor.top.toFixed(2) : '';
}
function restoreReadingPosition(delay = 0) {
const snapshot = readingAnchor;
if (!snapshot) return;
setTimeout(() => {
requestAnimationFrame(() => {
if (readingAnchor !== snapshot || !snapshot.element.isConnected) return;
const delta = snapshot.element.getBoundingClientRect().top - snapshot.top;
html.dataset.v7318ReadingRestore = snapshot.element.id || 'anonymous';
html.dataset.v7318ReadingDelta = delta.toFixed(2);
if (Math.abs(delta) > 1) {
const root = document.documentElement;
const previousScrollBehavior = root.style.scrollBehavior;
root.style.scrollBehavior = 'auto';
window.scrollBy(0, delta);
root.style.scrollBehavior = previousScrollBehavior;
html.dataset.v7318ReadingApplied = snapshot.element.id || 'anonymous';
}
});
}, delay);
}
function applyGovernance() {
scheduled = false;
const english = isEnglish();
const logo = document.querySelector('.site-header .logo-image-biocycle');
const logoImage = logo?.querySelector('img');
setAttribute(logo, 'href', 'bioten-platform.html');
setAttribute(logo, 'data-aria-cn', '博碳生物主页');
setAttribute(logo, 'data-aria-en', 'BIOTEN homepage');
setAttribute(logo, 'aria-label', english ? 'BIOTEN homepage' : '博碳生物主页');
setAttribute(logo, 'data-v7318-bioten-logo-route', 'platform-home');
setAttribute(logoImage, 'data-alt-cn', 'BIOTEN 博碳生物');
setAttribute(logoImage, 'data-alt-en', 'BIOTEN');
setAttribute(logoImage, 'alt', english ? 'BIOTEN' : 'BIOTEN 博碳生物');
const languageToggle = document.querySelector('[data-language-toggle]');
const languageLabel = english ? 'Switch to Chinese' : '切换至英文';
setAttribute(languageToggle, 'aria-label', languageLabel);
setAttribute(languageToggle, 'title', languageLabel);
const kicker = document.querySelector('.btp580-hero .btp580-kicker');
const kickerZh = 'BIOTEN 博碳生物 | PHA 生物基水性功能乳液';
const kickerEn = 'BIOTEN | PHA-based waterborne functional emulsions';
setAttribute(kicker, 'data-nav-cn', kickerZh);
setAttribute(kicker, 'data-nav-en', kickerEn);
if (kicker && kicker.textContent.trim() !== (english ? kickerEn : kickerZh)) {
kicker.textContent = english ? kickerEn : kickerZh;
}
const heroTitle = document.querySelector('#btp580-title');
const governedHeroTitle = english ? heroTitleEn : heroTitleZh;
if (heroTitle && heroTitle.innerHTML.trim() !== governedHeroTitle.trim()) {
heroTitle.innerHTML = governedHeroTitle;
}
setAttribute(heroTitle, 'data-v7318-hero-copy', english ? 'directional-en' : 'accepted-zh');
const methodImage = document.querySelector('.btp580-system__visual img');
const imageZh = '水性乳液、材料状态与刮涂试样的研发编辑示意,不作为实验现场、样品或测试证据';
const imageEn = 'Editorial R&D illustration of waterborne emulsions, material states and drawdown samples; not experimental, sample or test evidence';
setAttribute(methodImage, 'data-alt-cn', imageZh);
setAttribute(methodImage, 'data-alt-en', imageEn);
setAttribute(methodImage, 'alt', english ? imageEn : imageZh);
const capabilities = document.querySelector('.btp580-capabilities');
setAttribute(capabilities, 'data-aria-cn', '博碳生物研发控制维度');
setAttribute(capabilities, 'data-aria-en', 'BIOTEN R&D control dimensions');
setAttribute(capabilities, 'aria-label', english ? 'BIOTEN R&D control dimensions' : '博碳生物研发控制维度');
syncNavigationInert();
html.dataset.v7318BiotenRuntime = 'ready';
}
function scheduleGovernance() {
if (scheduled) return;
scheduled = true;
requestAnimationFrame(applyGovernance);
}
function start() {
applyGovernance();
const header = document.querySelector('.site-header');
if (header) {
new MutationObserver(() => {
scheduleGovernance();
syncNavigationInert();
}).observe(header, { childList: true, subtree: true });
}
new MutationObserver(() => {
scheduleGovernance();
restoreReadingPosition(0);
restoreReadingPosition(80);
restoreReadingPosition(200);
restoreReadingPosition(400);
restoreReadingPosition(440);
restoreReadingPosition(700);
restoreReadingPosition(960);
}).observe(html, { attributes: true, attributeFilter: ['lang', 'data-lang'] });
const skipLink = document.querySelector('.skip-link');
const main = document.querySelector('#main-content');
skipLink?.addEventListener('click', () => {
requestAnimationFrame(() => main?.focus({ preventScroll: true }));
});
document.addEventListener('pointerdown', (event) => {
if (event.target.closest('[data-language-toggle]')) captureReadingPosition();
}, true);
document.addEventListener('keydown', (event) => {
if ((event.key === 'Enter' || event.key === ' ') && event.target.closest('[data-language-toggle]')) {
captureReadingPosition();
}
}, true);
document.addEventListener('click', (event) => {
if (event.target.closest('[data-language-toggle]')) setTimeout(scheduleGovernance, 0);
}, true);
document.addEventListener('dbc:languagechange', (event) => {
syncLanguageUrl(event.detail?.language || (isEnglish() ? 'en' : 'zh'));
scheduleGovernance();
restoreReadingPosition(0);
restoreReadingPosition(80);
restoreReadingPosition(200);
restoreReadingPosition(400);
restoreReadingPosition(440);
restoreReadingPosition(700);
restoreReadingPosition(960);
});
const bodySurfaceObserver = new MutationObserver(syncNavigationInert);
bodySurfaceObserver.observe(document.body, { childList: true });
syncNavigationInert();
window.addEventListener('pageshow', scheduleGovernance);
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', start, { once: true });
else start();
})();