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 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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));
}