mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-05 19:24:39 +00:00
Merge pull request #373 from Jaxx7594/icon-race
fix: Favicon race condition
This commit is contained in:
+32
-4
@@ -50,13 +50,31 @@ async function init() {
|
|||||||
documentLoadStyle.textContent = documentLoadCSS;
|
documentLoadStyle.textContent = documentLoadCSS;
|
||||||
document.head.appendChild(documentLoadStyle);
|
document.head.appendChild(documentLoadStyle);
|
||||||
|
|
||||||
const icons =
|
replaceIcons();
|
||||||
document.querySelectorAll<HTMLLinkElement>('link[rel*="icon"]');
|
|
||||||
|
|
||||||
icons.forEach((link) => {
|
const observer = new MutationObserver((mutations) => {
|
||||||
link.href = icon48;
|
for (const mutation of mutations) {
|
||||||
|
|
||||||
|
if (
|
||||||
|
mutation.type === "attributes" &&
|
||||||
|
mutation.target instanceof HTMLLinkElement &&
|
||||||
|
mutation.target.rel.includes("icon") &&
|
||||||
|
mutation.attributeName === "href"
|
||||||
|
) {
|
||||||
|
replaceIcons();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
observer.observe(document.head, {
|
||||||
|
subtree: true,
|
||||||
|
attributes: true,
|
||||||
|
attributeFilter: ["href"],
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await initializeSettingsState();
|
await initializeSettingsState();
|
||||||
|
|
||||||
@@ -85,3 +103,13 @@ async function init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function replaceIcons() {
|
||||||
|
document
|
||||||
|
.querySelectorAll<HTMLLinkElement>('link[rel*="icon"]')
|
||||||
|
.forEach((link) => {
|
||||||
|
if (link.href !== icon48) {
|
||||||
|
link.href = icon48;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user