Difference between revisions of "MediaWiki:Vector.js"
Jump to navigation
Jump to search
(Created page with "→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 footerLinks = document.getElementById('footer-places'); var modeSwitch = document.createElement('li'); modeSwitch.setAttribute('id', 'footer-places-skin-mode'); modeSwitch.setAttribute('onclick', 'switchSkin()'); function switchSkinShared(...") |
|||
Line 7: | Line 7: | ||
var footerLinks = document.getElementById('footer-places'); | var footerLinks = document.getElementById('footer-places'); | ||
var modeSwitch = document.createElement(' | var modeSwitchBase = document.CreateElement('li') | ||
var modeSwitch = document.createElement('a'); | |||
modeSwitchBase.setAttribute('id', 'footer-places-skin-mode'); | |||
modeSwitch.setAttribute('onclick', 'switchSkin()'); | modeSwitch.setAttribute('onclick', 'switchSkin()'); | ||
Line 30: | Line 31: | ||
wikiStorage.setItem('darkMode', 0 ); | wikiStorage.setItem('darkMode', 0 ); | ||
} | } | ||
wikiStorage.getItem('darkMode'); | darkMode = wikiStorage.getItem('darkMode'); | ||
switchSkinShared(); | switchSkinShared(); | ||
} | } | ||
switchSkinShared(); | switchSkinShared(); | ||
footerLinks.appendChild( | modeSwitchBase.appendChild(modeSwitch) | ||
footerLinks.appendChild(modeSwitchBase); |
Revision as of 16:54, 18 February 2022
/* 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 footerLinks = document.getElementById('footer-places');
var modeSwitchBase = document.CreateElement('li')
var modeSwitch = document.createElement('a');
modeSwitchBase.setAttribute('id', 'footer-places-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)
footerLinks.appendChild(modeSwitchBase);