MediaWiki:Common.js: Difference between revisions

From COMP15212 Wiki
m 1 revision imported
Add a grey background to all images if the user uses a dark-mode extension.
 
(2 intermediate revisions by 2 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";});
}