MediaWiki:Common.js: Difference between revisions
From COMP15212 Wiki
pc>Yuron (Test) |
W81054ch [PHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs) (Add a grey background to all images if the user uses a dark-mode extension.) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
var bodyColour = window.getComputedStyle(document.querySelector("body")) | |||
.getPropertyValue("background-color").match(/rgba?\((.*)\)/)[1].split(",").map(Number); | |||
var usingDarkTheme; | |||
if (bodyColour[3] === 0) { | |||
usingDarkTheme = false; | |||
} else { | |||
usingDarkTheme = bodyColour.reduce(function accum(a,b){return a+b;}) < 255 * 1.5; | |||
} | |||
if (usingDarkTheme) { | |||
document.querySelectorAll("img").forEach(function turnGrey(image) {image.style.backgroundColor = "grey";}); | |||
} |
Latest revision as of 10:06, 15 February 2020
/* Any JavaScript here will be loaded for all users on every page load. */
var bodyColour = window.getComputedStyle(document.querySelector("body"))
.getPropertyValue("background-color").match(/rgba?\((.*)\)/)[1].split(",").map(Number);
var usingDarkTheme;
if (bodyColour[3] === 0) {
usingDarkTheme = false;
} else {
usingDarkTheme = bodyColour.reduce(function accum(a,b){return a+b;}) < 255 * 1.5;
}
if (usingDarkTheme) {
document.querySelectorAll("img").forEach(function turnGrey(image) {image.style.backgroundColor = "grey";});
}