战舰世界莱服网页汉化-代码-框架

战舰世界莱服网页汉化-代码

目前为 2025-03-10 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/529413/1551061/%E6%88%98%E8%88%B0%E4%B8%96%E7%95%8C%E8%8E%B1%E6%9C%8D%E7%BD%91%E9%A1%B5%E6%B1%89%E5%8C%96-%E4%BB%A3%E7%A0%81-%E6%A1%86%E6%9E%B6.js

  1. // ==UserScript==
  2. // @name 战舰世界莱服网页汉化-代码-框架
  3. // @namespace https://github.com/windofxy
  4. // @version 202503051039
  5. // @description 战舰世界莱服网页汉化-代码
  6. // @author Windofxy
  7. // @icon https://gh-proxy.net/github.com/OpenKorabli/Korabli-InGameBrowser-L10n-CHS/blob/main/Tampermonkey%20Script/icon128.png
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. if(!window.__localizer__)
  13. {
  14. window.__localizer__ = {};
  15. }
  16. if(!window.__localizer__.localizer_framework_loaded)
  17. {
  18. window.__localizer__.localizer_framework_loaded = true;
  19. window.__localizer__.localizer_mode = { mode: "Polling", interval: 500 };
  20. window.__localizer__.localizer_Debug = { showPerformanceData: false, showMutationTargetClassName: false };
  21. window.__localizer__.localizer_Debug_Execute_Start_Time = 0;
  22.  
  23. window.__localizer__.localizer_Observe_ClassName_Now = "";
  24. window.__localizer__.localizer_Observe_ClassName_Set = new Set();
  25.  
  26. window.__localizer__.localizer_MutationObserver_Config = { childList: true, subtree: true };
  27. window.__localizer__.localizer_Pass_Element_Id_Set = new Set();
  28. window.__localizer__.localizer_Pass_Element_ClassName_Set = new Set();
  29.  
  30. window.__localizer__.localizer_Detect_Elements_CssSelector_Set = new Set();
  31. window.__localizer__.localizer_Detect_Elements_Override_Map = new Map();
  32. window.__localizer__.localizer_Detect_Elements_Replace_Map = new Map();
  33.  
  34. window.__localizer__.localizer_Observe_ClassName_Set.add("navalBase");
  35. window.__localizer__.localizer_Observe_ClassName_Set.add("tasks");
  36. window.__localizer__.localizer_Observe_ClassName_Set.add("members");
  37. window.__localizer__.localizer_Observe_ClassName_Set.add("search");
  38. window.__localizer__.localizer_Observe_ClassName_Set.add("new-recommendations");
  39. window.__localizer__.localizer_Observe_ClassName_Set.add("treasury");
  40. window.__localizer__.localizer_Observe_ClassName_Set.add("clan-wars");
  41.  
  42. window.__localizer__.localizer_Pass_Element_Id_Set.add("app");
  43. window.__localizer__.localizer_Pass_Element_Id_Set.add("wows-react-tooltip-body");
  44. window.__localizer__.localizer_Pass_Element_ClassName_Set.add("wru__Tooltip__header");
  45. window.__localizer__.localizer_Pass_Element_ClassName_Set.add("clan-wars");
  46. window.__localizer__.localizer_Pass_Element_ClassName_Set.add("TotalBalance_wrapper_1sZcM");
  47. window.__localizer__.localizer_Pass_Element_ClassName_Set.add("History_noTransactionsWrapper_2q7z-");
  48. window.__localizer__.localizer_Pass_Element_ClassName_Set.add("we-asset__text we-widget__text");
  49. window.__localizer__.localizer_Pass_Element_ClassName_Set.add("ViewClanStars_wrapper_18UHq");
  50. window.__localizer__.localizer_Pass_Element_ClassName_Set.add("ViewTreasury_tabContent_2MpE4");
  51. window.__localizer__.localizer_Pass_Element_ClassName_Set.add("ViewClanBattles_wrapper_1uPSF");
  52. window.__localizer__.localizer_Pass_Element_ClassName_Set.add("ViewClanWars_blurable_GNk-j ");
  53. window.__localizer__.localizer_Pass_Element_ClassName_Set.add("MyWarTab_content_1d_Lf");
  54. window.__localizer__.localizer_Pass_Element_ClassName_Set.add(
  55. "wru__Menu__toggle wru__Menu__isActive"
  56. );
  57. window.__localizer__.localizer_Pass_Element_ClassName_Set.add("LanguagesDialog_error_zZskG");
  58.  
  59. window.__localizer__.Localizer_Init = function () {
  60. window.__localizer__.detect_elements.forEach((value, index, set) => {
  61. let cssSelector = value[0];
  62. let arg = value[1];
  63. if (!cssSelector || !arg) return;
  64. window.__localizer__.localizer_Detect_Elements_CssSelector_Set.add(cssSelector);
  65. if (!arg.isReplace) {
  66. let element_arg_list =
  67. window.__localizer__.localizer_Detect_Elements_Override_Map.get(cssSelector);
  68. if (!element_arg_list) {
  69. window.__localizer__.localizer_Detect_Elements_Override_Map.set(cssSelector, new Set());
  70. window.__localizer__.localizer_Detect_Elements_Override_Map.get(cssSelector).add(arg);
  71. } else {
  72. element_arg_list.add(arg);
  73. }
  74. } else {
  75. let element_arg_list =
  76. window.__localizer__.localizer_Detect_Elements_Replace_Map.get(cssSelector);
  77. if (!element_arg_list) {
  78. window.__localizer__.localizer_Detect_Elements_Replace_Map.set(cssSelector, new Set());
  79. window.__localizer__.localizer_Detect_Elements_Replace_Map.get(cssSelector).add(arg);
  80. } else {
  81. element_arg_list.add(arg);
  82. }
  83. }
  84. });
  85.  
  86. if(window.__localizer__.localizer_mode.mode === "Event")
  87. {
  88. window.__localizer__.Localizer_Start_Event_Mode();
  89. }
  90. else if(window.__localizer__.localizer_mode.mode === "Polling")
  91. {
  92. window.__localizer__.Localizer_Start_Polling_Mode();
  93. }
  94. };
  95.  
  96. window.__localizer__.Localizer_Start_Event_Mode = function() {
  97. if(window.__localizer_Event_Mode_Observing__)
  98. {
  99. window.__localizer__.localizer_mutationObserver.disconnect();
  100. window.__localizer__.localizer_mutationObserver.observe(
  101. document.getRootNode(),
  102. window.__localizer__.localizer_MutationObserver_Config
  103. );
  104. window.__localizer_Event_Mode_Observing__ = true;
  105. }
  106. else
  107. {
  108. window.__localizer__.localizer_mutationObserver.observe(
  109. document.getRootNode(),
  110. window.__localizer__.localizer_MutationObserver_Config
  111. );
  112. window.__localizer_Event_Mode_Observing__ = true;
  113. }
  114. };
  115.  
  116. window.__localizer__.Localizer_Start_Polling_Mode = function() {
  117. if(window.__localizer_Polling_Mode_Interval_Num__)
  118. {
  119. clearInterval(window.__localizer_Polling_Mode_Interval_Num__);
  120. window.__localizer_Polling_Mode_Interval_Num__ = setInterval(window.__localizer__.Localizer_Work_Polling_Mode, window.__localizer__.localizer_mode.interval);
  121. }
  122. else
  123. {
  124. window.__localizer_Polling_Mode_Interval_Num__ = setInterval(window.__localizer__.Localizer_Work_Polling_Mode, window.__localizer__.localizer_mode.interval);
  125. }
  126. };
  127.  
  128. window.__localizer__.Localizer_Work_Event_Mode = function (mutationList, observer) {
  129. if (window.__localizer__.localizer_Debug.showPerformanceData) { window.__localizer__.localizer_Debug_Execute_Start_Time = performance.now(); }
  130. for (let mutation of mutationList) {
  131. if (mutation.type !== "childList") continue;
  132. if (
  133. mutation.target.className !== window.__localizer__.localizer_Observe_ClassName_Now &&
  134. window.__localizer__.localizer_Observe_ClassName_Set.has(mutation.target.className)
  135. ) {
  136. observer.disconnect();
  137. observer.observe(mutation.target, window.__localizer__.localizer_MutationObserver_Config);
  138. return;
  139. }
  140. if (window.__localizer__.localizer_Debug.showMutationTargetClassName) console.log(mutation.target.className);
  141. if (
  142. !window.__localizer__.localizer_Pass_Element_Id_Set.has(mutation.target.id) &&
  143. !window.__localizer__.localizer_Pass_Element_ClassName_Set.has(mutation.target.className)
  144. )
  145. return;
  146. window.__localizer__.localizer_Detect_Elements_CssSelector_Set.forEach(
  147. (cssSelector, index, set) => {
  148. let targetElementsList = document.querySelectorAll(cssSelector);
  149. targetElementsList.forEach((element, index, list) => {
  150. if (!element.innerText) return;
  151. let override_arg_list =
  152. window.__localizer__.localizer_Detect_Elements_Override_Map.get(cssSelector);
  153. if (override_arg_list) {
  154. override_arg_list.forEach((arg, index, list) => {
  155. var temp_translated_str = window.__localizer__.translation.get(
  156. arg.isReplaceHTML ? element.innerHTML : element.innerText
  157. );
  158. if (!temp_translated_str) return;
  159. if (arg.isReplaceHTML) {
  160. if (element.innerHTML === temp_translated_str) return;
  161. element.innerHTML = temp_translated_str;
  162. } else {
  163. if (element.innerText === temp_translated_str) return;
  164. element.innerText = temp_translated_str;
  165. }
  166. });
  167. }
  168. let replace_arg_list =
  169. window.__localizer__.localizer_Detect_Elements_Replace_Map.get(cssSelector);
  170. if (replace_arg_list) {
  171. replace_arg_list.forEach((arg, index, list) => {
  172. if (arg.isReplace !== true) return;
  173. var temp_translated_str = arg.isReplaceHTML
  174. ? element.innerHTML
  175. : element.innerText;
  176. arg.translation.forEach((value, index, array) => {
  177. temp_translated_str = temp_translated_str.replaceAll(
  178. value[0],
  179. value[1]
  180. );
  181. });
  182. if (arg.isReplaceHTML) {
  183. if (element.innerHTML === temp_translated_str) return;
  184. element.innerHTML = temp_translated_str;
  185. } else {
  186. if (element.innerText === temp_translated_str) return;
  187. element.innerText = temp_translated_str;
  188. }
  189. });
  190. }
  191. });
  192. }
  193. );
  194. }
  195. if (window.__localizer__.localizer_Debug.showPerformanceData) { console.log(`Localizer Work Time: ${ (performance.now() - window.__localizer__.localizer_Debug_Execute_Start_Time).toFixed(2)} ms`); }
  196. };
  197.  
  198. window.__localizer__.Localizer_Work_Polling_Mode = function () {
  199. if (window.__localizer__.localizer_Debug.showPerformanceData) { window.__localizer__.localizer_Debug_Execute_Start_Time = performance.now(); }
  200. window.__localizer__.localizer_Detect_Elements_CssSelector_Set.forEach(
  201. (cssSelector, index, set) => {
  202. let targetElementsList = document.querySelectorAll(cssSelector);
  203. targetElementsList.forEach((element, index, list) => {
  204. if (!element.innerText) return;
  205. let override_arg_list =
  206. window.__localizer__.localizer_Detect_Elements_Override_Map.get(cssSelector);
  207. if (override_arg_list) {
  208. override_arg_list.forEach((arg, index, list) => {
  209. var temp_translated_str = window.__localizer__.translation.get(
  210. arg.isReplaceHTML ? element.innerHTML : element.innerText
  211. );
  212. if (!temp_translated_str) return;
  213. if (arg.isReplaceHTML) {
  214. if (element.innerHTML === temp_translated_str) return;
  215. element.innerHTML = temp_translated_str;
  216. } else {
  217. if (element.innerText === temp_translated_str) return;
  218. element.innerText = temp_translated_str;
  219. }
  220. });
  221. }
  222. let replace_arg_list =
  223. window.__localizer__.localizer_Detect_Elements_Replace_Map.get(cssSelector);
  224. if (replace_arg_list) {
  225. replace_arg_list.forEach((arg, index, list) => {
  226. if (arg.isReplace !== true) return;
  227. var temp_translated_str = arg.isReplaceHTML
  228. ? element.innerHTML
  229. : element.innerText;
  230. arg.translation.forEach((value, index, array) => {
  231. temp_translated_str = temp_translated_str.replaceAll(
  232. value[0],
  233. value[1]
  234. );
  235. });
  236. if (arg.isReplaceHTML) {
  237. if (element.innerHTML === temp_translated_str) return;
  238. element.innerHTML = temp_translated_str;
  239. } else {
  240. if (element.innerText === temp_translated_str) return;
  241. element.innerText = temp_translated_str;
  242. }
  243. });
  244. }
  245. });
  246. }
  247. );
  248. if (window.__localizer__.localizer_Debug.showPerformanceData) { console.log(`Localizer Work Time: ${ (performance.now() - window.__localizer__.localizer_Debug_Execute_Start_Time).toFixed(2)} ms`); }
  249. };
  250.  
  251. window.__localizer__.localizer_mutationObserver = new MutationObserver(
  252. (mutationList, observer) => {
  253. setTimeout(() => {
  254. window.__localizer__.Localizer_Work_Event_Mode(mutationList, observer);
  255. }, 100);
  256. }
  257. );
  258.  
  259. window.__localizer__.detect_elements = new Set();
  260. window.__localizer__.translation = new Map();
  261. }

QingJ © 2025

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