function ResetScrollBar() { window.scrollTo({ "top": 0, "left": 0, "behavior": "instant" }); } function IsPhone() { return /Mobi|Android|iPhone/i.test(navigator.userAgent); } function EventTrack(action, param) { // 埋点 if (window.location.protocol == "file:") { console.log(`EventTrack("${action}/${param}") OK.`); return; } let url = (location.hostname != "localhost") ? "https://api.joyida.com/track" : "/track"; const event = { action: action, param: param, width: window.innerWidth, height: window.innerHeight }; fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(event), }).then(response => { if (response.ok) { return response.json(); } }).then(data => { if (!data.ok) { console.log(data.data); } }).catch(error => console.error(error.message)); } function OpenPage(clickMenu) { const isPhone = IsPhone(); document.querySelectorAll("[data-bs-toggle=tooltip]").forEach(tooltip => { if (tooltip.hasAttribute("href")) { // 有链接 if (isPhone) { // 手机环境,只保留 href tooltip.removeAttribute("onclick"); tooltip.removeAttribute("data-bs-toggle"); tooltip.removeAttribute("data-bs-placement"); tooltip.removeAttribute("data-bs-title"); } else { // 电脑环境 tooltip.removeAttribute("href"); } } if (tooltip.hasAttribute("data-bs-toggle")) { new bootstrap.Tooltip(tooltip); } }); // 展示菜单 let rootNode = document.querySelector("ul.my-menu1"); if (rootNode) { InitMenu(rootNode); } // 点击首项 if (clickMenu) { let corpNode = document.querySelector("ul.my-menu2 li[my-path]"); if (corpNode) { MenuClick(corpNode, false); } } EventTrack("page", "open"); } function ClosePage() { EventTrack("page", "close"); } function ShowTitle(target, text) { let tooltip = bootstrap.Tooltip.getInstance(target); if (tooltip) { let title = tooltip._config.title; // 备份 tooltip._config.title = text; // 替换 tooltip.update(); // 更新 tooltip.show(); // 立即展示 tooltip._config.title = title; // 还原 tooltip.update(); // 更新(暂不展示) } } function CopyText(target) { // https://developer.mozilla.org/zh-CN/docs/Web/API/Clipboard/writeText let text = target.innerText || target.getAttribute("my-text"); navigator.clipboard.writeText(text).then(function () { ShowTitle(target, "已复制"); }, function (error) { ShowTitle(target, "未复制"); }); EventTrack("copy", text); } function InitMenu(rootNode) { let rootHtml = "\n"; for (typeId in menuJson) { rootHtml += `\t