Move to single global document observer where possible and relevant

This commit is contained in:
HighImKevin
2026-10-12 04:44:40 -04:00
parent 5d34fd09d9
commit 34bb37ff27
13 changed files with 874 additions and 329 deletions
+35 -38
View File
@@ -237,50 +237,47 @@
});
}
// Set up MutationObserver to watch for new overlay containers
// Shared body observer: inject when card overlays appear
function setupRemoveContinueButtonObserver() {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'childList') {
// Check for added nodes
mutation.addedNodes.forEach((node) => {
if (node.nodeType === Node.ELEMENT_NODE) {
// Check if the added node is an overlay container
if (node.classList && node.classList.contains('cardOverlayContainer')) {
const buttonContainer = node.querySelector('.cardOverlayButton-br');
if (buttonContainer) {
addRemoveContinueButton(node);
}
}
// Check for overlay containers within the added node
const overlayContainers = node.querySelectorAll && node.querySelectorAll('.cardOverlayContainer');
if (overlayContainers && overlayContainers.length > 0) {
overlayContainers.forEach((overlayContainer) => {
const buttonContainer = overlayContainer.querySelector('.cardOverlayButton-br');
if (buttonContainer) {
addRemoveContinueButton(overlayContainer);
}
});
}
}
});
const processNode = (node) => {
if (!node || node.nodeType !== Node.ELEMENT_NODE) return;
if (node.classList?.contains('cardOverlayContainer')) {
if (node.querySelector('.cardOverlayButton-br')) addRemoveContinueButton(node);
}
node.querySelectorAll?.('.cardOverlayContainer').forEach((overlayContainer) => {
if (overlayContainer.querySelector('.cardOverlayButton-br')) {
addRemoveContinueButton(overlayContainer);
}
});
});
// Start observing
observer.observe(document.body, {
childList: true,
subtree: true
});
// Process any existing overlay containers
};
const onMutations = (mutations) => {
for (const mutation of mutations) {
if (mutation.type !== 'childList') continue;
mutation.addedNodes.forEach(processNode);
}
};
const utils = window.KefinTweaksUtils;
if (utils?.onBodyMutation) {
utils.onBodyMutation('removeContinue-overlays', onMutations);
} else if (typeof MutationObserver !== 'undefined' && document.body) {
const observer = new MutationObserver(onMutations);
observer.observe(document.body, { childList: true, subtree: true });
}
processExistingOverlayContainers();
}
// Initialize the observer
setupRemoveContinueButtonObserver();
function startRemoveContinue() {
if (!window.KefinTweaksUtils?.onBodyMutation && !document.body) {
setTimeout(startRemoveContinue, 500);
return;
}
setupRemoveContinueButtonObserver();
}
startRemoveContinue();
// Debug function for troubleshooting (available in console)
window.debugRemoveContinueButtons = function() {