自动跳转 MDN 中文

点击 MDN 链接,自动跳转至中文路由

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         自动跳转 MDN 中文
// @namespace    http://tampermonkey.net/
// @version      0.2
// @license      MIT
// @description  点击 MDN 链接,自动跳转至中文路由
// @author       [Ares-Chang](https://github.com/Ares-Chang)
// @match        https://developer.mozilla.org/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=mozilla.org
// @link         https://github.com/Ares-Chang/tampermonkey
// @grant        none
// ==/UserScript==
;(function () {
  'use strict'

  const url = window.location.href

  // 如果 url 包含中文路由 || 包含 _stop 字段,则直接跳过
  if (url.includes('/zh-CN/') || url.includes('_stop')) return

  const language = document.querySelector('#languages-switcher-button')

  language.click() // 打开语言下拉菜单

  setTimeout(() => {
    const list = document.querySelectorAll('.languages-switcher-menu li')

    // 获取 list 中内容为 "中文" 的元素
    ;[...list].some(dom => {
      const judge = dom.innerText.includes('中文')
      if (judge) {
        dom.querySelector('a').click()
        return true
      }

      return false
    })

    language.click() // 关闭语言下拉菜单
  }, 0)
})()