MediaWiki:Vector.js

From Foundation - Wiki
Revision as of 16:39, 18 February 2022 by Sakaratte (talk | contribs) (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(...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* 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() {
	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 );
	}
	wikiStorage.getItem('darkMode');
	switchSkinShared();
}

switchSkinShared();
footerLinks.appendChild(modeSwitch);