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.3
  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. for (const [css, dic] of Object.entries(Locales.STATIC)) {
  34. if (DEBUG) {
  35. console.log(`〖${css}〗`);
  36. }
  37. const elements = document.querySelectorAll(css);
  38.  
  39. if (elements.length > 0) {
  40. for (let i = 0; i < elements.length; i++) {
  41. const element = elements[i];
  42. if (element.childElementCount === 0) {//节点内部无其他元素
  43. const raw = element.innerText;
  44. if (!raw || raw.length <= 2) { continue; }
  45. const txt = dic[raw];
  46. if (txt) {
  47. element.innerText = txt;
  48. } else if (DEBUG) {
  49. console.log(`"${raw}": "",`);
  50. }
  51. } else {//节点内部有其他元素
  52. const nodes = element.childNodes;
  53. for (let j = 0; j < nodes.length; j++) {
  54. const node = nodes[j];
  55. if (node.nodeType === Node.TEXT_NODE) {
  56. const raw = node.textContent;
  57. if (!raw || raw.length <= 2) { continue; }
  58. const txt = dic[raw];
  59. if (txt) {
  60. node.textContent = txt;
  61. } else if (DEBUG) {
  62. console.log(`"${raw}": "",`);
  63. }
  64. }
  65. }
  66. }
  67. }
  68. }
  69. }
  70.  
  71. const { script: { version } } = GM_info;
  72. const { DOC: { "更新时间": update, "贡献名单": contribution } } = Locales;
  73.  
  74. // call your function
  75. var End = new Date().getTime();
  76. console.log('执行耗时', `${End - Start} ms`);
  77. console.log('=================================')
  78. console.log(`插件版本: ${version}`);
  79. console.log(`更新时间: ${update}`);
  80. console.log(`贡献名单: ${contribution.join(', ')}`);
  81.  
  82. // // 创建一个观察器实例并传入回调函数
  83. // const observer = new MutationObserver((mutationsList, observer) => {
  84. // // Use traditional 'for loops' for IE 11
  85. // for (let mutation of mutationsList) {
  86. // console.log(mutation);
  87.  
  88. // }
  89.  
  90. // });
  91.  
  92. // // 以上述配置开始观察目标节点
  93. // observer.observe(document.body, { childList: true, subtree: true });
  94.  
  95. // // 之后,可停止观察
  96. // observer.disconnect();
  97.  
  98. })();