Skip to content

Commit

Permalink
fix: icon mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienfontaine committed Jun 26, 2024
1 parent a06a9ce commit ac8d439
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,47 @@ export async function applyRule(ruleParam, updateTitle) {
await chrome.runtime.sendMessage({ action: 'setMuted' });
}

let iconChangedByMe = false;

// Favicon handling
if (rule.tab.icon) {
if (rule.tab.icon && updateTitle) {
processIcon(rule.tab.icon);

const iconObserver = new MutationObserver((mutations) => {
if (!iconChangedByMe) {
mutations.forEach((mutation) => {
if (mutation.target.type === 'image/x-icon') {
processIcon(rule.tab.icon);
iconChangedByMe = true;
} else if (mutation.addedNodes.length) {
mutation.addedNodes.forEach((node) => {
if (node.type === 'image/x-icon') {
processIcon(rule.tab.icon);
iconChangedByMe = true;
}
});
} else if (mutation.removedNodes.length) {
mutation.removedNodes.forEach((node) => {
if (node.type === 'image/x-icon') {
processIcon(rule.tab.icon);
iconChangedByMe = true;
}
});
}
});
} else {
iconChangedByMe = false;
}
});

iconObserver.observe(document.head, {
attributes: true,
childList: true,
characterData: true,
subtree: true,
attributeOldValue: true,
characterDataOldValue: true,
});
}

if (rule.tab.protected) {
Expand Down

0 comments on commit ac8d439

Please sign in to comment.