profile menu
This commit is contained in:
@@ -31,6 +31,37 @@ window.html = function html(elementString) {
|
||||
return doc.body.firstChild;
|
||||
}
|
||||
|
||||
window.util = {}
|
||||
window.util.getColor = function(name) {
|
||||
const rootStyles = getComputedStyle(document.documentElement);
|
||||
const color = rootStyles.getPropertyValue(`--${name}`).trim();
|
||||
if(!color) {
|
||||
throw new Error("Color not found")
|
||||
}
|
||||
return color
|
||||
}
|
||||
|
||||
window.util.observeClassChange = (el, callback) => {
|
||||
if (!el || !(el instanceof Element)) {
|
||||
throw new Error("observeClassChange requires a valid DOM element.");
|
||||
}
|
||||
|
||||
const observer = new MutationObserver((mutations) => {
|
||||
for (const mutation of mutations) {
|
||||
if (mutation.type === "attributes" && mutation.attributeName === "class") {
|
||||
callback(el.classList);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(el, {
|
||||
attributes: true,
|
||||
attributeFilter: ["class"]
|
||||
});
|
||||
|
||||
return observer; // Optional: return it so you can disconnect later
|
||||
}
|
||||
|
||||
|
||||
/* JQUERY */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user