User:Tito151/common.js

var wikiThemes = { 'deadcells.fandom.com': 'hydradark' };

var pageUrl = new URL(window.location.href); if (pageUrl.host in wikiThemes) { // if theme GET parameter isn't set, set it and reload if (!pageUrl.searchParams.get('useskin')) { pageUrl.searchParams.set('useskin', wikiThemes[pageUrl.host]); window.location.href = pageUrl.href; }   // listen for clicks on document body var bodyObj = document.getElementsByTagName('body')[0]; bodyObj.addEventListener('click', function(event) {       // find the link        var anchor;        if (event.target.tagName === 'A') {            anchor = event.target;        } else if (event.target.parentNode.tagName === 'A') {            anchor = event.target.parentNode;        } else {            return; // clicked, not a link        }        var link = anchor.getAttribute('href');        if (link.includes(pageUrl.host)) {            // I don't want to handle this case lol, seems quite rare            // just return and lean on the first bit to apply theme            return;        }        // if link is internal, append theme GET parameter & navigate to destination        if (link.startsWith('/')) {            event.preventDefault;            var newUrl = new URL('https://' + pageUrl.host + link);            newUrl.searchParams.set('useskin', wikiThemes[pageUrl.host]);            window.location.href = newUrl.href; }   }); }