Login, Not Landing!

Replaces ALL occurences of "登陆" with "登录".

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Login, Not Landing!
// @name:zh-CN   登录,不是登陆!
// @namespace    http://tampermonkey.net/
// @version      0.1.0
// @description  Replaces ALL occurences of "登陆" with "登录".
// @description:zh-CN 用“登录”替换所有“登陆”。
// @author       PRO-2684
// @match        *://*/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @license      gpl-3.0
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const log = console.log.bind(console, "[Login, Not Landing!]");
    let cnt = 0;
    // Actual text replacement
    const regex = new RegExp('登(\\s*)陆', 'g');
    function replace(text) {
        const replaced = text.replace(regex, (match, p1) => {
            cnt++;
            return `登${p1}录`;
        });
        const unchanged = text === replaced;
        return [unchanged, replaced];
    }
    // Whether to accept a node
    const accepted = [Node.TEXT_NODE, Node.ELEMENT_NODE];
    function accept(node) {
        return accepted.includes(node.nodeType) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
    }
    // Process a node
    const attrs = ['title', 'alt', 'placeholder'];
    function processNode(node) {
        switch (node.nodeType) {
            case Node.TEXT_NODE: {
                const [unchanged, replaced] = replace(node.textContent);
                if (!unchanged) {
                    node.textContent = replaced;
                }
                break;
            }
            case Node.ELEMENT_NODE: {
                for (const attr of attrs) {
                    if (node.hasAttribute(attr)) {
                        const [unchanged, replaced] = replace(node.getAttribute(attr));
                        if (!unchanged) {
                            node.setAttribute(attr, replaced);
                        }
                    }
                }
                break;
            }
        }
    }
    // Walk the DOM and replace text
    const walker = document.createTreeWalker(document, NodeFilter.SHOW_ALL, accept);
    while (walker.nextNode()) {
        processNode(walker.currentNode);
    }
    // Log the results
    if (cnt === 0) {
        log("No occurence of \"登陆\" found.");
    } else {
        log(`Replaced ${cnt} occurence(s) of "登陆" with "登录".`);
    }
})();