python docs 简中切换

python docs zh-cn切换

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==
// @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);
})();