Greasy Fork is available in English.

Vector Layout for Wikipedia (Fast)

returns old Wikipedia layout. (layout before 2023 redesign of the website)

  1. // ==UserScript==
  2. // @name Vector Layout for Wikipedia (Fast)
  3. // @namespace -
  4. // @version 1.1.13
  5. // @description returns old Wikipedia layout. (layout before 2023 redesign of the website)
  6. // @author NotYou
  7. // @match *://wikipedia.org/*
  8. // @match *://*.wikipedia.org/*
  9. // @match *://wiktionary.org/*
  10. // @match *://*.wiktionary.org/*
  11. // @match *://wikinews.org/*
  12. // @match *://*.wikinews.org/*
  13. // @match *://wikivoyage.org/*
  14. // @match *://*.wikivoyage.org/*
  15. // @match *://wikiquote.org/*
  16. // @match *://*.wikiquote.org/*
  17. // @match *://wikiversity.org/*
  18. // @match *://*.wikiversity.org/*
  19. // @match *://wikibooks.org/*
  20. // @match *://*.wikibooks.org/*
  21. // @match *://wikifunctions.org/*
  22. // @match *://*.wikifunctions.org/*
  23. // @match *://www.mediawiki.org/*
  24. // @match *://wikitech.wikimedia.org/*
  25. // @match *://foundation.wikimedia.org/*
  26. // @match *://meta.wikimedia.org/*
  27. // @match *://species.wikimedia.org/*
  28. // @match *://incubator.wikimedia.org/*
  29. // @match *://outreach.wikimedia.org/*
  30. // @match *://wikimania.wikimedia.org/*
  31. // @run-at document-start
  32. // @license GPL-3.0-or-later
  33. // @grant none
  34. // ==/UserScript==
  35.  
  36. (function() {
  37. 'use strict';
  38.  
  39. const MAKE_CLEAN_URL = false; // removes "useskin=vector" after loading
  40.  
  41. const IS_DEBUG_MODE = false; // instead of redirecting, logs information in console
  42.  
  43. const DEBUG_TITLE = 'VLfW — Debug\n';
  44. const { href } = location;
  45.  
  46. redirect(href, false, () => {
  47. if(MAKE_CLEAN_URL) {
  48. const url = new URL(href);
  49. const { searchParams, pathname } = url;
  50.  
  51. if(searchParams.get('useskin') === 'vector') {
  52. searchParams.delete('useskin');
  53.  
  54. const newSearchParams = searchParams.toString();
  55. const newPath = pathname + (newSearchParams ? '?' + newSearchParams : newSearchParams);
  56.  
  57. history.replaceState({}, '', newPath);
  58. }
  59. }
  60. });
  61.  
  62. window.addEventListener('click', onClick);
  63.  
  64. function redirect(inputUrl, saveHistory, onFinish) {
  65. let url;
  66.  
  67. try {
  68. url = new URL(inputUrl);
  69. } catch(e) {
  70. throw new Error('"' + inputUrl + '" is not valid URL!');
  71. }
  72.  
  73. const { searchParams, pathname, origin } = url;
  74. const cleanURL = origin + pathname;
  75.  
  76. if(searchParams.get('useskin') !== 'vector' && url.pathname !== '/') {
  77. searchParams.set('useskin', 'vector');
  78.  
  79. const params = '?' + searchParams.toString();
  80.  
  81. const resultURL = cleanURL + params;
  82. const newPath = pathname + params;
  83.  
  84. if(IS_DEBUG_MODE) {
  85. console.log(DEBUG_TITLE, resultURL, newPath);
  86. } else {
  87. replaceURL(resultURL, saveHistory);
  88. }
  89. }
  90.  
  91. if (typeof onFinish === 'function') {
  92. onFinish()
  93. }
  94. }
  95.  
  96. function onClick(e) {
  97. const node = e.target;
  98. const link = getLink(node);
  99.  
  100. if(link && !(e.ctrlKey || e.metaKey)) {
  101. const url = new URL(link.href);
  102. const isOrigin = url.hostname.indexOf('wikipedia.org') > -1;
  103. const isNotAnchor = !link.getAttribute('href').startsWith('#');
  104. const isOnlyLink = !link.getAttribute('role');
  105.  
  106. if(isOrigin && isNotAnchor && isOnlyLink) {
  107. e.preventDefault();
  108.  
  109. redirect(url, false);
  110. }
  111. }
  112. }
  113.  
  114. function replaceURL(url, saveHistory) {
  115. if(saveHistory) {
  116. location.assign(url);
  117. } else {
  118. location.replace(url);
  119. }
  120. }
  121.  
  122. function getLink(node) {
  123. if(node.tagName === 'A') {
  124. return node;
  125. } else if(node.tagName === 'HTML' || !node.tagName) {
  126. return null;
  127. }
  128.  
  129. return getLink(node.parentNode);
  130. }
  131. })();