🏠 Home 

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. (function() {
  36. 'use strict';
  37. const MAKE_CLEAN_URL = false; // removes "useskin=vector" after loading
  38. const IS_DEBUG_MODE = false; // instead of redirecting, logs information in console
  39. const DEBUG_TITLE = 'VLfW — Debug\n';
  40. const { href } = location;
  41. redirect(href, false, () => {
  42. if(MAKE_CLEAN_URL) {
  43. const url = new URL(href);
  44. const { searchParams, pathname } = url;
  45. if(searchParams.get('useskin') === 'vector') {
  46. searchParams.delete('useskin');
  47. const newSearchParams = searchParams.toString();
  48. const newPath = pathname + (newSearchParams ? '?' + newSearchParams : newSearchParams);
  49. history.replaceState({}, '', newPath);
  50. }
  51. }
  52. });
  53. window.addEventListener('click', onClick);
  54. function redirect(inputUrl, saveHistory, onFinish) {
  55. let url;
  56. try {
  57. url = new URL(inputUrl);
  58. } catch(e) {
  59. throw new Error('"' + inputUrl + '" is not valid URL!');
  60. }
  61. const { searchParams, pathname, origin } = url;
  62. const cleanURL = origin + pathname;
  63. if(searchParams.get('useskin') !== 'vector' && url.pathname !== '/') {
  64. searchParams.set('useskin', 'vector');
  65. const params = '?' + searchParams.toString();
  66. const r###ltURL = cleanURL + params;
  67. const newPath = pathname + params;
  68. if(IS_DEBUG_MODE) {
  69. console.log(DEBUG_TITLE, r###ltURL, newPath);
  70. } else {
  71. replaceURL(r###ltURL, saveHistory);
  72. }
  73. }
  74. if (typeof onFinish === 'function') {
  75. onFinish()
  76. }
  77. }
  78. function onClick(e) {
  79. const node = e.target;
  80. const link = getLink(node);
  81. if(link && !(e.ctrlKey || e.metaKey)) {
  82. const url = new URL(link.href);
  83. const isOrigin = url.hostname.indexOf('wikipedia.org') > -1;
  84. const isNotAnchor = !link.getAttribute('href').startsWith('#');
  85. const isOnlyLink = !link.getAttribute('role');
  86. if(isOrigin && isNotAnchor && isOnlyLink) {
  87. e.preventDefault();
  88. redirect(url, false);
  89. }
  90. }
  91. }
  92. function replaceURL(url, saveHistory) {
  93. if(saveHistory) {
  94. location.assign(url);
  95. } else {
  96. location.replace(url);
  97. }
  98. }
  99. function getLink(node) {
  100. if(node.tagName === 'A') {
  101. return node;
  102. } else if(node.tagName === 'HTML' || !node.tagName) {
  103. return null;
  104. }
  105. return getLink(node.parentNode);
  106. }
  107. })();