python docs 简中切换

python docs zh-cn切换

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @namespace    zhcn-link-of-pydocs.deuterium.wiki
// @name         python docs 简中切换
// @version      0.1.1
// @author       Deuterium.wiki
// @match        https://docs.python.org/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=python.org
// @grant        none
// @license BSD
// @description:zh-cn python docs 简体中文切换
// @description  python docs zh-cn切换
// ==/UserScript==

(function () {
    'use strict';
    console.log('running pydocs zh-cn link')
    const match = /https?:\/\/docs\.python\.org\/([a-z\-]+\/)?3\.?\d*\/library.+/
    let url = window.location.href
    const matchResult = url.match(match);
    if (!matchResult) return
    if (matchResult[1]==='zh-cn/')return;

    if (matchResult[1]) {
        url = url.replace(matchResult[1], 'zh-cn/') }
    else{
        url = url.replace('.org/', '.org/zh-cn/')
    }

    const button = document.createElement('button');
    button.textContent = '跳转到中文';
    button.id = 'fixedButton';
    button.style.position = 'fixed';
    button.style.top = '20px';
    button.style.right = '20px';
    button.style.padding = '10px 20px';
    button.style.fontSize = '16px';
    button.style.backgroundColor = '#4CAF50';
    button.style.color = 'white';
    button.style.border = 'none';
    button.style.borderRadius = '5px';
    button.style.cursor = 'pointer';
    button.style.zIndex = '1000';
    button.onclick = () => {window.location.href=url};
    document.body.appendChild(button);
})();