Blookedex Integration

An efficient Blooket overhaul with blookedex integrations.

// ==UserScript==
// @name         Blookedex Integration
// @namespace    http://tampermonkey.net/
// @version      2025-05-23
// @description  An efficient Blooket overhaul with blookedex integrations.
// @author       fsscooter
// @match        https://*.blooket.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=blooket.com
// @grant        none
// @license GNU GPLv3
// ==/UserScript==

(function() {
    'use strict';

    const version = "2025-05-23";

    //w3schools minfied cookie managers
    function setCookie(e,t,o){let i=new Date;i.setTime(i.getTime()+864e5*o);let n="expires="+i.toUTCString();document.cookie=`${e}=${encodeURIComponent(t)}; ${n}; path=/; domain=.blooket.com; secure; samesite=Lax`}function getCookie(e){let t=e+"=",o=decodeURIComponent(document.cookie),i=o.split(";");for(let n of i){for(;" "===n.charAt(0);)n=n.substring(1);if(0===n.indexOf(t))return n.substring(t.length,n.length)}return null}

    const themes = [
        { name: "blooket", primary: "#9A48AA", secondary: "#08C2D0", background: "#08C2D0" },
        { name: "sunset", primary: "#E44C51", secondary: "#FFA41B", background: ["#5d87e3", "#ff3b8c"] },
        { name: "forest", primary: "#2E8B57", secondary: "#A3C586", background: ["#1B512D", "#A4DE02"] },
        { name: "ocean", primary: "#0077B6", secondary: "#90E0EF", background: ["#00B4D8", "#03045E"] },
        { name: "midnight", primary: "#1C1C2E", secondary: "#3E3E55", background: ["#3A3A7C", "#0F0F2D"] },
        { name: "sunrise", primary: "#FFA07A", secondary: "#FFD700", background: ["#FFDEE9", "#B5FFFC"] },
        { name: "aurora", primary: "#7F00FF", secondary: "#00FF87", background: ["#00FFC3", "#3E1E68"] },
        { name: "space", primary: "#4B0082", secondary: "#9370DB", background: ["#1F2833", "#0B0C10"] },
        { name: "peach", primary: "#FFADAD", secondary: "#FFD6A5", background: ["#FFEACD", "#FFDAC1"] },
        { name: "ice", primary: "#A0E9FD", secondary: "#CAF0F8", background: ["#B2EBF2", "#E0F7FA"] },
        { name: "coral", primary: "#148cdf", secondary: "#ee7de9", background: ["#ef1284", "#00b898"] },
        { name: "charcoal", primary: "#111a24", secondary: "#f8ee00", background: ["#aba400", "#1f3042"] },
        { name: "cotton candy", primary: "#ffcbcb", secondary: "#c9fdff", background: ["#9db1ea", "#e47e98"] },
        { name: "minecraft", primary: "#61371f", secondary: "#70b237", background: ["#3c44aa", "#3ab3da"], customShopkeeper: ["https://hollowvr.github.io/onlineassets/steveblooket.png", "1"], customStore: "https://hollowvr.github.io/onlineassets/mcstoreblooket.svg" },
        { name: "easter", primary: "#F8DC8A", secondary: "#F4A8CF", background: ["#B6E7B9", "#93DE8B"] },
        { name: "halloween", primary: "#F86D01", secondary: "#18e810", background: ["#A805F7", "#DA03F6"], customShopkeeper: ["https://hollowvr.github.io/onlineassets/jackolanternblooket.png","1.3"] },
        { name: "usa", primary: "#424173", secondary: "#B52A3A", background: "repeating-linear-gradient(-5deg,#dbdbdb,#dbdbdb 60px,#B52A3A 60px,#B52A3A 120px);", customShopkeeper: ["https://upload.wikimedia.org/wikipedia/commons/5/5a/Donald_Trump_cutout.png", "1.5"], customStore: "https://hollowvr.github.io/onlineassets/usastoreblooket.svg" },
        { name: "summer", primary: "#72D6E4", secondary: "#D8A93F", background: ["#89CDDA", "#FBDCA5"] },
        { name: "autumn", primary: "#C16A19", secondary: "#DFA628", background: ["#AD3B2D", "#D8284D"] },
        { name: "winter", primary: "#96CEFE", secondary: "#6C80BE", background: ["#A4F4FF", "#75A5C3"] },
        { name: "christmas", primary: "#C9001C", secondary: "#1FB34F", background: "radial-gradient(ellipse at bottom, #4e9a51 0%, #3d7b42 40%, #2f5e34 100%);", customShopkeeper: ["https://ac.blooket.com/marketassets/blooks/santaclaus.svg", "1"], customStore: "https://ac.blooket.com/dashclassic/assets/StoreWinter-DOhqNDCZ.svg" },
        { name: "marti gras", primary: "#A016FC", secondary: "#27DA3B", background: "linear-gradient(45deg,rgba(47, 163, 75, 1) 0%, rgba(140, 71, 151, 1) 50%, rgba(255, 204, 40, 1) 100%);" },
        { name: "haze", primary: "#4e4c29", customSidebar: "linear-gradient(to right, rgba(0,0,0,0) 40%, #4287f566 130%),repeating-linear-gradient(135deg,#535b1f 0%, rgba(83,91,31,0.8) 40%, #4b462c 70%, rgba(75,70,44,0.8) 100%)", secondary: "#f8de99", background: ["#fdbb35", "#ad1f25"] },
        { name: "midnight flare", primary: ["rgba(0, 20, 80, 0.8)", "rgba(0, 60, 255, 0.9)"], secondary: "#6c757d", background: ["#1a2b99", "#141414"] },
        { name: "twilight", primary: "rgba(38, 50, 56, 0.8)", secondary: "#b0bec5", background: ["#1a2327", "#37474f"] },
        { name: "blood moon", primary: "rgba(102, 0, 0, 0.8)", secondary: "#2f2f2f", background: ["#3e1414", "#000000"] },
        { name: "kraken", primary: "rgba(0, 51, 102, 0.8)", secondary: "#1abc9c", background: "linear-gradient(to bottom, #7db9e8 -5%, #005073 10%, #003e58 25%, #002a3d 55%, #000022 80%)", customShopkeeper: ["https://ac.blooket.com/marketassets/blooks/kraken.svg","1"] },
        { name: "pittsburgh", primary: "#000000", secondary: "#E0B800", background: ["#FFD700 0%", "#D4AF37 40%", "#B8860B 80%", "#2F1C00 100%"] },
        { name: "USSR", primary: "#C60300", secondary: "#F9D700", background: "radial-gradient(#ff0000, #a60000)", customShopkeeper: ["https://hollowvr.github.io/onlineassets/karlmarxblooket.png", "1.7"], customStore: "https://hollowvr.github.io/onlineassets/ussrstoreblooket.png" } //"radial-gradient(#ff0000, #db0202, #750000)"
    ];
    //   { name: "halloween", primary: "", secondary: "", background: ["", ""] }
    if (getCookie("blxdextheme") == null) {
        setCookie("blxdextheme", "5")
    }
    const theme = Number(getCookie("blxdextheme"))
    let background = "#fff"
    if (Array.isArray(themes[theme].background)) {
        background = 'linear-gradient('+themes[theme].background[0]+', '+themes[theme].background[1]+')';
    } else {
        background = themes[theme].background;
    }
    console.log(background)

    console.log("Blooket extension initialized");
    if (theme != 0) {
        const style = document.createElement('style');
        style.innerHTML = `
        :root {
            --purple: ${themes[theme].primary};
        }
        .blookedex-btnClose {
            transition:all .2s ease;
        }

        .blookedex-btnCloseGrandparent:hover .blookedex-btnClose {
            fill:#fff;
        }
        @keyframes blookedex-packImgKeyframes {
            from {transform:translateY(-50%) rotateY(90deg) scale(.1)}
            to {transform:translateY(-50%) rotateY(20deg) scale(1)}
        }
        .blookedex-packImg {
            animation: .5s cubic-bezier(.08,.54,.55,1.07) blookedex-packImgKeyframes;
        }
        .blookedex-buyBtn {
            transition: filter .25s;
        }
        .blookedex-buyBtn:hover {
            filter:brightness(110%);
        }
        .blookedex-buyBtn:hover > :first-child {
            transform:translateY(-2px);
        }
        .blookedex-buyBtn:hover > :nth-child(3) {
            transform:translateY(2px);
        }
        `;
        document.head.appendChild(style);
    }
    const applyBackground = () => {
        if (theme == 0) return;
        // Try primary selector
        let bgGradient = document.querySelector("div[data-sentry-component='Blooks']")?.children[0];

        // If not found, try fallback
        if (!bgGradient) {
            if (window.app?.children?.[0]?.children?.[0]?.children?.[6]) {
                bgGradient = window.app.children[0].children[0].children[6];
            }
        };

        if (!bgGradient) return;

        if (!bgGradient.className.includes('background')) return;

        bgGradient.style = "background: "+background
        console.log(bgGradient.style)
    };


    const correctColor = (el) => {
        if (theme == 0) return;
        const style = getComputedStyle(el);
        ['color', 'backgroundColor', 'borderColor'].forEach(prop => {
            const val = style[prop];
            if (val === 'rgb(154, 73, 170)' || val === 'rgb(64, 17, 95)') {
                el.style[prop] = themes[theme].primary;
            }
            if (val === 'rgb(11, 194, 207)' || val === 'rgb(122, 3, 157)') {
                el.style[prop] = themes[theme].secondary;
            }
            if (val === 'rgb(154, 73, 170)' && el.className.includes("statContainer")) {
                el.style[prop] = themes[theme].secondary;
            }
        });
    };

    const insertTab = (sideBar) => {
        if (typeof sideBar == 'undefined' || !sideBar.className.includes('sidebar') || sideBar.dataset.injected == "true") return;

        if (typeof themes[theme].customSidebar != 'undefined') sideBar.style = "background: "+themes[theme].customSidebar+" !important;background-color:transparent !important;"

        let clonedNode = sideBar.children[Math.min(3,sideBar.children.length-2)].cloneNode(true);
        if (sideBar.tagName == 'NAV') {
            clonedNode = sideBar.children[0].children[2].children[sideBar.children.length - 1].children[0].cloneNode(true);
        }
        clonedNode.href = "/my-sets?blookedex=true";
        clonedNode.children[0].classList.remove("fa-suitcase")
        clonedNode.classList.forEach(c => c.includes('pageSelected') && clonedNode.classList.remove(c));
        clonedNode.children[0].classList.add("fa-adjust")
        clonedNode.children[1].textContent = "Blookedex"
        clonedNode.onclick = function() {
            console.log("sucess")
        }
        if (sideBar.tagName == 'NAV') {
            (function(){if(!document.querySelector('link[href*="font-awesome"],link[href*="fontawesome"]')){let l=document.createElement('link');l.rel='stylesheet';l.href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css';document.head.appendChild(l);}})();
            clonedNode.children[0].remove()
            const icon = document.createElement('i')
            icon.className = "fas fa-adjust"
            icon.style = "font-size:22px;width:26px;text-align:center;"
            clonedNode.prepend(icon)


            const newElem = document.createElement('ul')
            newElem.appendChild(clonedNode)
            sideBar.children[0].children[2].appendChild(newElem)
            return;
        }
        if (window.location.href.includes("blookedex=true")) clonedNode.className = window.app.dataset.selectedClasses;
        sideBar.insertBefore(clonedNode, sideBar.childNodes[sideBar.children.length-1])
        sideBar.dataset.injected = "true"
    };

    const createCustomPage = () => {
        const body = window.app.children[0].children[0].children[6].cloneNode(false);
        window.app.children[0].children[0].children[6].style.display = "none";
        body.style = "display:flex;flex-direction:column;gap:20px;align-items:center;justify-content:center";
        body.innerHTML = '<div style="background:'+background+';position:fixed;width:100%;height:100%;left:0;top:0;overflow:hidden;"><div style="background-image: url(&quot;https://ac.blooket.com/dashclassic/assets/BlookCheckers-BykpA7vd.png&quot;);position: absolute;width: 200%;height: 200%;top: 50%;left: 50%;background-size: 550px;background-position: -100px -100px;opacity: .1;transform: translate(-50%,-50%) rotate(15deg)"></div></div>';
        const versionSection = document.createElement("div")
        versionSection.style = "position:relative;background-color:#efefef22;backdrop-filter:blur(10px);border:1px solid rgb(108, 117, 125);border-radius:20px;width:50rem;padding:20px;"
        versionSection.innerHTML = "<div style='font-family: Titan One;font-size: 44px;font-weight: 700;margin: 15px 5% 10px;color: #efefef;text-shadow:0 0 10px rgba(0,0,0,0.2);'>Version Info</div>"
        versionSection.appendChild(Object.assign(document.createElement('div'),{textContent: "Current Version: "+version, style: "font-size: 2em;"}))
        versionSection.appendChild(Object.assign(document.createElement('a'),{textContent: "Check Updates", href: "https://greasyfork.org/en/scripts/536421-blookedex-integration", style: "font-size: 2em;"}))
        const themeSection = document.createElement("div")
        themeSection.style = "position:relative;background-color:#efefef22;backdrop-filter:blur(10px);border:1px solid rgb(108, 117, 125);border-radius:20px;width:50rem;padding:20px;"
        themeSection.innerHTML = "<div style='font-family: Titan One;font-size: 44px;font-weight: 700;margin: 15px 5% 10px;color: #efefef;text-shadow:0 0 10px rgba(0,0,0,0.2);'>Select a Theme</div>"
        const themesContainer = document.createElement("div")
        themesContainer.style = "display: flex;flex-wrap: wrap;gap: 10px;width:100%;justify-content:center;";
        for (let i = 0;i < themes.length;i++) {
            let background = "#fff"
            if (Array.isArray(themes[i].background)) {
                background = 'linear-gradient('+themes[i].background[0]+', '+themes[i].background[1]+')';
            } else {
                background = themes[i].background;
            }
            const themeBox = document.createElement("div")
            themeBox.onclick = function() {setCookie("blxdextheme", String(i));window.location.reload();}
            themeBox.style = "width:120px;height:100px;border:2px solid "+((theme == i) ? "#0377fc" : "#e4e8ec33")+";border-radius:10px;background:#efefef22;--primary:"+themes[i].primary+";--secondary:"+themes[i].secondary+";--bgGradient:"+background+";";
            const previewBG = document.createElement("div");
            previewBG.style = "width:100%;height:80%;background:var(--bgGradient);border-radius:10px;cursor:pointer;overflow:hidden;position:relative;"
            const previewBar = document.createElement("div");
            previewBar.style = "position:absolute;left:0;top:0;height:100%;background:var(--primary);width:20px;box-shadow: 0 0 10px rgba(0,0,0,0.2), inset -3px 0 0 rgba(0,0,0,0.05);display:flex;flex-direction:column;gap:5px;padding:5px;align-items:center;"
            previewBar.innerHTML = "<div style='height:3px;width:15px;background:#efefefee;border-radius:10px;'></div><div style='height:8px;width:18px;background:"+themes[i].secondary+";border-radius:2px;'></div><div style='height:2px;width:10px;background:#efefefee;border-radius:10px;'></div><div style='height:2px;width:13px;background:#efefefee;border-radius:10px;'></div><div style='height:2px;width:15px;background:#efefefee;border-radius:10px;'></div><div style='height:2px;width:10px;background:#efefefee;border-radius:10px;'></div><div style='height:2px;width:8px;background:#efefefee;border-radius:10px;'></div><div style='height:2px;width:13px;background:#efefefee;border-radius:10px;'></div>"
            previewBG.appendChild(previewBar)
            themeBox.appendChild(previewBG)
            const themeName = document.createElement("div")
            themeName.textContent = themes[i].name
            themeName.style = "margin-left:7px;"
            themeBox.appendChild(themeName)
            themesContainer.appendChild(themeBox)
        }
        themeSection.appendChild(themesContainer)
        body.appendChild(versionSection)
        body.appendChild(themeSection)
        window.app.children[0].children[0].appendChild(body)





        const sidebar = window.app.children[0].children[0].children[0]
        const mo = new MutationObserver(() => {
            if (sidebar.children.length === 10) {
                mo.disconnect();
                insertTab(sidebar);
            }
        });
        mo.observe(sidebar, { childList: true });

    };

    const walkAndFix = (node) => {
        if (node.nodeType === Node.ELEMENT_NODE) {
            correctColor(node);
            if (typeof node.className == 'string' && node.className.includes("background")) {
                applyBackground();
                console.log(node)
            }
            if (typeof node.className == 'string' && (node.className.includes("bottomRow") || node.className.includes("Sidebar_footerWrapper"))) {
                try {
                    insertTab([...document.querySelectorAll('*')].find(e => String(e.className).includes('sidebar')));
                } catch (err) {}
            }
            if (typeof node.className == 'string' && (node.className.includes("spacer") && node.parentNode.className.includes("profileBody")) && window.location.href.includes("blookedex=true")) {
                createCustomPage();
            }
            if (typeof node.className == 'string' && (node.className.includes("topFolderButton") || node.className.includes("searchBar")) && window.location.href.includes("blookedex=true")) {
                node.style.display = "none";
            }
            if (typeof node.className == 'string' && node.className.includes("cashier") && window.location.pathname == "/market" && typeof themes[theme].customShopkeeper != 'undefined') {
                node.src = themes[theme].customShopkeeper[0];
                node.style = "transform: rotate(10deg) scale("+themes[theme].customShopkeeper[1]+")";
            }
            if (typeof node.className == 'string' && node.className.includes("storeImg") && window.location.pathname == "/market" && typeof themes[theme].customStore != 'undefined') {
                node.src = themes[theme].customStore;
                node.style = "filter: drop-shadow(0 0 5px #0004)";
            }
            if (node && typeof node.className === 'string' && node.className.includes("modal") && node.children[0] && typeof node.children[0].className === 'string' && node.children[0].className.includes("container")) {
                function runLogic() {
                    const matches = [...node.children[0].querySelectorAll("*")]
                    .filter(e => String(e.className).includes('button_'));
                    if (matches.length !== 2) return;

                    const container = node.children[0];
                    container.style.display = 'none';

                    const packName = container.firstChild.firstChild.childNodes[1].textContent.substr(13);
                    const packCost = +container.firstChild.firstChild.childNodes[3].textContent.match(/\d+/);


                    const menu = document.createElement("div");
                    menu.style = "width:500px;height:250px;background:var(--purple);border: solid 6px hsla(0, 0%, 100%, .2); border-radius:5px;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);font-size:26px;perspective: 300px;";

                    const closeButton = document.createElement("button");
                    closeButton.className = "blookedex-btnCloseGrandparent";
                    closeButton.style = "background:transparent;border:none;outline:none;padding:8px;font-size:26px;position:absolute;top:3px;right:10px;cursor:pointer;";
                    closeButton.onclick = () => matches[0].click();
                    closeButton.innerHTML = '<svg style="width:.6875em;height:1em;" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 352 512"><path class="blookedex-btnClose" fill="hsla(0, 0%, 100%, .2)" d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"/></svg>';

                    const nametopackimg = {
                        "Bug Pack": "https://ac.blooket.com/dashclassic/assets/Bug_Pack-Cm44315z.png",
                        "Pirate Pack": "https://ac.blooket.com/dashclassic/assets/Pirate_Pack-Uir9GffU.png",
                        "Outback Pack": "https://ac.blooket.com/dashclassic/assets/Outback_Pack-Y8OWSe8a.png",
                        "Ice Monster Pack": "https://ac.blooket.com/dashclassic/assets/Ice_Monsters_Pack-BkSPnfqh.png",
                        "Dino Pack": "https://ac.blooket.com/dashclassic/assets/Dino_Pack-DAApPtRS.png",
                        "Aquatic Pack": "https://ac.blooket.com/dashclassic/assets/Aquatic_Pack-jzoFduWG.png",
                        "Safari Pack": "https://ac.blooket.com/dashclassic/assets/Safari_Pack-CH238vQG.png",
                        "Bot Pack": "https://ac.blooket.com/dashclassic/assets/Bot_Pack-DH_cssp8.png",
                        "Space Pack": "https://ac.blooket.com/dashclassic/assets/Space_Pack-Ck3VoVFZ.png",
                        "Medieval Pack": "https://ac.blooket.com/dashclassic/assets/Medieval_Pack-Cv60cQFL.png",
                        "Wonderland Pack": "https://ac.blooket.com/dashclassic/assets/Wonderland_Pack-CaB8iqtb.png",
                        "Breakfast Pack": "https://ac.blooket.com/dashclassic/assets/Breakfast_Pack-Dbk28uOc.png",
                    }
                    console.log(packName);

                    const packImg = document.createElement("div");
                    packImg.style = "filter:drop-shadow(0 0 10px rgba(0,0,0,0.4));background-image:url("+nametopackimg[packName]+");width:204.55px;height:225px;background-size: 204.55px 225px;position:absolute;top:50%;left:25px;transform:translateY(-50%) rotateY(20deg);"
                    packImg.className = "blookedex-packImg";

                    menu.addEventListener('mousemove', e => {
                        const rect = packImg.getBoundingClientRect();
                        const x = e.clientX - rect.left + 100; // x position within the box
                        const y = e.clientY - rect.top; // y position within the box

                        const rotateX = ((y / rect.height) - 0.5) * -10; // max 5° rotation
                        const rotateY = ((x / rect.width) - 0.5) * 10;

                        packImg.style.transform = `translateY(-50%) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`;
                    });

                    menu.addEventListener('mouseleave', () => {
                        packImg.style.transform = 'translateY(-50%) rotateX(0deg) rotateY(10deg)';
                    });

                    const buyBtn = document.createElement('button')
                    buyBtn.className = "blookedex-buyBtn"
                    buyBtn.style = "position:absolute;width:250px;height: 55px;top:calc(100% - 65px);right:10px;padding:0;cursor:pointer;background:transparent;border:none;outline:none;"
                    buyBtn.innerHTML = "<div style='transition:transform .25s cubic-bezier(.3,.7,.4,1);font-family:Titan One;font-size:30px;display:flex;align-items:center;justify-content:center;text-shadow: 2px 2px 0 rgba(0,0,0,0.2);color:white;background:"+themes[theme].secondary+";width:100%;height:calc(100% - 15px);position:absolute;top:5px;z-index:3;border-radius:5px;'>Purchase</div><div style='background:"+themes[theme].secondary+";width:100%;height:calc(100% - 15px);position:absolute;top:9px;filter:brightness(.8);z-index:2;border-radius:5px;'></div><div style='background:#00000040;width:100%;height:calc(100% - 15px);position:absolute;top:12px;z-index:1;border-radius:5px;transition:transform .25s cubic-bezier(.3,.7,.4,1);'></div>"
                    buyBtn.onclick = () => matches[1].click();

                    const infoTitle = document.createElement("div");
                    infoTitle.style = "position:absolute;right:50px;width:200px;height:50px;top:20px;font-family:Titan One;font-size:30px;display:flex;align-items:center;text-shadow: 2px 2px 0 rgba(0,0,0,0.2);color:white;"
                    infoTitle.textContent = packName

                    const infoCost = document.createElement("div");
                    infoCost.style = "position:absolute;right:185px;width:65px;height:30px;top:80px;background:#00000040;font-family:Titan One;font-size:20px;display:flex;align-items:center;text-shadow: 2px 2px 0 rgba(0,0,0,0.2);color:white;padding-left:5px;border-radius:5px;"
                    infoCost.innerHTML = "<img src='https://ac.blooket.com/dashclassic/assets/Token-DmrosBZF.svg' alt='Token' draggable='false' style='height:20px;height:20px;margin-right:7px;' />"+packCost;

                    menu.appendChild(buyBtn);
                    menu.appendChild(closeButton);
                    menu.appendChild(packImg);
                    menu.appendChild(infoTitle);
                    menu.appendChild(infoCost)
                    node.appendChild(menu);

                    console.log(matches);
                }

                // Run immediately if ready
                const initialMatches = [...node.children[0].querySelectorAll("*")]
                .filter(e => String(e.className).includes('button_'));
                if (initialMatches.length === 2) {
                    runLogic();
                } else {
                    // Wait for the buttons to appear
                    const observer = new MutationObserver(() => {
                        const updatedMatches = [...node.children[0].querySelectorAll("*")]
                        .filter(e => String(e.className).includes('button_'));
                        if (updatedMatches.length === 2) {
                            observer.disconnect();
                            runLogic();
                        }
                    });

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

            }
            if (typeof node.className == 'string' && node.className.includes("profileBody") && !window.location.href.includes("blookedex=true") && (window.location.pathname != "/stats" || window.location.pathname != "/blooks")) {
                if (theme == 0) return;
                window.app.children[0].children[0].classList.add("blookedex-bgInject");
                if (window.app.dataset.backgroundInjected == "true") document.getElementById("blookedex-customStyles").remove();
                const style = document.createElement('style');
                style.id = "blookedex-customStyles"
                style.innerHTML = `
.blookedex-bgInject {
    background-image: ${background};
}
.blookedex-bgInject::before {
    content: "";display:block;position:fixed;
    background-image: url(https://ac.blooket.com/dashclassic/assets/BlookCheckers-BykpA7vd.png);width: 200%;height: 200%;top: 50%;left: 50%;background-size: 550px;background-position: -100px -100px;opacity: .1;transform: translate(-50%,-50%) rotate(15deg);
}
.${[...node.querySelectorAll('*')].find(e => String(e.className).includes('header'))?.className}, .${[...node.querySelectorAll('*')].find(e => String(e.className).includes('subheader'))?.className} {
    font-family: Titan One;
    color:white;
    text-shadow: .1em .1em 0 rgba(0,0,0,0.4), 0 0 .2em rgba(0,0,0,0.2);
}
                `;
                document.head.appendChild(style);
                window.app.dataset.backgroundInjected = "true"
            }
            if (typeof node.className == 'string' && node.className.includes("pageSelected") && window.location.href.includes("blookedex=true") && node.href == "https://dashboard.blooket.com/my-sets") {
                window.app.dataset.selectedClasses = node.className
                node.classList.forEach(c => c.includes('pageSelected') && node.classList.remove(c));
                node.style = ""
                node.addEventListener('click', function() {
                    window.location.href = "/my-sets";
                });
                node.childrenNodes[0].style = ""
                node.childrenNodes[1].style = ""
            }
            if (node.children.length) {
                Array.from(node.children).forEach(walkAndFix);
            }
        }
    };

    const observer = new MutationObserver(mutations => {
        for (const mutation of mutations) {
            mutation.addedNodes.forEach(walkAndFix);
        }
    });

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

    // Initial run on current elements
    document.querySelectorAll('*').forEach(correctColor);
    applyBackground();
})();