Greasy Fork镜像 支持简体中文。

SteamDB_CN

SteamDB汉化插件

目前為 2022-02-18 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name:zh-CN SteamDB汉化
  3. // @name SteamDB_CN
  4. // @namespace https://blog.chrxw.com
  5. // @supportURL https://blog.chrxw.com/scripts.html
  6. // @contributionURL https://afdian.net/@chr233
  7. // @version 1.21
  8. // @description SteamDB汉化插件
  9. // @description:zh-cn SteamDB汉化插件
  10. // @author Chr_
  11. // @match https://steamdb.info/*
  12. // @license AGPL-3.0
  13. // @icon https://blog.chrxw.com/favicon.ico
  14. // @resource data https://gitee.com/chr_a1/gm_scripts/raw/master/SteamDB/lang_zh_CN.json
  15. // @grant GM_addStyle
  16. // @grant GM_getResourceText
  17. // @grant GM_registerMenuCommand
  18. // ==/UserScript==
  19.  
  20.  
  21. (function () {
  22. "use strict";
  23. const DEBUG = window.localStorage["dbg_mode"] == "开";
  24. const OUTPUT = window.localStorage["out_word"] == "开";
  25.  
  26. GM_registerMenuCommand(`调试汉化文本: ${DEBUG ? "开" : "关"}】`, () => {
  27. window.localStorage["dbg_mode"] = DEBUG ? "关" : "开";
  28. window.location.reload();
  29. });
  30.  
  31. GM_registerMenuCommand(`在控制台输出未匹配文本: ${OUTPUT ? "开" : "关"}】`, () => {
  32. window.localStorage["out_word"] = OUTPUT ? "关" : "开";
  33. window.location.reload();
  34. });
  35.  
  36. document.querySelector("html").setAttribute("lang", "zh-CN");
  37.  
  38. let Locales;
  39.  
  40. if (DEBUG) {
  41.  
  42. const template = `{"DOC":{"更新时间":"调试模式","贡献名单":["调试模式"]},\n"STATIC":\n{\n\n},\n"INPUT":\n{\n\n},\n"LABEL":\n{\n\n},\n"DYNAMIC":\n{\n\n}\n}`;
  43. const box = document.createElement("div");
  44. box.className = "sdc";
  45. const text = document.createElement("textarea");
  46. box.appendChild(text);
  47. const action = document.createElement("div");
  48. action.className = "app-links";
  49. box.appendChild(action);
  50. const btnSave = document.createElement("a");
  51. btnSave.innerText = "💾 保存并应用";
  52. btnSave.addEventListener("click", () => {
  53. const raw = text.value.trim();
  54. if (!raw) {
  55. alert("翻译文本不能为空!!!");
  56. } else {
  57. try {
  58. JSON.parse(raw);
  59. window.localStorage["sdb_lang"] = raw;
  60. window.location.reload();
  61. } catch (e) {
  62. alert("翻译文本不是有效的JSON格式!!!");
  63. }
  64. }
  65. });
  66. action.appendChild(btnSave);
  67. const btnReset = document.createElement("a");
  68. btnReset.textContent = "🗑️ 清空文本";
  69. btnReset.addEventListener("click", () => {
  70. window.localStorage["sdb_lang"] = template;
  71. window.location.reload();
  72. });
  73. action.appendChild(btnReset);
  74. const btnOnline = document.createElement("a");
  75. btnOnline.textContent = "📄 当前在线文本";
  76. btnOnline.addEventListener("click", () => {
  77. if (confirm("替换为在线版本后当前所做修改将会丢失, 确定要继续吗?")) {
  78. text.value = GM_getResourceText("data");
  79. }
  80. });
  81. action.appendChild(btnOnline);
  82. const about = document.createElement('a');
  83. about.href = "https://blog.chrxw.com"
  84. about.innerText = "🔗 By Chr_ © 2022";
  85. action.appendChild(about);
  86.  
  87. const father = document.getElementById("main");
  88. father.insertBefore(box, father.firstChild);
  89. const customLang = window.localStorage["sdb_lang"] ?? template;
  90. text.value = customLang;
  91. Locales = JSON.parse(customLang);
  92. } else {
  93. Locales = JSON.parse(GM_getResourceText("data"));
  94. }
  95.  
  96. //计时
  97. var Start = new Date().getTime();
  98.  
  99. {//静态元素
  100. for (const [css, dic] of Object.entries(Locales.STATIC)) {
  101. if (OUTPUT) { console.log(`〖${css}〗`); }
  102. const elements = document.querySelectorAll(css);
  103. if (elements.length > 0) {
  104. for (let i = 0; i < elements.length; i++) {
  105. const element = elements[i];
  106. if (element.childElementCount === 0) {//节点内部无其他元素
  107. const raw = element.innerText?.trim();
  108. if (!raw || raw.length <= 2) { continue; }
  109. const txt = dic[raw];
  110. if (txt) {
  111. element.innerText = txt;
  112. } else if (OUTPUT) {
  113. console.log(`"${raw}": "",`);
  114. }
  115. } else {//节点内部有其他元素
  116. const nodes = element.childNodes;
  117. for (let j = 0; j < nodes.length; j++) {
  118. const node = nodes[j];
  119. if (node.nodeType === Node.TEXT_NODE) {
  120. const raw = node.textContent?.trim();
  121. if (!raw || raw.length <= 2) { continue; }
  122. const txt = dic[raw];
  123. if (txt) {
  124. node.textContent = txt;
  125. } else if (OUTPUT) {
  126. console.log(`"${raw}": "",`);
  127. }
  128. }
  129. }
  130. }
  131. }
  132. } else {
  133. if (OUTPUT) { console.warn(`CSS选择器未匹配到任何元素: ${css}`); }
  134. }
  135. }
  136. }
  137.  
  138. {//输入框
  139. const inputs = Locales.INPUT;
  140. if (OUTPUT) { console.log("〖输入框〗"); }
  141. const elements = document.querySelectorAll("input");
  142. for (let i = 0; i < elements.length; i++) {
  143. const element = elements[i];
  144. const raw = element.placeholder;
  145. if (!raw) { continue; }
  146. const txt = inputs[raw];
  147. if (txt) {
  148. element.placeholder = txt;
  149. } else if (OUTPUT) {
  150. console.log(`"${raw}": "",`);
  151. }
  152. }
  153. }
  154.  
  155. {//悬浮提示
  156. const labels = Locales.LABEL;
  157. if (OUTPUT) { console.log("〖提示文本〗"); }
  158. const elements = document.querySelectorAll("*[aria-label]");
  159. for (let i = 0; i < elements.length; i++) {
  160. const element = elements[i];
  161. const raw = element.getAttribute("aria-label");
  162. if (!raw) { continue; }
  163. const txt = labels[raw];
  164. if (txt) {
  165. element.setAttribute("aria-label", txt);
  166. } else if (OUTPUT) {
  167. console.log(`"${raw}": "",`);
  168. }
  169. }
  170. }
  171.  
  172. const { script: { version } } = GM_info;
  173. const { DOC: { "更新时间": update, "贡献名单": contribution } } = Locales;
  174.  
  175. var End = new Date().getTime();
  176.  
  177. // 统计耗时
  178. console.log("执行耗时", `${End - Start} ms`);
  179. console.log("=================================");
  180. console.log(`插件版本: ${version}`);
  181. console.log(`更新时间: ${update}`);
  182. console.log(`贡献名单: ${contribution.join(", ")}`);
  183. console.log("=================================");
  184. console.log("迷茫同学:\n『没有恶意 请问直接用谷歌翻译整个网页不香吗』")
  185.  
  186. // 添加按钮
  187. const headerUl=document.querySelector(".header-menu-container>div>ul:nth-child(1)");
  188. const footerUl=document.querySelector(".footer-container>div>ul:nth-child(1)");
  189. const scriptLink = document.createElement("li");
  190. scriptLink.innerHTML = `<a href="https://blog.chrxw.com" target="_blank">SteamDB 汉化 V${version}</a>`;
  191. headerUl.appendChild(scriptLink);
  192. footerUl.appendChild(scriptLink.cloneNode(true));
  193.  
  194. // 添加样式
  195. GM_addStyle(`
  196. .tabnav-tabs > a {
  197. min-width: 80px;
  198. }
  199. .sdc {
  200. display: flex;
  201. }
  202. .sdc > textarea {
  203. width: 100%;
  204. height: 200px;
  205. min-height: 200px;
  206. resize: vertical;
  207. }
  208. .sdc > div.app-links {
  209. width: 150px;
  210. margin: 5px;
  211. }
  212. .sdc > div.app-links > a {
  213. width: 100%;
  214. margin-bottom: 10px;
  215. background-color: #213145;
  216. color: white;
  217. font-size: 12px;
  218. border-radius: 0px;
  219. }
  220. .sdc > div.app-links > a:last-child {
  221. width: 100%;
  222. margin-top: 30px;
  223. margin-bottom: 0px;
  224. color: #67c1f5;
  225. background-color: #273b4b;
  226. }
  227. `);
  228. })();

QingJ © 2025

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