js-tampermonkey-public-scripts/setupObserver MutationObserver exapmle.user.js
Unkas Amanjolov 42b29defae first commit
2024-10-07 10:25:50 +05:00

47 lines
1.5 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ==UserScript==
// @name setupObserver MutationObserver exapmle
// @namespace http://your.namespace.here/
// @version 0.1
// @description Your description here
// @author You
// @run-at document-end
// @match https://trello.com3/*
// @grant none
// ==/UserScript==
(async function () {
'use strict';
async function setupObserver() {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.target.matches('#chrome-container > div.window-overlay > div')) {
const hasWindowClass = mutation.target.classList.contains('window');
if (hasWindowClass) {
console.log('ЕСТЬ!');
} else {
console.log('Ничего не изменилось');
}
}
});
});
const targetElement = document.querySelector('#chrome-container > div.window-overlay > div');
if (targetElement) {
observer.observe(targetElement, {
attributes: true,
subtree: true,
attributeFilter: ['class'],
});
} else {
// Если элемент еще не существует, повторно вызываем setupObserver через некоторое время
setTimeout(setupObserver, 1000);
}
}
setupObserver();
})();