mirror of
https://github.com/ranaldsgift/KefinTweaks.git
synced 2026-11-05 15:52:47 +01:00
Move to single global document observer where possible and relevant
This commit is contained in:
+35
-38
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user