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.4
  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. GM_registerMenuCommand(`在控制台输出未匹配文本:【${DEBUG ? '开' : '关'}】`, () => {
  24. window.localStorage['dbg_mode'] = DEBUG ? '关' : '开';
  25. window.location.reload();
  26. });
  27.  
  28. const Locales = JSON.parse(GM_getResourceText("data"));
  29. // const Locales = {}
  30.  
  31. var Start = new Date().getTime();
  32.  
  33. //静态元素
  34. for (const [css, dic] of Object.entries(Locales.STATIC)) {
  35. if (DEBUG) {
  36. console.log(`〖${css}〗`);
  37. }
  38. const elements = document.querySelectorAll(css);
  39.  
  40. if (elements.length > 0) {
  41. for (let i = 0; i < elements.length; i++) {
  42. const element = elements[i];
  43. if (element.childElementCount === 0) {//节点内部无其他元素
  44. const raw = element.innerText;
  45. if (!raw || raw.length <= 2) { continue; }
  46. const txt = dic[raw];
  47. if (txt) {
  48. element.innerText = txt;
  49. } else if (DEBUG) {
  50. console.log(`"${raw}": "",`);
  51. }
  52. } else {//节点内部有其他元素
  53. const nodes = element.childNodes;
  54. for (let j = 0; j < nodes.length; j++) {
  55. const node = nodes[j];
  56. if (node.nodeType === Node.TEXT_NODE) {
  57. const raw = node.textContent;
  58. if (!raw || raw.length <= 2) { continue; }
  59. const txt = dic[raw];
  60. if (txt) {
  61. node.textContent = txt;
  62. } else if (DEBUG) {
  63. console.log(`"${raw}": "",`);
  64. }
  65. }
  66. }
  67. }
  68. }
  69. }
  70. }
  71.  
  72. //输入框
  73. {
  74. const inputs = Object.entries(Locales.INPUT);
  75. if (DEBUG) {
  76. console.log('〖输入框〗');
  77. }
  78. const elements = document.querySelectorAll("input");
  79. if (elements.length > 0) {
  80. for (let i = 0; i < elements.length; i++) {
  81. const element = elements[i];
  82. const raw = element.placeholder;
  83. if (!raw) { continue; }
  84. const txt = inputs[raw];
  85. if (txt) {
  86. element.placeholder = txt;
  87. } else if (DEBUG) {
  88. console.log(`"${raw}": "",`);
  89. }
  90. }
  91. }
  92. }
  93.  
  94.  
  95.  
  96. const { script: { version } } = GM_info;
  97. const { DOC: { "更新时间": update, "贡献名单": contribution } } = Locales;
  98.  
  99. // call your function
  100. var End = new Date().getTime();
  101. console.log('执行耗时', `${End - Start} ms`);
  102. console.log('=================================')
  103. console.log(`插件版本: ${version}`);
  104. console.log(`更新时间: ${update}`);
  105. console.log(`贡献名单: ${contribution.join(', ')}`);
  106.  
  107. // // 创建一个观察器实例并传入回调函数
  108. // const observer = new MutationObserver((mutationsList, observer) => {
  109. // // Use traditional 'for loops' for IE 11
  110. // for (let mutation of mutationsList) {
  111. // console.log(mutation);
  112.  
  113. // }
  114.  
  115. // });
  116.  
  117. // // 以上述配置开始观察目标节点
  118. // observer.observe(document.body, { childList: true, subtree: true });
  119.  
  120. // // 之后,可停止观察
  121. // observer.disconnect();
  122.  
  123. })();