Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name temporary RSW darkmode enabler
- // @namespace http://tampermonkey.net/
- // @version 0.2
- // @description try to take over the world!
- // @author gaz lloyd
- // @match http://runescape.wikia.com/*
- // @match https://runescape.wikia.com/*
- // @match http://rs.wikia.com/*
- // @match https://rs.wikia.com/*
- // @grant none
- // ==/UserScript==
- /* jshint -W097 */
- 'use strict';
- /* ==================
- COLOUR CHANGER 1.0
- ==================
- borrowed from http://tardis.wikia.com/wiki/MediaWiki:Wikia.js
- by [[user:Pecoes]]
- see http://community.wikia.com/wiki/Thread:477388
- for conceptual design discussion
- ================== */
- (function (mw, $, rswiki, window) {
- if (rswiki && rswiki.loaded) {
- if (rswiki.loaded.indexOf('common.darkmode') > -1) {
- window.alert("The darkmode script is live now! You should disable and remove this tampermonkey/greasemonky script. Thanks for testing!");
- }
- }
- //if (mw.config.get('skin') !== 'oasis' || mw.config.get('wgNamespaceNumber')) return;
- var css, stylesheet, button, defer, origwordmark, newwordmark, newcss;
- origwordmark = $('#WikiHeader .wordmark a img').attr('src'); //so that reverting works correctly
- newwordmark = 'http://vignette4.wikia.nocookie.net/iiiiiii/images/8/89/Wiki-wordmark.png/revision/latest';
- newcss = 'http://runescape.wikia.com/wiki/User:Iiii_I_I_I/darkmode.css?action=raw&ctype=text/css&maxage=3600&smaxage=3600';
- function addStylesheet () {
- stylesheet =
- $('<style type="text/css" id="alt-stylesheet">' + css + '">')
- .appendTo(window.document.head || 'head');
- $('#WikiHeader .wordmark a img').attr('src', newwordmark);
- $.storage.set('altStylesheet', '1');
- }
- function loadStylesheet () {
- if (!css) {
- if (defer && defer.state() === 'pending') return;
- if (button && button.length) {
- button.prop('disabled', true);
- }
- defer = $.ajax({
- url: newcss,
- dataType: 'text',
- async: false,
- cache: true
- })
- .done(function (text) {
- css = text;
- addStylesheet();
- if (button && button.length) {
- button.prop('disabled', false);
- }
- });
- } else {
- addStylesheet();
- }
- }
- if ($.storage.get('altStylesheet')) {
- loadStylesheet();
- }
- $(function () {
- button =
- // this is the button:
- $('<input type="button" value="Change theme" class="wikia-button color-changer">')
- .insertAfter('a.wikia-button.secondary.talk')
- .attr('title', 'Toggle dark theme')
- //.prependTo('.grid-4')
- //('.WikiaMainContent')
- .click(function () {
- var stylesheet = $('#alt-stylesheet');
- if (stylesheet.length) {
- stylesheet.remove();
- $('#WikiHeader .wordmark a img').attr('src', origwordmark);
- $.storage.del('altStylesheet');
- } else {
- loadStylesheet();
- }
- // this BS code forces stupid browsers to repaint:
- var div = $('<div>').appendTo(window.document.body);
- window.setTimeout(function(){ div.remove(); }, 0);
- });
- if (defer && defer.state() === 'pending') {
- button.prop('disabled', true);
- }
- });
- }(window.mediaWiki, window.jQuery, window.rswiki, window));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement