Vector Layout for Wikipedia (Fast)

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

Stan na 03-12-2023. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name Vector Layout for Wikipedia (Fast)
// @namespace -
// @version 1.1.9
// @description returns old Wikipedia layout. (layout before 2023 redesign of the 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';

    const { href } = location;

    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!');
        }

        const searchParams = new URLSearchParams(url.search);
        const { pathname, origin, hash } = url;
        const cleanURL = origin + pathname;

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

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

            const resultURL = cleanURL + params + hash;
            const newPath = pathname + params;

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

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

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

            const 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);
    }
})();