Vector Layout for Wikipedia (Fast)

returns old wikipedia layout. (layout before 2023 redesign of website)

Mint 2023.02.16.. Lásd a legutóbbi verzió

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name Vector Layout for Wikipedia (Fast)
// @namespace -
// @version 1.1.6
// @description returns old wikipedia layout. (layout before 2023 redesign of website)
// @author NotYou
// @match *://wikipedia.org/*
// @match *://*.wikipedia.org/*
// @run-at document-start
// @license GPL-3.0-or-later
// @grant none
// ==/UserScript==

(function() {
    'use strict';

    const MAKE_CLEAN_URL = false; // removes "useskin=vector" after loading

    const IS_DEBUG_MODE = false; // instead of redirecting, logs information in console

    const DEBUG_TITLE = 'DEBUG - Vector Layout for Wikipedia\n';

    let href = location.href;

    redirect(href, true);

    window.addEventListener('click', onClick);

    if(MAKE_CLEAN_URL) {
        let url = new URL(href);
        let searchParams = new URLSearchParams(url.search);

        if(searchParams.get('useskin') === 'vector') {
            searchParams.delete('useskin');

            let _searchParams = searchParams.toString();

            let newPath = url.pathname + (_searchParams ? '?' + _searchParams : _searchParams);

            history.replaceState({}, '', newPath);
        }
    }

    function redirect(inputUrl, replaceHistory) {
        let url;

        try {
            url = new URL(inputUrl)
        } catch(e) {
            throw new Error('"' + inputUrl + '" is not valid URL!')
        }

        let searchParams = new URLSearchParams(url.search);
        let pathname = url.pathname;
        let cleanURL = url.origin + pathname;

        if(searchParams.get('useskin') !== 'vector' && url.pathname !== '/') {
            searchParams.set('useskin', 'vector');

            let params = '?' + searchParams.toString();

            let resultURL = cleanURL + params;
            let newPath = pathname + params;

            if(IS_DEBUG_MODE) {
                console.log(DEBUG_TITLE, resultURL, newPath);
            } else {
                history[replaceHistory ? 'replaceState' : 'pushState']({}, '', newPath);
                replaceURL(resultURL);
            }
        }
    }

    function onClick(e) {
        let node = e.target;
        let link = getLink(node);

        if(link) {
            let url = new URL(link.href);
            let isOrigin = url.hostname.indexOf('wikipedia.org') > -1;
            let isNotAnchor = !link.getAttribute('href').startsWith('#');
            let isOnlyLink = !link.getAttribute('role');

            let isValid = isOrigin && isNotAnchor && isOnlyLink;

            if(isValid) {
                e.preventDefault();

                redirect(url, false);
            }
        }
    }

    function replaceURL(url) {
        if(location.replace) {
            location.replace(url);
        } else {
            location.href = url;
        }
    }

    function getLink(node) {
        if(node.tagName === 'A') {
            return node;
        } else if(node.tagName === 'HTML' || !node.tagName) {
            return null;
        }

        return getLink(node.parentNode);
    }
})();