Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2023
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Old Wikipedia Layout
  3. // @namespace    http://greasyfork.org/
  4. // @version      0.2
  5. // @description  Redirects Wikipedia to use the good (pre-2023) skin.
  6. // @author       Sheer Anger
  7. // @match        *://*.wikipedia.org/*
  8. // @icon         https://www.google.com/s2/favicons?domain=www.wikipedia.org
  9. // @grant        none
  10. // @license      MIT
  11. // ==/UserScript==
  12.  
  13. const skinchoice = 'vector';
  14.  
  15. function test(url){
  16.     return !!url.match(/(?!.*useskin)^(|http(s?):\/\/)(|www\.|\w{2,6}\.)(|m\.)wikipedia.org(\/.*|$)/gim) && url != `https://www.wikipedia.org/`;
  17. }
  18.  
  19. function getNewPage(url){
  20.     var que = '?';
  21.     if(url.includes("?")){que = '&'};
  22.     if(url.includes("#")) {
  23.       const s = url.split("#");
  24.       return s[0]+que+"useskin="+skinchoice+"#"+s[1];
  25.     }
  26.     return url.concat(que,"useskin=",skinchoice);
  27. }
  28.  
  29. function fixWikiLinks(){
  30.     var links = Array.prototype.slice.call(document.links, 0);
  31.     links.filter(function(link){
  32.         if(test(link.href)){
  33.             var greatNewLink = getNewPage(link.href);
  34.             if(link.hasAttribute('data-outbound-url')) link.setAttribute('data-outbound-url', greatNewLink);
  35.             link.setAttribute('href', greatNewLink);
  36.         }
  37.     });
  38. }
  39.  
  40. if(test(window.location.href)){window.location.assign(getNewPage(window.location.href));}
  41.  
  42. window.onload = fixWikiLinks;
  43. setInterval(fixWikiLinks, 50);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement