Better Buzz Maths

Fixes the weird math test images in Agilix Buzz

目前為 2024-08-29 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Better Buzz Maths
// @namespace    https://greasyfork.org/users/1359538
// @version      1.1
// @description  Fixes the weird math test images in Agilix Buzz
// @author       Deniz
// @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 urlCheck = /^https:\/\/cdn\.flvs\.net\/assessment_images\/.*math/;
    const processDelay = 30;

    let queue = [];
    let processing = false;

    function next() {
        if (queue.length === 0) {
            processing = false;
            document.querySelectorAll("img").forEach(fixImg);
            return;
        }
        const img = queue.shift();
        if (img) {
            fixImg(img);
        }
        setTimeout(next,processDelay);
    }

    function queueProcess() {
        if (processing) return;
        processing = true;
        next();
    }

    function queueImg(img) {
        queue.push(img);
        queueProcess();
    }

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

    const observer = new MutationObserver((mutationsList) => {
        for (const mut of mutationsList) {
            if (mut.type === 'childList') {
                for (const n of mut.addedNodes) {
                    if (n.tagName === 'IMG') {
                        queueImg(n);
                    }
                }
            }
        }
    });

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

}());