MDN Toc Bar 中英文快速切换和序号目录

MDN 网站中英文快速切换和新标签页打开对比,需要先安装Toc Bar脚本

当前为 2023-05-06 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         MDN Toc Bar 中英文快速切换和序号目录
// @description  MDN 网站中英文快速切换和新标签页打开对比,需要先安装Toc Bar脚本
// @namespace    http://tampermonkey.net/
// @version      0.34
// @description  try to take over the world!
// @author       You
// @match        *://developer.mozilla.org/*/docs/*
// @icon         https://developer.mozilla.org/favicon.ico
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    function change() {
        var tocbarheader = document.querySelector("#toc-bar > div.toc-bar__header > div.flex.toc-bar__header-left > div.toc-bar__title.hidden-when-collapsed")
            //document.querySelector("#toc-bar > div.toc-bar__header > div.flex.toc-bar__header-left");
        var url = window.location.href.includes('en-US') ? window.location.href.replace('en-US', 'zh-CN') : window.location.href.replace('zh-CN', 'en-US');
        tocbarheader.innerHTML = tocbarheader.innerHTML + '    <a href="' + url + '"  style="padding-left:10px">中英文转换</a><a href="' + url + '"  target="_blank">/新页</a>';
        var tocbarbody = document.querySelector("#toc-bar > div.toc-bar__toc");
        var s = document.styleSheets[document.styleSheets.length - 1];
        s.insertRule('#toc-bar {z-index: 2147483647;}');
        s.insertRule('.toc-bar__toc > .toc-list {padding-left: 18px!important;}');
        s.insertRule('.toc-bar__toc>.toc-list>li li {list-style: decimal!important;padding-left: 0;}');
        s.insertRule('.toc-bar__toc>.toc-list>li ol {padding-left: 8px;}');
        var nav = document.querySelector("#root > div.page-wrapper.document-page > div.breadcrumb-locale-container.eye-protector-processed > nav");
        if (!nav) {
            return;
        }
        tocbarbody.innerHTML = nav.outerHTML + tocbarbody.innerHTML;
        s.insertRule('#toc-bar > div.toc-bar__toc > ol > li > a {display:none;}');
    }
    setTimeout(change, 200);
    //window.addEventListener("hashchange",change);
})();