Difference between revisions of "MediaWiki:Vector.js"
Jump to navigation
Jump to search
(One intermediate revision by one other user not shown) | |||
Line 6: | Line 6: | ||
} | } | ||
var | var toolLinksBase = document.getElementById('p-tb'); | ||
var toolLinks = toolLinksBase.getElementsByClassName('vector-menu-content-list'); | |||
var modeSwitchBase = document.createElement('li'); | var modeSwitchBase = document.createElement('li'); | ||
var modeSwitch = document.createElement(' | var modeSwitch = document.createElement('span'); | ||
modeSwitchBase.setAttribute('id', ' | modeSwitchBase.setAttribute('id', 'skin-mode'); | ||
modeSwitch.setAttribute('onclick', 'switchSkin()'); | modeSwitch.setAttribute('onclick', 'switchSkin()'); | ||
Line 37: | Line 38: | ||
switchSkinShared(); | switchSkinShared(); | ||
modeSwitchBase.appendChild(modeSwitch); | modeSwitchBase.appendChild(modeSwitch); | ||
toolLinks[0].appendChild(modeSwitchBase); |
Latest revision as of 12:19, 6 February 2024
/* All JavaScript here will be loaded for users of the Vector skin */
const wikiStorage = window.localStorage;
var darkMode = wikiStorage.getItem('darkMode');
if (darkMode == null) {
window.localStorage.setItem('darkMode', 0);
}
var toolLinksBase = document.getElementById('p-tb');
var toolLinks = toolLinksBase.getElementsByClassName('vector-menu-content-list');
var modeSwitchBase = document.createElement('li');
var modeSwitch = document.createElement('span');
modeSwitchBase.setAttribute('id', 'skin-mode');
modeSwitch.setAttribute('onclick', 'switchSkin()');
function switchSkinShared() {
if (darkMode == 1) {
bodyTag = document.getElementsByTagName('body');
bodyTag[0].classList.add('mw-dark-mode');
modeSwitch.innerHTML = 'Light Mode';
} else {
bodyTag = document.getElementsByTagName('body');
bodyTag[0].classList.remove('mw-dark-mode');
modeSwitch.innerHTML = 'Dark Mode';
}
}
function switchSkin() {
if (darkMode == 0) {
wikiStorage.setItem('darkMode', 1);
} else {
wikiStorage.setItem('darkMode', 0 );
}
darkMode = wikiStorage.getItem('darkMode');
switchSkinShared();
}
switchSkinShared();
modeSwitchBase.appendChild(modeSwitch);
toolLinks[0].appendChild(modeSwitchBase);