agent-Specialization/website-design/site-manual/js/main.js
JOJO 39a7a5fc6f chore(website): 归档官网文档内容与设计素材
- website-content/:官网 10 篇文档内容 + README
- website-design/:官网设计稿、动画实验、预览图与资源
- 根目录官网截图两张
- .gitignore 忽略 website-design/exp/static/dist 构建产物(7.1MB)
2026-09-02 14:38:51 +08:00

56 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* Astrion 官网 C —— 交互(形象 / scrollspy / 复制) */
(function () {
'use strict';
AstrionAvatar.mount(document.getElementById('sideAvatar'), { mode: 'idle', blink: true, track: true });
/* scrollspy目录高亮当前章节 */
var links = Array.prototype.slice.call(document.querySelectorAll('.toc-item'));
var chapters = links
.map(function (a) { return document.querySelector(a.getAttribute('href')); })
.filter(Boolean);
var spy = new IntersectionObserver(function (entries) {
entries.forEach(function (e) {
if (!e.isIntersecting) return;
links.forEach(function (a) {
a.classList.toggle('current', a.getAttribute('href') === '#' + e.target.id);
});
});
}, { rootMargin: '-20% 0px -65% 0px' });
chapters.forEach(function (c) { spy.observe(c); });
/* 复制按钮:固定尺寸,只换图标 */
document.querySelectorAll('[data-copy]').forEach(function (btn) {
var timer = null;
btn.addEventListener('click', function () {
var block = btn.parentElement.querySelector('pre code');
var text = block ? block.textContent : '';
function mark() {
btn.classList.add('copied');
clearTimeout(timer);
timer = setTimeout(function () { btn.classList.remove('copied'); }, 1600);
}
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(text).then(mark, function () { fallback(text); mark(); });
} else {
fallback(text);
mark();
}
});
});
function fallback(text) {
var ta = document.createElement('textarea');
ta.value = text;
ta.style.position = 'fixed';
ta.style.opacity = '0';
document.body.appendChild(ta);
ta.select();
try { document.execCommand('copy'); } catch (e) {}
document.body.removeChild(ta);
}
})();