Maskify

Ensitive Data Anonymizer

目前為 2024-09-11 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Maskify
// @namespace    shawnzhang31
// @license      MIT
// @version      0.1
// @description  Ensitive Data Anonymizer
// @author       守着瓜的猹
// @match        http://10.250.186.247:20201/project/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 正则表达式匹配IP地址
    const ipRegex = /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/g;

    // 正则表达式匹配电话号码(简单示例,可以根据实际情况调整)
   //const phoneRegexCN = /^(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])\d{8}\b/g;
   //const phoneRegexCN = /(?:\+?0?86)?1[3-9]\d{9}\b/g; // 支持+86前缀
    const phoneRegexCN = /(\+?0?86)?(1[3-9]\d{1})\d{5}(\d{3})\b/g;


    // 遍历页面的所有文本节点,并替换内容
    function maskSensitiveData() {
        const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
        let node;
        while (node = walker.nextNode()) {
            let newText = node.nodeValue;

            // 替换IP地址的中间部分为*
            newText = newText.replace(ipRegex, (match, p1, p2, p3, p4) => {
                return `${p1}.*.*.${p4}`;
            });


            // 替换电话号码中间部分为*
            newText = newText.replace(phoneRegexCN, (match, countryCode, firstPart, lastPart) => {
                return `${countryCode || ''}${firstPart}*****${lastPart}`;
            });


            // 更新文本节点
            if (newText !== node.nodeValue) {
                node.nodeValue = newText;
            }
        }
    }

    // 执行替换
    // maskSensitiveData();
    const observer = new MutationObserver(maskSensitiveData);
    observer.observe(document.body, { childList: true, subtree: true });
})();