good/代码 给memos 插入一个备案号
async function insertBeianLink() {
// 检查是否已经插入了备案号链接
if (document.getElementById("header-beian") !== null) {
return;
}
// 等待目标元素加载完成
let insertionTries = 0;
const targetSelector = "#root > div.w-full.min-h-full.bg-zinc-100.dark\\:bg-zinc-800 > div.w-full.max-w-6xl.mx-auto.flex.flex-row.justify-center.items-start.sm\\:px-4 > div > header > div.w-full.px-2.py-2.flex.flex-col.justify-start.items-start.shrink-0.space-y-2";
let targetElement = document.querySelector(targetSelector);
while (targetElement === null && insertionTries < 20) {
await new Promise((r) => setTimeout(r, 100));
targetElement = document.querySelector(targetSelector);
insertionTries++;
}
// 获取目标元素
if (targetElement === null) {
console.error("Target element not found.");
return;
}
// 插入备案号链接
targetElement.insertAdjacentHTML(
"beforeend",
`
备案号:12345678
`
);
}
// 在页面加载完成后插入备案号链接
(async () => {
try {
await insertBeianLink();
} catch (e) {
console.error(e);
}
})();