SteamDB_CN

SteamDB汉化插件

目前为 2021-12-15 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name SteamDB_CN
  3. // @name:zh-CN SteamDB汉化
  4. // @namespace https://blog.chrxw.com
  5. // @version 1.2
  6. // @description SteamDB汉化插件
  7. // @description:zh-cn SteamDB汉化插件
  8. // @author Chr_
  9. // @match https://steamdb.info/*
  10. // @supportURL https://steamcn.com/t339531-1-1
  11. // @license AGPL-3.0
  12. // @icon https://blog.chrxw.com/favicon.ico
  13. // @resource data https://gitee.com/chr_a1/gm_scripts/raw/master/SteamDB/lang_zh_CN.json
  14. // @grant GM_getResourceText
  15. // @grant GM_registerMenuCommand
  16. // ==/UserScript==
  17.  
  18.  
  19. (function () {
  20. 'use strict';
  21. const DEBUG = window.localStorage['dbg_mode'] == '开';
  22.  
  23. const locales = JSON.parse(GM_getResourceText("data"));
  24. // const locales = {};
  25.  
  26. for (const [css, dic] of Object.entries(locales.STATIC)) {
  27. if (DEBUG) {
  28. console.log(`〖${css}〗`);
  29. }
  30. const elements = document.querySelectorAll(css);
  31.  
  32. if (elements.length > 0) {
  33. for (let i = 0; i < elements.length; i++) {
  34. const element = elements[i];
  35. if (element.childElementCount === 0) {//节点内部无其他元素
  36. const raw = element.innerText;
  37. if (!raw || raw.length <= 2) { continue; }
  38. const txt = dic[raw];
  39. if (txt) {
  40. element.innerText = txt;
  41. } else if (DEBUG) {
  42. console.log(`"${raw}": "",`);
  43. }
  44. } else {//节点内部有其他元素
  45. const nodes = element.childNodes;
  46. for (let j = 0; j < nodes.length; j++) {
  47. const node = nodes[j];
  48. if (node.nodeType === Node.TEXT_NODE) {
  49. const raw = node.textContent;
  50. if (!raw || raw.length <= 2) { continue; }
  51. const txt = dic[raw];
  52. if (txt) {
  53. node.textContent = txt;
  54. } else if (DEBUG) {
  55. console.log(`"${raw}": "",`);
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. }
  63.  
  64. GM_registerMenuCommand(`在控制台输出未匹配文本:【${DEBUG ? '开' : '关'}】`, () => {
  65. window.localStorage['dbg_mode'] = DEBUG ? '关' : '开';
  66. window.location.reload();
  67. })
  68.  
  69. // // 创建一个观察器实例并传入回调函数
  70. // const observer = new MutationObserver((mutationsList, observer) => {
  71. // // Use traditional 'for loops' for IE 11
  72. // for (let mutation of mutationsList) {
  73. // console.log(mutation);
  74.  
  75. // }
  76.  
  77. // });
  78.  
  79. // // 以上述配置开始观察目标节点
  80. // observer.observe(document.body, { childList: true, subtree: true });
  81.  
  82. // // 之后,可停止观察
  83. // observer.disconnect();
  84.  
  85. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址