Advertisement
gaz_lloyd

Untitled

Aug 14th, 2016
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         temporary RSW darkmode enabler
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.2
  5. // @description  try to take over the world!
  6. // @author       gaz lloyd
  7. // @match        http://runescape.wikia.com/*
  8. // @match        https://runescape.wikia.com/*
  9. // @match        http://rs.wikia.com/*
  10. // @match        https://rs.wikia.com/*
  11. // @grant        none
  12. // ==/UserScript==
  13. /* jshint -W097 */
  14. 'use strict';
  15.  
  16. /* ==================
  17.    COLOUR CHANGER 1.0
  18.    ==================
  19.    borrowed from http://tardis.wikia.com/wiki/MediaWiki:Wikia.js
  20.  
  21.  
  22.    by [[user:Pecoes]]
  23.    see http://community.wikia.com/wiki/Thread:477388
  24.    for conceptual design discussion
  25.    ================== */
  26.  
  27. (function (mw, $, rswiki, window) {
  28.  
  29.     if (rswiki && rswiki.loaded) {
  30.         if (rswiki.loaded.indexOf('common.darkmode') > -1) {
  31.             window.alert("The darkmode script is live now! You should disable and remove this tampermonkey/greasemonky script. Thanks for testing!");
  32.         }
  33.     }
  34.     //if (mw.config.get('skin') !== 'oasis' || mw.config.get('wgNamespaceNumber')) return;
  35.  
  36.     var css, stylesheet, button, defer, origwordmark, newwordmark, newcss;
  37.     origwordmark = $('#WikiHeader .wordmark a img').attr('src'); //so that reverting works correctly
  38.  
  39.     newwordmark = 'http://vignette4.wikia.nocookie.net/iiiiiii/images/8/89/Wiki-wordmark.png/revision/latest';
  40.     newcss = 'http://runescape.wikia.com/wiki/User:Iiii_I_I_I/darkmode.css?action=raw&ctype=text/css&maxage=3600&smaxage=3600';
  41.  
  42.     function addStylesheet () {
  43.         stylesheet =
  44.             $('<style type="text/css" id="alt-stylesheet">' + css + '">')
  45.             .appendTo(window.document.head || 'head');
  46.         $('#WikiHeader .wordmark a img').attr('src', newwordmark);
  47.         $.storage.set('altStylesheet', '1');
  48.     }
  49.  
  50.     function loadStylesheet () {
  51.         if (!css) {
  52.             if (defer && defer.state() === 'pending') return;
  53.             if (button && button.length) {
  54.                 button.prop('disabled', true);
  55.             }
  56.             defer = $.ajax({
  57.                 url: newcss,
  58.                 dataType: 'text',
  59.                 async: false,
  60.                 cache: true
  61.             })
  62.                 .done(function (text) {
  63.                 css = text;
  64.                 addStylesheet();
  65.                 if (button && button.length) {
  66.                     button.prop('disabled', false);
  67.                 }
  68.             });
  69.         } else {
  70.             addStylesheet();
  71.         }
  72.     }
  73.  
  74.     if ($.storage.get('altStylesheet')) {
  75.         loadStylesheet();
  76.     }
  77.  
  78.     $(function () {
  79.         button =
  80.  
  81.             // this is the button:
  82.             $('<input type="button" value="Change theme" class="wikia-button color-changer">')
  83.             .insertAfter('a.wikia-button.secondary.talk')
  84.             .attr('title', 'Toggle dark theme')
  85.         //.prependTo('.grid-4')
  86.         //('.WikiaMainContent')
  87.  
  88.             .click(function () {
  89.             var stylesheet = $('#alt-stylesheet');
  90.             if (stylesheet.length) {
  91.                 stylesheet.remove();
  92.                 $('#WikiHeader .wordmark a img').attr('src', origwordmark);
  93.                 $.storage.del('altStylesheet');
  94.             } else {
  95.                 loadStylesheet();
  96.             }
  97.             // this BS code forces stupid browsers to repaint:
  98.             var div = $('<div>').appendTo(window.document.body);
  99.             window.setTimeout(function(){ div.remove(); }, 0);
  100.         });
  101.  
  102.         if (defer && defer.state() === 'pending') {
  103.             button.prop('disabled', true);
  104.         }
  105.     });
  106.  
  107. }(window.mediaWiki, window.jQuery, window.rswiki, window));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement