Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.9 kB
1
Indexable
Never
(function() {
    try {
        /* main variables */
        var debug = 0;
        var variation_name = "";
        var $;
        /* all Pure helper functions */

        function waitForElement(selector, trigger, delayInterval, delayTimeout) {
            var interval = setInterval(function() {
                if (
                    document &&
                    document.querySelector(selector) &&
                    document.querySelectorAll(selector).length > 0
                ) {
                    clearInterval(interval);
                    trigger();
                }
            }, delayInterval);
            setTimeout(function() {
                clearInterval(interval);
            }, delayTimeout);
        }


        /* Variation Init */
        function init() {
            let egURL = document.querySelector("#__next > .datasheet .header > div > ul > li:last-child a").href;
            getTable(egURL);
        }

        async function getTable(url) {
            let response = await fetch(url);
            let data = await response.text();
            let ele = document.createElement("div");
            ele.innerHTML = data;
            let egTable = ele.querySelector("#__next .page-container > div:nth-child(2)");
            if (!document.querySelector(".eg-table")) {
                egTable.classList.add("eg-table");
                document.querySelector(".footer").insertAdjacentHTML("beforebegin", `<div class="eg-table-container"><div class="eg-wrapper"></div></div>`);
                document.querySelector(".eg-table-container > .eg-wrapper").insertAdjacentElement("afterbegin", egTable);
            }
        }

        /* Initialize variation */
        waitForElement('#__next > .datasheet .header > div > ul > li:last-child a', init, 50, 15000);
    } catch (e) {
        if (debug) console.log(e, "error in Test" + variation_name);
    }
})();