Unicode字符串转中文

将网页中所有的Unicode字符串替换为中文

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Unicode字符串转中文
// @version      1.0
// @author        ChatGPT
// @description  将网页中所有的Unicode字符串替换为中文
// @match        *://*/*
// @run-at      document-end
// @grant        none
// @namespace https://greasyfork.org/users/452911
// ==/UserScript==

(function() {
  'use strict';

  function replaceUnicodeWithChinese() {
    var elements = document.getElementsByTagName('*');

    for (var i = 0; i < elements.length; i++) {
      var element = elements[i];
      var nodes = element.childNodes;

      for (var j = 0; j < nodes.length; j++) {
        var node = nodes[j];

        if (node.nodeType === Node.TEXT_NODE) {
          var text = node.nodeValue;
          var replacedText = text.replace(/\\u([\d\w]{4})/gi, function(match, grp) {
            return String.fromCharCode(parseInt(grp, 16));
          });

          if (replacedText !== text) {
            element.replaceChild(document.createTextNode(replacedText), node);
          }
        }
      }
    }
  }

  replaceUnicodeWithChinese();
})();