gaz_lloyd

Untitled

Aug 14th, 2016
158
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.1
  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, $, window) {
  28.  
  29.  
  30.     //if (mw.config.get('skin') !== 'oasis' || mw.config.get('wgNamespaceNumber')) return;
  31.  
  32.     var css, stylesheet, button, defer, origwordmark, newwordmark, newcss;
  33.     origwordmark = $('#WikiHeader .wordmark a img').attr('src'); //so that reverting works correctly
  34.  
  35.     newwordmark = 'http://vignette4.wikia.nocookie.net/iiiiiii/images/8/89/Wiki-wordmark.png/revision/latest';
  36.     newcss = 'http://runescape.wikia.com/wiki/User:Iiii_I_I_I/darkmode.css?action=raw&ctype=text/css&maxage=3600&smaxage=3600';
  37.  
  38.     function addStylesheet () {
  39.         stylesheet =
  40.             $('<style type="text/css" id="alt-stylesheet">' + css + '">')
  41.             .appendTo(window.document.head || 'head');
  42.         $('#WikiHeader .wordmark a img').attr('src', newwordmark);
  43.         $.storage.set('altStylesheet', '1');
  44.     }
  45.  
  46.     function loadStylesheet () {
  47.         if (!css) {
  48.             if (defer && defer.state() === 'pending') return;
  49.             if (button && button.length) {
  50.                 button.prop('disabled', true);
  51.             }
  52.             defer = $.ajax({
  53.                 url: newcss,
  54.                 dataType: 'text',
  55.                 async: false,
  56.                 cache: true
  57.             })
  58.                 .done(function (text) {
  59.                 css = text;
  60.                 addStylesheet();
  61.                 if (button && button.length) {
  62.                     button.prop('disabled', false);
  63.                 }
  64.             });
  65.         } else {
  66.             addStylesheet();
  67.         }
  68.     }
  69.  
  70.     if ($.storage.get('altStylesheet')) {
  71.         loadStylesheet();
  72.     }
  73.  
  74.     $(function () {
  75.         button =
  76.  
  77.             // this is the button:
  78.             $('<input type="button" value="Change theme" class="wikia-button color-changer">')
  79.             .insertAfter('a.wikia-button.secondary.talk')
  80.             .attr('title', 'Toggle dark theme')
  81.         //.prependTo('.grid-4')
  82.         //('.WikiaMainContent')
  83.  
  84.             .click(function () {
  85.             var stylesheet = $('#alt-stylesheet');
  86.             if (stylesheet.length) {
  87.                 stylesheet.remove();
  88.                 $('#WikiHeader .wordmark a img').attr('src', origwordmark);
  89.                 $.storage.del('altStylesheet');
  90.             } else {
  91.                 loadStylesheet();
  92.             }
  93.             // this BS code forces stupid browsers to repaint:
  94.             var div = $('<div>').appendTo(window.document.body);
  95.             window.setTimeout(function(){ div.remove(); }, 0);
  96.         });
  97.  
  98.         if (defer && defer.state() === 'pending') {
  99.             button.prop('disabled', true);
  100.         }
  101.     });
  102.  
  103. }(window.mediaWiki, window.jQuery, window));
Advertisement
Add Comment
Please, Sign In to add comment