Skip to content

Instantly share code, notes, and snippets.

@emerson-pereira
Last active February 7, 2018 18:52
Show Gist options
  • Save emerson-pereira/5a032db8e39b8615975f962ae976d78d to your computer and use it in GitHub Desktop.
Save emerson-pereira/5a032db8e39b8615975f962ae976d78d to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Wikipedia
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://en.wikipedia.org/*
// @match https://pt.wikipedia.org/*
// @grant none
// @import https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
// ==/UserScript==
function init() {
var namesLists = [
{
type: 'tag',
names: [
'html',
'pre'
]
},
{
type: 'class',
names: [
'thumbcaption'
]
},
{
type: 'id',
names: [
'mw-panel',
'mw-head',
'content',
'bodyContent',
'firstHeading',
'footer',
'catlinks'
]
}
],
elms = []
;
namesLists.map(function(list, i) {
list.names.map(function(name) {
switch (list.type) {
case 'tag':
var elmsList = document.getElementsByTagName(name);
for (var i = 0; i < elmsList.length; i++) {
elmsList[i].classList.add('dark-bg');
}
break;
case 'class':
var elmsList = document.getElementsByClassName(name);
for (var i = 0; i < elmsList.length; i++) {
elmsList[i].classList.add('dark-bg');
}
break;
case 'id':
document.getElementById(name).classList.add('dark-bg');
break;
}
});
});
var sheet = (function() {
var style = document.createElement('style');
// WebKit hack :(
style.appendChild(document.createTextNode(''));
document.head.appendChild(style);
return style.sheet;
})();
sheet.addRule('.dark-bg', 'background-color: #999; color: #f2f2f2;', 0);
sheet.addRule('a', 'color: #ffffcc', 0);
sheet.addRule('p, span, h1, h2, h3, h4, h5, h6', 'color: #f2f2f2; -webkit-font-smoothing: antialiased;', 0);
sheet.addRule('#toc', 'background-color: gray;', 0);
sheet.addRule('.mw-wiki-logo', 'background-image: url(//upload.wikimedia.org/wikipedia/en/thumb/8/80/Wikipedia-logo-v2.svg/1200px-Wikipedia-logo-v2.svg.png); background-size: contain; width: 7em;', 0);
sheet.addRule('div#mw-panel', 'width: 11em;', 0);
sheet.addRule('li span', 'background-image: none; background-color: gray;', 0);
sheet.addRule('table.plainlinks', 'display: none;', 0);
var anchorList = document.getElementsByTagName('a');
for (var i = 0; i < anchorList.length; i++) {
anchorList[i].setAttribute('target', '_blank');
}
}
init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment