Skip to content

Commit

Permalink
Updated to version 0.81
Browse files Browse the repository at this point in the history
Minor improvement on background display
  • Loading branch information
maxsrli committed Apr 10, 2019
1 parent 9407eec commit abad0a1
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Wikipedia Dark Theme.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name Wikipedia Dark Theme
// @namespace https://github.com/MaxsLi/WikipediaDarkTheme
// @version 0.80
// @version 0.81
// @icon https://www.wikipedia.org/favicon.ico
// @description Pure Dark theme for Wikipedia pages
// @author Shangru Li
Expand Down Expand Up @@ -33,13 +33,13 @@
setPageVisibility("visible")
}

// function to set the visbility of a html page
function setPageVisibility(visbility) {
// function to set the visibility of a html page
function setPageVisibility(visibility) {
// get the entire html page
var EntirePage = document.getElementsByTagName('html')[0];
// set the page's background color to `default_backgroundColor`
EntirePage.style.backgroundColor = default_backgroundColor;
EntirePage.style.visibility = visbility;
EntirePage.style.visibility = visibility;
}

// function to change the all the elements on a page to desired color
Expand Down Expand Up @@ -73,7 +73,7 @@
// get the foreground color of the `currentElement`, using `getComputedStyle` will return the actual showing
// color of the given element in `rgb` format. However, this method seems to need the document first be loaded
// after returning the computed style. Hence, to get around, we hide the entire page while waiting the document
// to load, then unhide after finished.
// to load, then un-hide after finished.
var foregroundColor = window.getComputedStyle(currentElement, null).getPropertyValue("color");
var backgroundColor = window.getComputedStyle(currentElement, null).getPropertyValue("background-color");
// temporary helper variables
Expand Down Expand Up @@ -119,6 +119,12 @@
g = g + 30;
b = b + 30;
}
// if the background is too bright, we decrease the brightness of `backgroundColor`
while (contrast([r, g, b], [default_backgroundColor_array[1], default_backgroundColor_array[2], default_backgroundColor_array[3]]) > default_contrastValue/7) {
r = r - 30;
g = g - 30;
b = b - 30;
}
// set color
currentElement.style.backgroundColor = 'rgb(' + r + ', ' + g + ', ' + b + ')';
} else{
Expand All @@ -127,12 +133,12 @@
}
} catch (e){
// print any exception messages
console.log(e)
console.log(e);
}
}
}

// function to calculate the luminace of given `r`, `g`, `b` value
// function to calculate the luminance of given `r`, `g`, `b` value
function luminance(r, g, b) {
var a = [r, g, b].map(function (v) {
v /= 255;
Expand Down

0 comments on commit abad0a1

Please sign in to comment.