Greasy Fork

来自缓存

Greasy Fork is available in English.

登录,不是登陆!

用“登录”替换所有“登陆”。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 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 "登录".`);
    }
})();