Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsrli authored Feb 4, 2019
1 parent eb8772f commit 9ba0316
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Wikipedia Dark Mode.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name Wikipedia Dark Mode
// @namespace https://github.com/MaxsLi/WikiDarkMode/
// @version 0.4
// @version 0.5
// @icon https://www.wikipedia.org/favicon.ico
// @description Pure Dark theme for wikipedia.org
// @author Shangru Li
Expand All @@ -13,20 +13,23 @@
'use strict';
// General idea is to put all elements on a wikipedia page to an array `allElements`
// traverse through this array and change the color of each element accordingly
// Hyper-link set to white: rgb(255, 255, 255)
// Normal text set to grey: rgb(155, 155, 155)
// Background set to black: rgb(35, 35, 35)
// images left untouched
// running time o(n), n is number of elements on a page
// Hyperlink set to white: rgb(255, 255, 255)
// Normal text set to grey: rgb(155, 155, 155)
// Background color set to black: rgb(35, 35, 35)
// Images background set to white: rgb(255, 255, 255)
// running time o(n), where n is the number of elements on a page
var allElements = document.getElementsByTagName("*");
for(var i=0; i<allElements.length; i++) {
// Check for images
if (allElements[i].nodeName.toLowerCase() === 'img'){
// Set images background color to white for better visibility
allElements[i].style.background = "rgb(255, 255, 255)";
// Leave forground color untouched
continue;
}
// Check for URLs
// Check for hyperlinks
if(new RegExp("([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?").test(allElements[i])) {
// Set all URL to white
// Set all hyperlinks to white
allElements[i].style.color = "rgb(255, 255, 255)";
} else {
// Exception handler
Expand All @@ -41,7 +44,7 @@
var backgroundColor = allElements[i].style.background.match(/rgba?\((\d{1,3}), ?(\d{1,3}), ?(\d{1,3})\)?(?:, ?(\d(?:\.\d?))\))?/);
// check for null
if (backgroundColor==null) {
allElements[i].style.background = "rgb(35, 35, 35)";
//allElements[i].style.background = "rgb(35, 35, 35)";
} else {
// Set new backgroundColor value
var r = parseInt(backgroundColor[1]) - 200;
Expand Down

0 comments on commit 9ba0316

Please sign in to comment.