MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
Import-sysop (talk | contribs) (transformed) |
WikiDevops (talk | contribs) No edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
loadScript('/MediaWiki:Scripting.js?action=raw&ctype=text/javascript'); | loadScript('/MediaWiki:Scripting.js?action=raw&ctype=text/javascript'); | ||
function | function makeBlock(el) { | ||
el.style.display = 'block'; | |||
} | |||
function makeInline(el) { | |||
el.style.display = 'inline'; | el.style.display = 'inline'; | ||
} | } | ||
// show edit items when a user is logged in | |||
// show edit items when a user is logged in | // show edit items when a user is logged in | ||
if (window.mw.config.values.wgUserId) { | if (window.mw.config.values.wgUserId) { | ||
Array.from(document.getElementsByClassName('controls-loggedin')).forEach( | Array.from(document.getElementsByClassName('controls-loggedin')).forEach(makeBlock); | ||
Array.from(document.getElementsByClassName('controls-loggedin-inline')).forEach(makeInline); | |||
} | } | ||
// make sunwater logo area clickable | // make sunwater logo area clickable | ||
document.querySelector('#p-tb').addEventListener('click', function (e) { | document.querySelector('#p-tb').addEventListener('click', function(e) { | ||
function isInPath( | function isInPath(target) { | ||
while (target) { | |||
if (target.nodeName === 'A') return true; | |||
target = target.parentNode; | |||
} | |||
return false; | |||
} | } | ||
const isMenuItem = isInPath(e.target); | |||
const isMenuItem = isInPath(e. | |||
if (!isMenuItem) { | if (!isMenuItem) { | ||
document.location = 'https://sunwater.org'; | document.location = 'https://sunwater.org'; |
Latest revision as of 21:33, 20 August 2023
loadScript('/MediaWiki:Scripting.js?action=raw&ctype=text/javascript');
function makeBlock(el) {
el.style.display = 'block';
}
function makeInline(el) {
el.style.display = 'inline';
}
// show edit items when a user is logged in
// show edit items when a user is logged in
if (window.mw.config.values.wgUserId) {
Array.from(document.getElementsByClassName('controls-loggedin')).forEach(makeBlock);
Array.from(document.getElementsByClassName('controls-loggedin-inline')).forEach(makeInline);
}
// make sunwater logo area clickable
document.querySelector('#p-tb').addEventListener('click', function(e) {
function isInPath(target) {
while (target) {
if (target.nodeName === 'A') return true;
target = target.parentNode;
}
return false;
}
const isMenuItem = isInPath(e.target);
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);
}