User:ShowierData9978/wikicrawl/index.js

Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
let url;
{
    //@ts-ignore     
    let pre = document.currentScript.getAttribute('src');
    let indexJsPosition = pre.indexOf("/index.js");
    url = indexJsPosition !== -1 ? pre.substring(0, indexJsPosition) : pre;
}

window.wh = window.wh || {}; window.wh.url = url;
window.wh.dev = url.includes("localhost");
if (localStorage.getItem("wk:list") === null)  {
    localStorage.setItem('wk:list', JSON.stringify({
        tree: {},
        root: [],
        lastUpdated: mw.now()
    }));
}
mw.loader.using('mediawiki.util', function () {
    $('<script> ', {
        src: `${url}/require.js`
    }).appendTo('head');
    $("<script>", {
        src: `${url}/module.js&action=raw&ctype=text/javascript`,
        // module
        type: "module",
    }).appendTo('body');
});