Old Wikipedia Layout Fixed

Redirects Wikipedia to use the good (pre-2023) skin. Fork of https://greasyfork.org/en/scripts/458494-old-wikipedia-layout with bugfixes.

2024-06-05 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Old Wikipedia Layout Fixed
// @namespace    http://greasyfork.org/
// @version      1.0.0
// @description  Redirects Wikipedia to use the good (pre-2023) skin. Fork of https://greasyfork.org/en/scripts/458494-old-wikipedia-layout with bugfixes.
// @author       Marp
// @match        *://*.wikipedia.org/*
// @icon         https://www.google.com/s2/favicons?domain=www.wikipedia.org
// @grant        none
// @license      MIT
// ==/UserScript==

//choose from: vector, monobook, timeless, minerva
const skinchoice = 'vector';

function test(url){
    return !!url.match(/(?!.*useskin)^(|http(s?):\/\/)(|www\.|\w{2,6}\.)(|m\.)wikipedia.org(\/.*|$)/gim);
}

function getNewPage(url) {
    const useskinParam = `useskin=${skinchoice}`;
    let newURL = url;

    if (url.includes('#')) {
        const [baseURL, section] = url.split('#');
        const separator = baseURL.includes('?') ? '&' : '?';
        newURL = `${baseURL}${separator}${useskinParam}#${section}`;
    } else if (!url.includes('useskin=')) {
        const separator = url.includes('?') ? '&' : '?';
        newURL = `${url}${separator}${useskinParam}`;
    }

    return newURL;
}

function fixWikiLinks(){
    var links = Array.prototype.slice.call(document.links, 0);
    links.filter(function(link){
        if(test(link.href)){
            var greatNewLink = getNewPage(link.href);

            if(typeof(link.onclick) == "undefined" || link.onclick == null){
                link.addEventListener("click", e => {
                    e.preventDefault();
                    window.location.assign(greatNewLink);
                });
            }

            if(typeof(link.mousedown) == "undefined" || link.mousedown == null){
                link.addEventListener("mousedown", e => {
                    if (e.button === 1) {
                        e.preventDefault();
                        window.open(greatNewLink, '_blank');
                    }
                });
           }
        }
    });
    console.log("zakonczono");
}

fixWikiLinks();
document.addEventListener("DOMContentLoaded", fixWikiLinks);

const currentURL = window.location.href;
const previousURL = localStorage.getItem('previousURL');

if (test(currentURL) && currentURL !== previousURL) {
    localStorage.setItem('previousURL', currentURL);
    window.location.assign(getNewPage(currentURL));
}