Better Buzz Maths

Fixes the weird math test images in Agilix Buzz

// ==UserScript==
// @name         Better Buzz Maths
// @namespace    https://greasyfork.org/users/1359538
// @version      1.5
// @description  Fixes the weird math test images in Agilix Buzz
// @license      MIT
// @icon         https://www.google.com/s2/favicons?sz=64&domain=agilixbuzz.com
// @homepage     https://greasyfork.org/scripts/505681
// @match        https://legacy.agilixbuzz.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const url = /cdn\.flvs\.net\/.*math_.*/;

    function fixImg(img) {
        if (url.test(img.src)) {
            img.style.filter = 'brightness(0.5) invert(1)';
        }
    }

    document.querySelectorAll('img').forEach(img => fixImg(img));

    const observer = new MutationObserver((mutationsList) => {
        for (const mut of mutationsList) {
            if (mut.type === 'childList') {
                for (const n of mut.addedNodes) {
                    if (n.tagName === 'IMG') {
                        fixImg(n);
                    } else if (n.nodeType === Node.ELEMENT_NODE) {
                        n.querySelectorAll('img').forEach(img => fixImg(img));
                    }
                }
            }
        }
    });

    observer.observe(document.body, {childList: true, subtree: true});
}());