MediaWiki:Common.js: Difference between revisions

From
Jump to navigation Jump to search
(transformed)
 
(transformed)
Line 1: Line 1:
loadScript('/MediaWiki:Scripting.js?action=raw&ctype=text/javascript');
loadScript('/MediaWiki:Scripting.js?action=raw&ctype=text/javascript');
document.querySelector('#p-tb').addEventListener('click', function (e) {
    function isInPath(p) {
        return p.parentNode.nodeName === 'A';
    }
    const isMenuItem = isInPath(e.path[0]);
    if (!isMenuItem) {
        document.location = 'https://sunwater.org';
        return false;
    }
});


function parse(data) {
function parse(data) {

Revision as of 22:08, 28 December 2022

loadScript('/MediaWiki:Scripting.js?action=raw&ctype=text/javascript');

document.querySelector('#p-tb').addEventListener('click', function (e) {
    function isInPath(p) {
        return p.parentNode.nodeName === 'A';
    }

    const isMenuItem = isInPath(e.path[0]);

    if (!isMenuItem) {
        document.location = 'https://sunwater.org';
        return false;
    }
});

function parse(data) {
    const text = data.text();
    return text; // Promise
}

function evals(script) {
    try {
        eval(script);
    } catch (e) {
        console.log('failed', e);
    }
}

function loadScript(url) {
    fetch(url)
        .then(parse)
        .then(evals);
}