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.0
  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. // ==/UserScript==
  16.  
  17.  
  18. (function () {
  19. 'use strict';
  20. const DEBUG = true;
  21.  
  22. const locales = JSON.parse(GM_getResourceText("data"));
  23. // const locales = {};
  24.  
  25. for (const [css, dic] of Object.entries(locales.STATIC)) {
  26. console.log(`〖${css}〗`);
  27. const elements = document.querySelectorAll(css);
  28.  
  29. if (elements.length > 0) {
  30. for (let i = 0; i < elements.length; i++) {
  31. const element = elements[i];
  32. if (element.childElementCount === 0) {//节点内部无其他元素
  33. const raw = element.innerText;
  34. if (!raw || raw.length <= 2) { continue; }
  35. const txt = dic[raw];
  36. if (txt) {
  37. element.innerText = txt;
  38. } else if (DEBUG) {
  39. console.log(`"${raw}": "",`);
  40. }
  41. } else {//节点内部有其他元素
  42. const nodes = element.childNodes;
  43. for (let j = 0; j < nodes.length; j++) {
  44. const node = nodes[j];
  45. if (node.nodeType === Node.TEXT_NODE) {
  46. const raw = node.textContent;
  47. if (!raw || raw.length <= 2) { continue; }
  48. const txt = dic[raw];
  49. if (txt) {
  50. node.textContent = txt;
  51. } else if (DEBUG) {
  52. console.log(`"${raw}": "",`);
  53. }
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
  60.  
  61. // // 创建一个观察器实例并传入回调函数
  62. // const observer = new MutationObserver((mutationsList, observer) => {
  63. // // Use traditional 'for loops' for IE 11
  64. // for (let mutation of mutationsList) {
  65. // console.log(mutation);
  66.  
  67. // }
  68.  
  69. // });
  70.  
  71. // // 以上述配置开始观察目标节点
  72. // observer.observe(document.body, { childList: true, subtree: true });
  73.  
  74. // // 之后,可停止观察
  75. // observer.disconnect();
  76.  
  77. })();