STS Helper

In Steam Translation Server, add many features to make translate easier.

当前为 2018-01-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name STS Helper
  3. // @namespace iFantz7E.StsHelper
  4. // @version 2.31
  5. // @description In Steam Translation Server, add many features to make translate easier.
  6. // @match *://translation.steampowered.com/*
  7. // @icon https://translation.steampowered.com/public/favicon.ico
  8. // @run-at document-start
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @grant GM_addStyle
  12. // @copyright 2014, 7-elephant
  13. // ==/UserScript==
  14.  
  15. //// Compatibility: Firefox 14+ from Mutation Observer
  16.  
  17. // http://userscripts.org/scripts/show/325610
  18. // https://greasyfork.org/scripts/2250-sts-helper/
  19.  
  20. (function ()
  21. {
  22. "use strict";
  23. // jshint multistr:true
  24. function initStyle()
  25. {
  26. GM_addStyle
  27. (" \
  28. /* STSH Modify CSS */ \
  29. body { color: #acacac; } \
  30. #logout { \
  31. position: fixed; z-index: 1001; right: 12px; top: 10px; \
  32. line-height: 24px; text-align: right; } \
  33. input[type='button'], input[type='submit'] { \
  34. cursor: pointer; padding: 1px 9px; } \
  35. input[type='button']:disabled, input[type='submit']:disabled { \
  36. cursor: default; color: #777; } \
  37. #suggestionmain { overflow-x: hidden; } \
  38. #suggestionmain > div:nth-child(4) > form:nth-child(2) > div:nth-child(1) { \
  39. text-align: left; } \
  40. .lbAction > div > input[value^='SUBMIT'] { \
  41. width: 750px; height: 30px; border-color: #777 #333 #777 #777; } \
  42. .lbAction > div > input[value^='RESUBMIT'] { \
  43. width: 641px; height: 30px; border-color: #777 #333 #777 #777; } \
  44. .lbAction > div > input[value='CANCEL'] { \
  45. width: 100px; height: 30px; margin-right: 5px; } \
  46. form.lbAction:nth-child(1) > div:nth-child(2) > input:nth-child(1) { \
  47. width: 90%; margin-top: 5px; } \
  48. .suggestion .lbAction textarea { \
  49. max-width: 700px !important; min-height: 50px; } \
  50. .progress td { vertical-align: top; } \
  51. div#suggestions_nav { \
  52. z-index: 3; position: absolute; width: 440px; \
  53. left: 543px; top: 2px; text-align: right; line-height: 24px; \
  54. color: #E1E1E1; } \
  55. #suggestionmain .smallcopy { width: 855px; min-height: 70px; max-height: 70px; } \
  56. #suggestionmain .progress { margin-top: -12px; } \
  57. #leftAreaContainer > table > tbody:nth-child(1) > tr > td:nth-child(1) { \
  58. vertical-align: top; } \
  59. #leftAreaContainer > table, #leftAreaContainer > table th, #leftAreaContainer > table td { \
  60. border: 1px solid #333; border-collapse: collapse; padding: 4px; } \
  61. #suggestions_box { margin-top: 1px !important; position: relative; z-index: 20; } \
  62. #suggestions_iframe { min-height: 100px !important; } \
  63. #keylist td:nth-child(1) > div { \
  64. background-image: none !important; min-height: 43px; } \
  65. #keylist tr:nth-child(2n) > td:nth-child(1) > div { \
  66. background-color: #060606 !important; } \
  67. #keylist tr:nth-child(2n) > td:nth-child(1) > div:hover { \
  68. background-color: #0D0D0D !important; } \
  69. #keylist td:nth-child(1) > div:hover { \
  70. background-repeat: no-repeat; background-position: center; \
  71. background-color: #0D0D0D !important; \
  72. background-image: url('./public/images/row_over.gif') !important; } \
  73. #keylist td.progress { \
  74. color: #fff; max-width: 430px; overflow: hidden; \
  75. text-overflow: ellipsis; white-space: nowrap; } \
  76. .progress h1 { display: inline-block; width: 484px; } \
  77. div#suggestions_box iframe { background-color: #111 !important; } \
  78. .suggestions_list { border-right: 0px none !important; } \
  79. .suggestion { \
  80. resize: both; overflow: hidden; border-right: 1px solid #505050; \
  81. max-width: 953px; min-width: 200px; min-height: 50px; } \
  82. .suggestion_signature { font-family: Verdana; } \
  83. .stsh_action_approve, .stsh_action_approve_next { color: #A4B23C } \
  84. .stsh_action_decline, .stsh_action_decline_next { color: #F22 } \
  85. .suggestion_signature input:disabled { color: #777 !important; } \
  86. .lbAction input[value~='COMMENT'] { \
  87. vertical-align: top; margin-top: 1px; height: 52px; } \
  88. .lbAction input[value~='DISCUSS'] { \
  89. vertical-align: top; margin-top: 1px; height: 21px; top: 0px !important; } \
  90. #votes_container a[title='not translated'] { background-color: #333; } \
  91. #suggestion_value_new { min-height: 84px; max-width: 960px; min-width: 200px; overflow-y: auto; } \
  92. #hours > table > tbody > tr:nth-child(2) > th:nth-child(1) { width: 106px; text-align: center; } \
  93. #hours > table > tbody > tr:nth-child(2) > th:nth-child(3) { text-align: center; } \
  94. #hours > table > tbody > tr:nth-child(2) > th:nth-child(4) { text-align: center; } \
  95. #hours > table > tbody > tr > td:nth-child(1) { padding-right: 4px; } \
  96. #hours > table input[name*='[remarks]'] { width: 520px; } \
  97. #hours > table input[name*='[hours]'] { width: 100px; } \
  98. #hours > table input[name*='[minutes]'] { width: 100px; } \
  99. #suggestions_box_outer { overflow: hidden !important; } \
  100. #add_to_discussion { height: 19px; min-height: 19px; } \
  101. .gradienttable td > div { top: 1px !important; } \
  102. .copysmall > td:nth-child(1) { \
  103. white-space: nowrap; overflow: hidden; text-overflow: ellipsis; \
  104. display: inline-block; width: 430px; direction: ltr; } \
  105. div:hover > table > tbody > tr.copysmall > td:nth-child(1) { \
  106. direction: rtl; text-shadow: 1px 1px 1px #0D0D0D;} \
  107. #search input[type='radio'], #search input[type='checkbox'] \
  108. , #search button, #search label { cursor: pointer; } \
  109. .suggestion_error { max-width: 600px; margin: auto; } \
  110. ");
  111. GM_addStyle
  112. (" \
  113. /* STSH Main CSS */ \
  114. .stsh_btn { width: 90px; } \
  115. .stsh_btn_med { min-width: 112px; } \
  116. .stsh_btn_long { min-width: 136px; } \
  117. .stsh_btn_short { min-width: 66px; } \
  118. .stsh_btn_right { position: relative; float: right; margin-left: 4px; } \
  119. .stsh_border_left { border-color: #777 #333 #777 #777 !important; } \
  120. .stsh_border_right { border-color: #777 #777 #777 #333 !important; } \
  121. .stsh_suggestion_header { color: #A4B23C; } \
  122. .stsh_suggestion_comment:before { background-color: #E15417 !important; } \
  123. .stsh_suggestion_pending:before { background-color: #DDD !important; } \
  124. .stsh_suggestion_approved:before { background-color: #A4B23C !important; } \
  125. .stsh_suggestion_declined:before { background-color: #F22 !important; } \
  126. .stsh_suggestion_applied:before { background-color: #2EBCEB !important; } \
  127. .stsh_suggestion_removed:before { background-color: #777 !important; } \
  128. .stsh_suggestion { list-style: none; } \
  129. .stsh_suggestion:before { \
  130. content: ''; display: inline-block; position: relative; height: 6px; width: 6px; \
  131. border-radius: 3px; background-clip: padding-box; margin-right: -6px; \
  132. top: -1px; left: -12px; background-color: green; }\
  133. #stsh_frame { \
  134. text-align: center; position: fixed; z-index: 10; \
  135. top: 100px; left: 50%; margin-left: -322px;} \
  136. #stsh_frame_sub { \
  137. background-color: #111; width: 600px; display: inline-block; \
  138. padding: 20px; border: 2px solid #cf9e5f; } \
  139. .stsh_blue { color: #2ebceb; } \
  140. .stsh_blue_light { color: #87beed; } \
  141. .stsh_blue_dark { color: #1B6A85; } \
  142. .stsh_green { color: #a4b23c !important; } \
  143. .stsh_green_dark { color: #3a482a; } \
  144. .stsh_red { color: #F22; } \
  145. .stsh_white { color: #e1e1e1; } \
  146. .stsh_grey { color: #777 !important; } \
  147. .stsh_orange { color: #E15417; } \
  148. .stsh_orange_light { color: #CF8B37; } \
  149. .stsh_orange_lighter { color: #EDB687; } \
  150. .stsh_aqua { color: #538583; } \
  151. .stsh_pink { color: pink; } \
  152. .stsh_yellow { color: #E0B816; } \
  153. .stsh_yellow_light { color: #E0CA70; } \
  154. .stsh_greenyellow_light { color: #D1E070; } \
  155. .stsh_border_green { border-color: #76802B !important; } \
  156. .stsh_border_green_left { border-color: #76802B #474D1A #76802B #76802B !important; } \
  157. .stsh_cursor_notallowed { cursor: not-allowed !important; } \
  158. .stsh_cursor_pointer { cursor: pointer !important; } \
  159. .stsh_cursor_default { cursor: default !important; } \
  160. .stsh_cursor_help { cursor: help; !important; } \
  161. #stsh_showing { \
  162. color: #CCDAD6; position: fixed; z-index: 1001; \
  163. right: 12px; bottom: 12px; text-align: right; line-height: 14px;} \
  164. #stsh_showing_current { \
  165. color: #CCDAD6; position: fixed; z-index: 1001; \
  166. right: 12px; bottom: 28px; text-align: right; line-height: 14px;} \
  167. .stsh_showing_counter { \
  168. display: inline-block; min-width: 60px; text-align: center; } \
  169. .stsh_showing_header { \
  170. color: #CCDAD6; display: inline-block; width: 135px; \
  171. text-align: center; padding-top: 10px; } \
  172. .stsh_showing_group { \
  173. position: fixed; z-index: 3; right: 10px; top: 74px; \
  174. line-height: 24px; text-align: right; } \
  175. .stsh_home_header { color: #CCDAD6; display: inline-block; padding-top: 10px; } \
  176. .stsh_home_group { \
  177. position: fixed; z-index: 3; right: 0px; top: 74px; \
  178. line-height: 24px; text-align: center; width: 164px; } \
  179. .stsh_scroll_header { \
  180. color: #CCDAD6; display: inline-block; width: 130px; \
  181. text-align: center; padding-top: 10px; } \
  182. #stsh_specialEvent { position: absolute; z-index: 2; right: 164px; top: 13px; } \
  183. @media screen and (min-width: 1500px) { \
  184. #stsh_specialEvent { position: fixed; } \
  185. } \
  186. .stsh_snapshot { \
  187. position: absolute; top: 320px; left: 790px; \
  188. width: 140px; text-align: center; color: #FFF; } \
  189. .stsh_text_comment_header { vertical-align: top; } \
  190. .stsh_text_comment { vertical-align: top; display: inline-block; max-width: 850px; } \
  191. #stsh_autoApprove { vertical-align: -2px; margin-left: 15px; margin-right: 1px; } \
  192. .stsh_unselectable { \
  193. -webkit-touch-callout: none !important; \
  194. -webkit-user-select: none !important; \
  195. -khtml-user-select: none !important; \
  196. -moz-user-select: none !important; \
  197. -ms-user-select: none !important; \
  198. user-select: none !important; } \
  199. .stsh_a_button { \
  200. background-color: #1D1D1D; \
  201. font-family: tahoma,arial,helvetica,trebuchet ms,sans-serif; \
  202. color: #E1E1E1; font-size: 13px; border: 1px solid #777; padding: 1px 9px; } \
  203. .stsh_a_button:link, .stsh_a_button:hover, .stsh_a_button:active, .stsh_a_button:visited { \
  204. color: #E1E1E1; text-decoration: none; } \
  205. .stsh_a_button.stsh_btn { \
  206. display: inline-block; padding: 0px; \
  207. height: 19px; line-height: 19px; width: 88px; } \
  208. .stsh_a_button.stsh_btn_med { \
  209. display: inline-block; padding: 0px; \
  210. height: 19px; line-height: 19px; min-width: 110px; } \
  211. .stsh_a_button.stsh_btn_long { \
  212. display: inline-block; padding: 0px; \
  213. height: 19px; line-height: 19px; min-width: 134px; } \
  214. .stsh_lineCounter_outer { position: relative; } \
  215. .stsh_lineCounter { \
  216. position: absolute; width: 30px; left: -35px; top: -28px; \
  217. line-height: 28px; text-align: right; \
  218. color: #ACACAC; font-size: 9px; text-shadow: 0px 0px 3px #111; } \
  219. .stsh_glossary_term { min-width: 50px; display: inline-block; } \
  220. .stsh_glossary_header { font-family: Verdana; } \
  221. .stsh_glossary_header, .stsh_glossary_header td { color: #DDD; } \
  222. .stsh_glossary_header *, .stsh_glossary_header td * { color: #858585; } \
  223. .stsh_glossary_header > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(4) { \
  224. width: 10px !important; } \
  225. .stsh_comment_img { \
  226. display: block; cursor: zoom-in; cursor: -webkit-zoom-in; cursor: -moz-zoom-in; \
  227. max-width: 400px; margin-top: 5px; margin-bottom: 20px; } \
  228. .stsh_hours_curDate { color: #A4B23C; } \
  229. .stsh_hours_curDate input { border-color: #A4B23C; } \
  230. .stsh_submit_suggestion_right { \
  231. height: 30px; width: 214px; margin-right: 5px; border-color: #777 #777 #777 #333; } \
  232. .stsh_truncate { \
  233. white-space: nowrap; overflow: hidden; text-overflow: ellipsis; \
  234. display: inline-block; vertical-align: bottom; } \
  235. .stsh_token_name { max-width: 500px; } \
  236. .stsh_token_share { max-width: 600px; font-size: 0.8em; direction: rtl; } \
  237. .stsh_token_share:hover { direction: ltr; } \
  238. .stsh_pad { padding-left: 2px; padding-right: 2px; } \
  239. .stsh_hidden { display: none; } \
  240. table.gradienttable .stsh_curLang td, table.gradienttable .stsh_dst_curLang td \
  241. , table.gradienttable .stsh_dst_curLang th { \
  242. background: transparent \
  243. linear-gradient(to bottom, #171717 0%, rgba(71, 77, 26, 0.66) 40%, #121212 100%) \
  244. repeat scroll 0% 0% !important; } \
  245. .stsh_delta #suggestion_value_new { border-color: #1B6A85; } \
  246. .stsh_delta .stsh_text_submit { \
  247. color: #2EBCEB; border-color: #1B6A85 #083F52 #1B6A85 #1B6A85 !important; } \
  248. .stsh_delta .stsh_submit_suggestion_right { \
  249. color: #2EBCEB; border-color: #1B6A85 #1B6A85 #1B6A85 #083F52 !important; } \
  250. .stsh_delta .suggestions_list, .stsh_delta .suggestion { \
  251. border-color: #083F52 !important; } \
  252. .stsh_usThem_curLang { background-color: #2F3317; color: #E1E1E1; } \
  253. .stsh_dst_curLang, table.gradienttable .stsh_dst_curLang th, .stsh_dst_curLang a { \
  254. color: #2ebceb; } \
  255. .stsh_text_trn .lbAction textarea { max-width: 450px !important; } \
  256. .stsh_text_trn .lbAction input[value~='COMMENT'] { height: auto; } \
  257. .stsh_text_trn .stsh_text_submit { width: 270px !important; } \
  258. .stsh_text_trn .stsh_submit_suggestion_right { \
  259. width: 184px !important; margin-right: 32px !important; } \
  260. .stsh_text_org, .stsh_text_trn { min-height: 21px; display: block; max-width: 486px !important; } \
  261. .stsh_text_org { margin-bottom: 3px; } \
  262. .stsh_autoLoginOption { display: inline-block; vertical-align: top; line-height: 69px; padding-left: 30px; } \
  263. #stsh_autoLogin { margin-right: 0px; } \
  264. .stsh_moveSuggestionContainer { margin-top: -3px; } \
  265. #stsh_moveSuggestionBox, #stsh_moveSuggestionList { margin-right: 5px; } \
  266. #stsh_hoursCalc_from { width: 130px; } \
  267. #stsh_hoursCalc_to { width: 130px; border-right: 1px #333 solid; } \
  268. #stsh_hoursCalc_toNow { border-left: 1px #333 solid; } \
  269. .stsh_nav_prev { border-right-color: #333; } \
  270. .stsh_nav_next { border-left-color: #333; } \
  271. .stsh_nav_group { display: inline-block; } \
  272. .stsh_nav_group .stsh_a_button { \
  273. display: inline-block; text-align: center; \
  274. line-height: 17px; min-width: 40px; } \
  275. .stsh_nav_group .stsh_a_button:first-child:not(:last-child) { border-right-color: #333; } \
  276. .stsh_nav_group .stsh_a_button:last-child:not(:first-child) { border-left-color: #333; } \
  277. .stsh_nav_group .stsh_a_button:not(:first-child):not(:last-child) { \
  278. border-left-color: #333; border-right-color: #333; } \
  279. .stsh_img_min { max-width: 200px !important; height: auto !important; } \
  280. .stsh_showHidden { \
  281. display: inherit !important; background-color: #1d1d1d; padding: 1px 5px; \
  282. max-height: inherit !important; height: inherit !important; } \
  283. .stsh_discussion_header input[type='button'] { \
  284. padding: 1px 6px; } \
  285. .stsh_counter { display: inline-block; } \
  286. .stsh_counter[data-counter='Char: 0 :: Word: 0'] { display: none; } \
  287. .stsh_counter:after { content: attr(data-counter); position: absolute; \
  288. margin-left: -200px; width: 198px; text-align: right; } \
  289. #stsh_spanSpOrg, #stsh_spanSpTrn { display: block; margin-top: -4px; margin-bottom: 8px; } \
  290. .stsh_spanSpSug, .stsh_spanDctSug { display: block; margin-top: 8px; margin-bottom: 12px; } \
  291. .stsh_autoCopy_header font { color: #a4b23c !important; font-weight: normal; font-family: Verdana;} \
  292. .stsh_glossary_move { color: #e1e1e1; margin-left: 4px; } \
  293. .stsh_sametoken_file { display: inline-block; } \
  294. ");
  295. }
  296.  
  297. function attachOnLoad(callback)
  298. {
  299. window.addEventListener("load", function (e)
  300. {
  301. callback();
  302. });
  303. }
  304.  
  305. function attachOnReady(callback)
  306. {
  307. document.addEventListener("DOMContentLoaded", function (e)
  308. {
  309. callback();
  310. });
  311. }
  312.  
  313. function insertBeforeElement(newNode, referenceNode)
  314. {
  315. referenceNode.parentNode.insertBefore(newNode, referenceNode);
  316. }
  317.  
  318. function insertAfterElement(newNode, referenceNode)
  319. {
  320. referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
  321. }
  322.  
  323. function addKey(eleListener, eleClick, keyCode, keyName, keyTitleMode, keyModifierName, checkModifierCallback)
  324. {
  325. /*
  326. keyTitleMode:
  327. 0: do nothing
  328. 1: append value
  329. 2: add title if not exist
  330. 4: override title
  331. 8: append textContent
  332. 16: append textContent of firstElementChild
  333. keyModifierName:
  334. Ctrl, Ctrl+Shift, Alt
  335. */
  336. keyCode = keyCode || 0;
  337. keyName = keyName || "";
  338. keyTitleMode = keyTitleMode || 0;
  339. keyModifierName = keyModifierName || "";
  340. if (typeof checkModifierCallback !== "function")
  341. {
  342. checkModifierCallback = function(ev)
  343. {
  344. return ev.ctrlKey && ev.shiftKey && ev.altKey;
  345. };
  346. }
  347. if (eleListener && eleClick)
  348. {
  349. // apply title
  350. var keyTitle = keyModifierName ? keyModifierName + "+" + keyName : "";
  351. if (keyTitle !== "")
  352. {
  353. if ((keyTitleMode & 1) === 1)
  354. {
  355. // 1: append value
  356. if (typeof eleClick.value !== "undefined")
  357. {
  358. eleClick.value += " (" + keyTitle + ")";
  359. }
  360. }
  361. if ((keyTitleMode & 2) === 2)
  362. {
  363. // 2: add title if not exist
  364. if (!eleClick.title)
  365. {
  366. eleClick.title = keyTitle;
  367. }
  368. }
  369. if ((keyTitleMode & 4) === 4)
  370. {
  371. // 4: override title
  372. eleClick.title = keyTitle;
  373. }
  374. if ((keyTitleMode & 8) === 8)
  375. {
  376. // 8: append textContent
  377. eleClick.textContent += " (" + keyTitle + ")";
  378. }
  379. if ((keyTitleMode & 16) === 16)
  380. {
  381. // 16: append textContent of firstElementChild
  382. if (eleClick.firstElementChild)
  383. {
  384. eleClick.firstElementChild.textContent += " (" + keyTitle + ")";
  385. }
  386. }
  387. }
  388. eleListener.addEventListener("keydown", function (ev)
  389. {
  390. if (checkModifierCallback(ev))
  391. {
  392. var isSameKey = false;
  393. if (typeof keyCode === "number" && isFinite(keyCode) && Math.floor(keyCode) === keyCode)
  394. {
  395. // polyfill for Number.isInteger before Firefox 16
  396. isSameKey = (ev.keyCode === keyCode);
  397. }
  398. else
  399. {
  400. // Firefox 32+
  401. isSameKey = (typeof ev.code !== "undefined" && ev.code === keyCode)
  402. }
  403. if (isSameKey)
  404. {
  405. ev.preventDefault();
  406. eleClick.focus();
  407. eleClick.click();
  408. return false;
  409. }
  410. }
  411. }, true);
  412. }
  413. }
  414.  
  415. function addKeyCtrl(eleListener, eleClick, keyCode, keyName, keyTitleMode)
  416. {
  417. addKey(eleListener, eleClick, keyCode, keyName, keyTitleMode, "Ctrl", function(ev)
  418. {
  419. return ev.ctrlKey && !ev.shiftKey && !ev.altKey;
  420. });
  421. }
  422.  
  423. function addKeyCtrlShift(eleListener, eleClick, keyCode, keyName, keyTitleMode)
  424. {
  425. addKey(eleListener, eleClick, keyCode, keyName, keyTitleMode, "Ctrl+Shift", function(ev)
  426. {
  427. return ev.ctrlKey && ev.shiftKey && !ev.altKey;
  428. });
  429. }
  430.  
  431. function addKeyAlt(eleListener, eleClick, keyCode, keyName, keyTitleMode)
  432. {
  433. addKey(eleListener, eleClick, keyCode, keyName, keyTitleMode, "Alt", function(ev)
  434. {
  435. return !ev.ctrlKey && !ev.shiftKey && ev.altKey;
  436. });
  437. }
  438.  
  439. function addKeyCtrlEnter(form, input)
  440. {
  441. addKeyCtrl(form, input, 13, "Enter", 1|2);
  442. }
  443.  
  444. function addKeyCtrlShiftEnter(form, input)
  445. {
  446. addKeyCtrlShift(form, input, 13, "Enter", 1|2);
  447. }
  448.  
  449. function disableAfterClick(ele)
  450. {
  451. ele.addEventListener("click", function (e)
  452. {
  453. var ele = e.target;
  454. var attrClick = ele.getAttribute("onclick");
  455. if (attrClick && attrClick.indexOf("confirm") > -1)
  456. {
  457. // skip if has confirm
  458. return;
  459. }
  460. var tagName = ele.tagName;
  461. if (tagName === "INPUT")
  462. {
  463. // don't change color after disable
  464. var styleCp = window.getComputedStyle(ele);
  465. if (styleCp)
  466. {
  467. ele.style.setProperty("color", styleCp.color, "important");
  468. }
  469. ele.disabled = true;
  470. }
  471. else if (tagName === "IMG")
  472. {
  473. ele.removeAttribute("onclick");
  474. }
  475. }, true);
  476. }
  477.  
  478. function removeAllEventListeners(element)
  479. {
  480. if (element)
  481. {
  482. var clone = element.cloneNode(false);
  483. while (element.firstChild)
  484. {
  485. clone.appendChild(element.lastChild);
  486. }
  487. element.parentNode.replaceChild(clone, element);
  488. }
  489. }
  490.  
  491. function scrollToId(id, offset)
  492. {
  493. scrollToElement("#" + id, offset);
  494. }
  495.  
  496. function scrollToElement(selector, offset)
  497. {
  498. if (typeof offset === "undefined")
  499. {
  500. offset = -20;
  501. }
  502. var ele = null;
  503. if (selector)
  504. {
  505. if (selector instanceof HTMLElement)
  506. {
  507. ele = selector;
  508. }
  509. else
  510. {
  511. ele = document.querySelector(selector);
  512. }
  513. if (ele)
  514. {
  515. ele.scrollIntoView(true);
  516. window.scrollBy(0, offset);
  517. }
  518. }
  519. }
  520.  
  521. function resizeSuggestionBox()
  522. {
  523. var script = document.createElement('script');
  524. script.innerHTML =
  525. " \
  526. var stsh_showSuggestionsBox_start = getTimeMs(); \
  527. var stsh_showSuggestionsBox_itv = setIntervalCustom(function() \
  528. { \
  529. var stsh_showSuggestionsBox_isEnd = false; \
  530. var stsh_showSuggestionsBox_cur = getTimeMs(); \
  531. if (typeof showSuggestionsBox !== 'undefined') \
  532. { \
  533. showSuggestionsBox = function(url) \
  534. { \
  535. /* Edit from STS */ \
  536. g_suggestionsBoxIsOpen = true; \
  537. $('suggestions_box_outer').appear( \
  538. { \
  539. duration : 0.1 \
  540. } \
  541. ); \
  542. $('suggestions_iframe').setAttribute('src', url); \
  543. if (!Prototype.Browser.IE) \
  544. { \
  545. $('suggestions_iframe').focus(); \
  546. } \
  547. $('suggestions_iframe').style.height = (document.viewport.getHeight() * 0.99) + 'px'; \
  548. return false; \
  549. }; \
  550. stsh_showSuggestionsBox_isEnd = true; \
  551. } \
  552. if (stsh_showSuggestionsBox_isEnd || stsh_showSuggestionsBox_cur - stsh_showSuggestionsBox_start > 10000) \
  553. { \
  554. clearInterval(stsh_showSuggestionsBox_itv); \
  555. } \
  556. }, 300); \
  557. ";
  558. document.head.appendChild(script);
  559.  
  560. window.addEventListener("resize", function()
  561. {
  562. var iframe = document.querySelector("#suggestions_iframe");
  563. if (iframe)
  564. {
  565. iframe.style.height = (window.innerHeight * 0.99) + "px";
  566. }
  567. });
  568. }
  569.  
  570. function isRally()
  571. {
  572. var date = new Date();
  573. var year = date.getUTCFullYear();
  574. var month = date.getUTCMonth() + 1;
  575. var day = date.getUTCDate();
  576. if ((month > 9) || (month === 9 && day >= 22) || (month === 0 && day <= 2))
  577. {
  578. return true;
  579. }
  580. return false;
  581. }
  582.  
  583. function getQueryByName(name, url)
  584. {
  585. if (!url)
  586. {
  587. url = (!location) ? "" : location.search;
  588. }
  589. name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  590. var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
  591. var results = regex.exec(url);
  592. var retVal = "";
  593. if (results)
  594. {
  595. retVal = results[1].replace(/\+/g, " ");
  596. try
  597. {
  598. retVal = decodeURIComponent(retVal);
  599. }
  600. catch (ex)
  601. {
  602. console.error("getQueryByName", ex.message);
  603. }
  604. }
  605. return retVal;
  606. }
  607.  
  608. function padZero(num, size)
  609. {
  610. return (1e15 + num + "").slice(-size);
  611. }
  612.  
  613. function padZeroHex(num, size)
  614. {
  615. return ("00000000000000000000000" + num.toString(16)).slice(-size).toUpperCase();
  616. }
  617.  
  618. function randNum(min, max)
  619. {
  620. return Math.round(Math.random() * (max - min) + min);
  621. }
  622.  
  623. function isSpecialChar(ch)
  624. {
  625. var chCode = -1;
  626. if (typeof ch === 'number')
  627. {
  628. chCode = ch;
  629. }
  630. else
  631. {
  632. chCode = ch.charCodeAt(0);
  633. }
  634. if ((chCode > -1 && chCode < 9) // 0-8
  635. || (chCode > 10 && chCode < 13) // 11-12
  636. || (chCode > 13 && chCode < 32)) // 14-31
  637. {
  638. return true;
  639. }
  640. return false;
  641. }
  642.  
  643. function hasSpecialChar(str)
  644. {
  645. var rgxSpCh = /[\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u000B\u000C\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F]+/;
  646. return rgxSpCh.test(str);
  647. }
  648. function checkSpecialCharMatched(str1, str2)
  649. {
  650. // return (status, numSp1, numSp2)
  651. // status: 0:Match, 1:NotMatch, 2:NotEqual
  652. str1 = str1 || "";
  653. str2 = str2 || "";
  654. var strOut1 = "";
  655. var strOut2 = "";
  656. for (var i = 0; i < str1.length; i++)
  657. {
  658. if (isSpecialChar(str1[i]))
  659. {
  660. strOut1 += str1[i];
  661. }
  662. }
  663. for (var i = 0; i < str2.length; i++)
  664. {
  665. if (isSpecialChar(str2[i]))
  666. {
  667. strOut2 += str2[i];
  668. }
  669. }
  670. var retVal = 0;
  671. if (strOut1 === strOut2)
  672. retVal = 0;
  673. else if (strOut1.length === strOut2.length)
  674. retVal = 1;
  675. else
  676. retVal = 2;
  677. return new Array(retVal, strOut1.length, strOut2.length);
  678. }
  679.  
  680. function countDiacriticalMark(str)
  681. {
  682. str = str || "";
  683. var rgxDct = /[\u0300-\u036F]/g;
  684. var matchDct = str.match(rgxDct);
  685. var countDct = matchDct ? matchDct.length : 0;
  686.  
  687. return countDct;
  688. }
  689.  
  690. function trimSpace(str)
  691. {
  692. return str.replace(/^[ \r\n\t]+/, "").replace(/[ \r\n\t]+$/, "");
  693. }
  694.  
  695. if (!String.prototype.endsWith)
  696. {
  697. String.prototype.endsWith = function(searchString, position)
  698. {
  699. var subjectString = this.toString();
  700. if (typeof position !== 'number' || !isFinite(position)
  701. || Math.floor(position) !== position || position > subjectString.length)
  702. {
  703. position = subjectString.length;
  704. }
  705. position -= searchString.length;
  706. var lastIndex = subjectString.indexOf(searchString, position);
  707. return lastIndex !== -1 && lastIndex === position;
  708. };
  709. }
  710.  
  711. function reload()
  712. {
  713. var curHref = window.location.href;
  714. var posHashtag = curHref.indexOf("#");
  715. if (posHashtag > -1)
  716. {
  717. window.location = curHref.substr(0, posHashtag);
  718. }
  719. else
  720. {
  721. window.location = curHref;
  722. }
  723. }
  724.  
  725. function getCookie(c_name) {
  726. var c_value = document.cookie;
  727. var c_start = c_value.indexOf(" " + c_name + "=");
  728. if (c_start === -1) {
  729. c_start = c_value.indexOf(c_name + "=");
  730. }
  731. if (c_start === -1) {
  732. c_value = null;
  733. }
  734. else {
  735. c_start = c_value.indexOf("=", c_start) + 1;
  736. var c_end = c_value.indexOf(";", c_start);
  737. if (c_end === -1) {
  738. c_end = c_value.length;
  739. }
  740. c_value = unescape(c_value.substring(c_start, c_end));
  741. }
  742. return c_value;
  743. }
  744.  
  745. var isVisible = (function()
  746. {
  747. var stateKey;
  748. var eventKey;
  749. var keys =
  750. {
  751. hidden: "visibilitychange",
  752. webkitHidden: "webkitvisibilitychange",
  753. mozHidden: "mozvisibilitychange",
  754. msHidden: "msvisibilitychange"
  755. };
  756. for (stateKey in keys)
  757. {
  758. if (stateKey in document)
  759. {
  760. eventKey = keys[stateKey];
  761. break;
  762. }
  763. }
  764. return function(c)
  765. {
  766. if (c)
  767. {
  768. document.addEventListener(eventKey, c);
  769. }
  770. return !document[stateKey];
  771. }
  772. })();
  773.  
  774. function isDstUs(year, month, day, hour)
  775. {
  776. // Support: 2007 - 2029
  777. // Params: 2016, 3, 1, 15 === 1 Mar 2016 15:00
  778. var isDst = false;
  779. try
  780. {
  781. var y = parseInt(year);
  782. var m = parseInt(month);
  783. var d = parseInt(day);
  784. var h = parseInt(hour);
  785. function checkDstUsa(dayMar, dayNov, m, d, h)
  786. {
  787. var isDst = false;
  788. if ((m === 3 && d >= dayMar) || (m > 3 && m < 11) || (m === 11 && d <= dayNov))
  789. isDst = true;
  790. if ((m === 3 && d === dayMar && h < 2) || (m === 11 && d === dayNov && h >= 2))
  791. isDst = false;
  792. return isDst;
  793. }
  794. if (y === 2007 || y === 2012 || y === 2018 || y === 2029)
  795. {
  796. isDst = checkDstUsa(11, 4, m, d, h);
  797. }
  798. else if (y === 2013 || y === 2019 || y === 2024)
  799. {
  800. isDst = checkDstUsa(10, 3, m, d, h);
  801. }
  802. else if (y === 2008 || y === 2014 || y === 2025)
  803. {
  804. isDst = checkDstUsa(9, 2, m, d, h);
  805. }
  806. else if (y === 2009 || y === 2015 || y === 2020 || y === 2026)
  807. {
  808. isDst = checkDstUsa(8, 1, m, d, h);
  809. }
  810. else if (y === 2010 || y === 2021 || y === 2027)
  811. {
  812. isDst = checkDstUsa(14, 7, m, d, h);
  813. }
  814. else if (y === 2011 || y === 2016 || y === 2022)
  815. {
  816. isDst = checkDstUsa(13, 6, m, d, h);
  817. }
  818. else if (y === 2017 || y === 2023 || y === 2028)
  819. {
  820. isDst = checkDstUsa(12, 5, m, d, h);
  821. }
  822. }
  823. catch (ex)
  824. {
  825. console.error("isDstUs", ex.message);
  826. }
  827. return isDst;
  828. }
  829.  
  830. function getDateIsoUs()
  831. {
  832. var dateUs = new Date();
  833. dateUs.setTime(dateUs.getTime() - (1000 * 60 * 60 * 8)); // GMT-8
  834. if (isDstUs(dateUs.getUTCFullYear(), dateUs.getUTCMonth() + 1, dateUs.getUTCDate(), dateUs.getUTCHours()))
  835. {
  836. dateUs.setTime(dateUs.getTime() + (1000 * 60 * 60 * 1)); // GMT-7
  837. }
  838. return dateUs.toISOString();
  839. }
  840.  
  841. function getDateUs()
  842. {
  843. return getDateIsoUs().substr(0, 10);
  844. }
  845.  
  846. function getTimeUs()
  847. {
  848. return getDateIsoUs().substr(11, 5);
  849. }
  850.  
  851. function getTimeMs()
  852. {
  853. return (new Date()).getTime();
  854. }
  855.  
  856. function getUnixTimestamp()
  857. {
  858. return parseInt(getTimeMs() / 1000);
  859. }
  860. var pattUrlTimestamp1 = /\?t=[0-9]{6,}\&/g;
  861. var pattUrlTimestamp2 = /\&t=[0-9]{6,}/g;
  862. var pattUrlTimestamp3 = /\?t=[0-9]{6,}/g;
  863. var pattUrlTimestamp4 = /\&[0-9]{6,}\&/g;
  864.  
  865. function cleanUrlTimestamp(eles)
  866. {
  867. if (!eles || !eles.length)
  868. return;
  869.  
  870. for (var i = 0; i < eles.length; i++)
  871. {
  872. var val = "";
  873. var attr = "";
  874. if (eles[i].tagName === "A")
  875. {
  876. attr = "href";
  877. }
  878. else if (eles[i].tagName === "FORM")
  879. {
  880. attr = "action";
  881. }
  882. else if (eles[i].tagName === "DIV" || eles[i].tagName === "INPUT")
  883. {
  884. attr = "onclick";
  885. }
  886. var isEdit = false;
  887. val = eles[i].getAttribute(attr);
  888. if (pattUrlTimestamp1.test(val))
  889. {
  890. eles[i].setAttribute(attr, val.replace(pattUrlTimestamp1,"?"));
  891. isEdit = true;
  892. }
  893. else if (pattUrlTimestamp2.test(val))
  894. {
  895. eles[i].setAttribute(attr, val.replace(pattUrlTimestamp2,""));
  896. isEdit = true;
  897. }
  898. else if (pattUrlTimestamp3.test(val))
  899. {
  900. eles[i].setAttribute(attr, val.replace(pattUrlTimestamp3,""));
  901. isEdit = true;
  902. }
  903. if (isEdit)
  904. {
  905. val = eles[i].getAttribute(attr);
  906. }
  907. if (pattUrlTimestamp4.test(val))
  908. {
  909. eles[i].setAttribute(attr, val.replace(pattUrlTimestamp4,"&"));
  910. }
  911. }
  912. }
  913.  
  914. var timeoutList = new Array();
  915. var intervalList = new Array();
  916.  
  917. function setTimeoutCustom(func, tm, params)
  918. {
  919. var id = setTimeout(func, tm, params);
  920. timeoutList.push(id);
  921. return id;
  922. }
  923.  
  924. function clearTimeoutAll()
  925. {
  926. for (var i = 0; i < timeoutList.length; i++)
  927. {
  928. clearTimeout(timeoutList[i]);
  929. }
  930. }
  931.  
  932. function setIntervalCustom(func, tm, params)
  933. {
  934. var id = setInterval(func, tm, params);
  935. intervalList.push(id);
  936. return id;
  937. }
  938.  
  939. function clearIntervalAll()
  940. {
  941. for (var i = 0; i < intervalList.length; i++)
  942. {
  943. clearInterval(intervalList[i]);
  944. }
  945. }
  946.  
  947. function main()
  948. {
  949. var url = document.documentURI;
  950. var lang = getCookie("Language");
  951. document.body.classList.add("stsh");
  952. // Auto refresh when error
  953. {
  954. var h1 = document.querySelector("#leftAreaContainer > h1, body > h1");
  955. if (h1)
  956. {
  957. var text = h1.textContent.trim();
  958. if (text === "Steam Translation Server - Maintenance Warning"
  959. || text === "Forbidden")
  960. {
  961. console.log("stsh: refresh");
  962. setTimeoutCustom(reload, 60000);
  963. return;
  964. }
  965. }
  966. }
  967.  
  968. // Clean links
  969. {
  970. setTimeoutCustom(function()
  971. {
  972. var eles = document.querySelectorAll("a, form[action], input");
  973. cleanUrlTimestamp(eles);
  974. }, 100);
  975. }
  976.  
  977. var eleLogout = document.querySelector("#logout");
  978. if (eleLogout)
  979. {
  980. var logoutHtml =
  981. ' \
  982. <a class="stsh_a_button" target="_blank" href="/user_activity.php">My Profile</a> \
  983. <input name="login_button" value="Logout?" type="submit" onclick="return confirm(\'Logout?\');" /> \
  984. ';
  985. eleLogout.innerHTML = logoutHtml;
  986. // Special event button
  987. {
  988. if (isRally())
  989. {
  990. var divSpecial = document.createElement("div");
  991. divSpecial.id = "stsh_specialEvent";
  992. divSpecial.innerHTML =
  993. ' \
  994. <a class="stsh_a_button" target="_blank" href="/rally.php">Year-End Rally</a> \
  995. ';
  996. eleLogout.parentElement.appendChild(divSpecial);
  997. }
  998. }
  999. }
  1000. if (url.indexOf("Us_And_Them.php") > -1)
  1001. {
  1002. var container = "\"";
  1003. var tdEng = document.querySelector(
  1004. "#leftAreaContainer > table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)");
  1005. if (tdEng)
  1006. {
  1007. tdEng.innerHTML = container + tdEng.innerHTML + container;
  1008. }
  1009. var h1 = document.querySelector("#leftAreaContainer > h1:nth-child(2)");
  1010. if (h1)
  1011. {
  1012. var header = h1.textContent.trim();
  1013. var key = header.split(" ")[0];
  1014. h1.innerHTML = header.replace(key, "<a href='/translate.php?keyonly=1&search_input="
  1015. + encodeURIComponent(key) + "' >" + key + "</a>");
  1016. document.title = key + " - " + document.title;
  1017. }
  1018. // Hilight cur lang
  1019. {
  1020. //var first = document.querySelector("#leftAreaContainer tr:nth-child(1) > td:nth-child(1) > a");
  1021. //if (first)
  1022. {
  1023. var cur = null;
  1024. var elesLang = document.querySelectorAll("#leftAreaContainer tr > td:nth-child(1) > a");
  1025. for (var i = 1; i < elesLang.length; i++)
  1026. {
  1027. if (lang === elesLang[i].textContent.trim().toLowerCase())
  1028. {
  1029. cur = elesLang[i].parentElement.parentElement;
  1030. break;
  1031. }
  1032. }
  1033. if (cur)
  1034. {
  1035. cur.classList.add("stsh_usThem_curLang");
  1036. //insertAfterElement(cur, first.parentElement.parentElement);
  1037. }
  1038. }
  1039. }
  1040. } // End Us_And_Them.php
  1041.  
  1042. if (url.indexOf("suggestions.php") > -1)
  1043. {
  1044. var eleTextOrg = document.querySelector(".progress > tbody > tr:last-child > td:nth-child(1)");
  1045. if (eleTextOrg)
  1046. {
  1047. eleTextOrg.classList.add("stsh_text_org");
  1048. }
  1049. var eleTextTrn = document.querySelector(".progress > tbody > tr:last-child > td:nth-child(3)");
  1050. if (eleTextTrn)
  1051. {
  1052. eleTextTrn.classList.add("stsh_text_trn");
  1053. if (eleTextTrn.textContent.trim() === "")
  1054. {
  1055. eleTextTrn.classList.add("stsh_text_trn_empty");
  1056. }
  1057. }
  1058. var eleTextSubmit = document.querySelector(".lbAction[name='suggestion_temp'] input[accesskey='s']");
  1059. if (eleTextSubmit)
  1060. {
  1061. eleTextSubmit.classList.add("stsh_text_submit");
  1062. }
  1063. var elesTextRemoveComment = document.querySelectorAll(".suggestion_signature .lbAction[name^='mymodcomment'] a");
  1064. for (var i = 0; i < elesTextRemoveComment.length; i++)
  1065. {
  1066. elesTextRemoveComment[i].removeAttribute("href");
  1067. elesTextRemoveComment[i].classList.add("stsh_text_removeComment");
  1068. }
  1069. var elesTextComment = document.querySelectorAll("textarea[name='suggestion_comment']");
  1070. for (var i = 0; i < elesTextComment.length; i++)
  1071. {
  1072. elesTextComment[i].nextElementSibling.classList.add("stsh_submit_comment");
  1073. elesTextComment[i].classList.add("stsh_text_addComment");
  1074. }
  1075. var eleTextNew = document.querySelector("#suggestion_value_new");
  1076. if (eleTextNew)
  1077. {
  1078. eleTextNew.style.width = "960px";
  1079. eleTextNew.style.height = "64px";
  1080. eleTextNew.style.marginLeft = "3px";
  1081. }
  1082. var inputClose = document.querySelector("#suggestions_nav > input[value^='Close']");
  1083. if (inputClose)
  1084. {
  1085. inputClose.value = "Close (Esc)";
  1086. }
  1087. // Normalize
  1088. {
  1089. var elesApprove = document.querySelectorAll(".suggestion_signature input[value~='APPROVE']");
  1090. for (var i = 0; i < elesApprove.length; i++)
  1091. {
  1092. elesApprove[i].classList.add("stsh_action_approve");
  1093. }
  1094. var elesDecline = document.querySelectorAll(".suggestion_signature input[value~='DECLINE']");
  1095. for (var i = 0; i < elesDecline.length; i++)
  1096. {
  1097. elesDecline[i].classList.add("stsh_action_decline");
  1098. }
  1099. var elesNext = document.querySelectorAll(".suggestion_signature input[value~='Next']");
  1100. for (var i = 0; i < elesNext.length; i++)
  1101. {
  1102. elesNext[i].value = "Next";
  1103. var elePrev = elesNext[i].previousElementSibling;
  1104. if (elePrev)
  1105. {
  1106. if (elePrev.classList.contains("stsh_action_approve"))
  1107. {
  1108. elesNext[i].classList.add("stsh_action_approve_next");
  1109. }
  1110. else if (elePrev.classList.contains("stsh_action_decline"))
  1111. {
  1112. elesNext[i].classList.add("stsh_action_decline_next");
  1113. }
  1114. }
  1115. }
  1116. var elesRemove = document.querySelectorAll(".suggestion_signature input[value='REMOVE']");
  1117. for (var i = 0; i < elesRemove.length; i++)
  1118. {
  1119. elesRemove[i].classList.add("stsh_action_remove");
  1120. elesRemove[i].classList.add("stsh_yellow_light");
  1121. }
  1122. var elesEdit = document.querySelectorAll("input[value='Edit']");
  1123. for (var i = 0; i < elesEdit.length; i++)
  1124. {
  1125. elesEdit[i].classList.add("stsh_action_edit");
  1126. elesEdit[i].classList.add("stsh_blue_light");
  1127. }
  1128. }
  1129. // Move region
  1130. {
  1131. var td = eleTextTrn;
  1132. if (td.classList.contains("stsh_text_trn_empty"))
  1133. {
  1134. function moveSuggestionBox()
  1135. {
  1136. var td = document.querySelector(".stsh_text_trn.stsh_text_trn_empty");
  1137. if (td)
  1138. {
  1139. td.innerHTML = "";
  1140. var eleTarget = document.querySelector("#suggestionmain > div:nth-child(4) > .lbAction");
  1141. if (eleTarget)
  1142. {
  1143. td.appendChild(eleTarget);
  1144. td.style.padding = "0px";
  1145. var textarea = document.querySelector("#suggestion_value_new");
  1146. if (textarea)
  1147. {
  1148. textarea.style.width = "98%";
  1149. textarea.style.marginLeft = "0px";
  1150. if (textarea.scrollHeight < 500)
  1151. {
  1152. textarea.style.height = (textarea.scrollHeight + 20) + "px";
  1153. }
  1154. else
  1155. {
  1156. textarea.style.height = "500px";
  1157. }
  1158. textarea.focus();
  1159. }
  1160. var eleTextOrg = document.querySelector(".stsh_text_org");
  1161. if (eleTextOrg)
  1162. {
  1163. eleTextOrg.style.display = "table-cell";
  1164. eleTextOrg.style.paddingTop = "6px";
  1165. }
  1166. }
  1167. }
  1168. }
  1169. function moveSuggestionList()
  1170. {
  1171. var td = document.querySelector(".stsh_text_trn.stsh_text_trn_empty");
  1172. if (td && td.textContent.trim() === "")
  1173. {
  1174. td.innerHTML = "";
  1175. var eleTarget = document.querySelector(".suggestion");
  1176. if (eleTarget)
  1177. {
  1178. td.appendChild(eleTarget);
  1179. td.style.padding = "0px";
  1180. eleTarget.style.marginTop = "-2px";
  1181. eleTarget.style.paddingTop = "0px";
  1182. eleTarget.style.borderBottomWidth = "0px";
  1183. eleTarget.style.borderRightWidth = "0px";
  1184. eleTarget.style.resize = "none";
  1185. var eleAutoApprove = document.querySelector("#stsh_autoApprove");
  1186. if (eleAutoApprove)
  1187. {
  1188. eleAutoApprove.classList.add("stsh_hidden");
  1189. }
  1190. var eleAutoApproveLabel = document.querySelector(".stsh_autoApprove_label");
  1191. if (eleAutoApproveLabel)
  1192. {
  1193. eleAutoApproveLabel.classList.add("stsh_hidden");
  1194. }
  1195. }
  1196. }
  1197. }
  1198. var eleDiv = document.createElement("div");
  1199. eleDiv.classList.add("stsh_moveSuggestionContainer");
  1200. td.appendChild(eleDiv);
  1201. var eleMoveBox = document.createElement("input");
  1202. eleMoveBox.id = "stsh_moveSuggestionBox";
  1203. eleMoveBox.setAttribute("value", "Move Box Here");
  1204. eleMoveBox.setAttribute("type", "button");
  1205. eleDiv.appendChild(eleMoveBox);
  1206. eleMoveBox.addEventListener("click", function(e)
  1207. {
  1208. moveSuggestionBox();
  1209. });
  1210. if (document.querySelector(".suggestion"))
  1211. {
  1212. var eleMoveList = document.createElement("input");
  1213. eleMoveList.id = "stsh_moveSuggestionList";
  1214. eleMoveList.setAttribute("value", "Move Suggestion Here");
  1215. eleMoveList.setAttribute("type", "button");
  1216. eleDiv.appendChild(eleMoveList);
  1217. eleMoveList.addEventListener("click", function(e)
  1218. {
  1219. moveSuggestionList();
  1220. });
  1221. }
  1222. }
  1223. }
  1224. // Resize suggestion textarea
  1225. if (eleTextNew)
  1226. {
  1227. var resizeTextNew = function(eleTextNew)
  1228. {
  1229. eleTextNew.focus();
  1230. if (eleTextNew.scrollHeight < 500)
  1231. {
  1232. eleTextNew.style.height = (eleTextNew.scrollHeight + 20) + "px";
  1233. }
  1234. else
  1235. {
  1236. eleTextNew.style.height = "500px";
  1237. }
  1238. if (eleTextNew.scrollHeight > 200 && document.querySelector(".suggestion"))
  1239. {
  1240. eleTextNew.scrollIntoView();
  1241. }
  1242. };
  1243. if (isVisible())
  1244. {
  1245. resizeTextNew(eleTextNew);
  1246. }
  1247. else
  1248. {
  1249. // Fix size error when inactive
  1250. setTimeoutCustom(resizeTextNew, 100, eleTextNew);
  1251. }
  1252. }
  1253. var br = document.querySelector("form.lbAction:nth-child(2) > div:nth-child(2) > br:nth-child(1)");
  1254. if (br)
  1255. {
  1256. br.parentElement.removeChild(br);
  1257. }
  1258. var key = "";
  1259. var divNav = document.querySelector("div#suggestions_nav");
  1260. if (!divNav)
  1261. {
  1262. // Add when error occured
  1263. divNav = document.createElement("div");
  1264. divNav.id = "suggestions_nav";
  1265. document.body.appendChild(divNav);
  1266. }
  1267. if (divNav)
  1268. {
  1269. var insert = "";
  1270. var insertSearch = "";
  1271. var insertView = "";
  1272. var spliter = "_";
  1273. var regApp = /[0-9]{4,}/;
  1274. var aKey = document.querySelector(".smallcopy > font:nth-child(2) > a:nth-child(1)");
  1275. if (aKey)
  1276. {
  1277. key = encodeURIComponent(aKey.textContent.trim());
  1278. if (key === "token-key")
  1279. {
  1280. aKey = document.querySelector(".smallcopy > a:nth-child(3)");
  1281. if (aKey)
  1282. {
  1283. key = encodeURIComponent(aKey.textContent.trim());
  1284. }
  1285. }
  1286. if (key !== "")
  1287. {
  1288. document.title = key + " - " + document.title;
  1289. if (key.split(spliter).length > 1)
  1290. {
  1291. if (key.indexOf("%23") === 0)
  1292. {
  1293. var firstSpliter = key.indexOf(spliter);
  1294. var keySharp = key.substring(0, firstSpliter);
  1295. insertSearch += '<a class="stsh_a_button" target="_blank" '
  1296. + ' href="/translate.php?keyonly=1&paginationrows=1000&search_input='
  1297. + keySharp + '">Hashtag</a>';
  1298. }
  1299. var lastSpliter = key.lastIndexOf(spliter);
  1300. var keyGroup = key.substring(0, lastSpliter);
  1301. insertSearch += '<a class="stsh_a_button" target="_blank" '
  1302. + ' href="/translate.php?keyonly=1&paginationrows=1000&search_input='
  1303. + keyGroup + '">Group</a>';
  1304. }
  1305. insertSearch += '<a class="stsh_a_button" target="_blank" '
  1306. + ' href="/translate.php?keyonly=1&search_input='
  1307. + key + '">Key</a>';
  1308. }
  1309. }
  1310. var tdText = eleTextOrg;
  1311. if (tdText)
  1312. {
  1313. var text = encodeURIComponent(tdText.textContent.trim())
  1314. .replace(/(%20|%09)/g,"+")
  1315. .replace(/'/g,"\\'")
  1316. .replace("%0A", "+")
  1317. .replace(/\++/g, "+")
  1318. .substr(0, 80);
  1319. if (text.length >= 80)
  1320. {
  1321. text = text.substr(0, text.lastIndexOf("+"));
  1322. }
  1323. if (text.indexOf(".") > 20)
  1324. {
  1325. text = text.substr(0, text.indexOf(".") + 1);
  1326. }
  1327. if (text.indexOf("%5C") > 10)
  1328. {
  1329. text = text.substr(0, text.indexOf("%5C"));
  1330. }
  1331. var eleSubmit = document.querySelector(".stsh_text_submit");
  1332. if (eleSubmit)
  1333. {
  1334. var elePrev = eleSubmit.previousElementSibling;
  1335. if (!elePrev || elePrev.tagName !== "BR")
  1336. {
  1337. var eleNew = document.createElement("br");
  1338. insertBeforeElement(eleNew, eleSubmit);
  1339. }
  1340. }
  1341. if (text !== "")
  1342. {
  1343. insertSearch += '<a class="stsh_a_button" target="_blank" '
  1344. + ' href="/translate.php?keyonly=2&paginationrows=1000&search_input='
  1345. + text + '">String</a>';
  1346. var eleSubmitNext = document.querySelector(".lbAction input[type='submit'][accesskey='a']");
  1347. if (eleSubmitNext)
  1348. {
  1349. eleSubmitNext.value = "Next";
  1350. eleSubmitNext.classList.add("stsh_submit_suggestion_right");
  1351. var eleForm = eleSubmitNext.parentElement.parentElement;
  1352. if (eleForm.tagName === "FORM")
  1353. {
  1354. addKeyCtrlShiftEnter(eleForm, eleSubmitNext);
  1355. }
  1356. }
  1357. else
  1358. {
  1359. if (eleSubmit)
  1360. {
  1361. eleSubmitNext = document.createElement("input");
  1362. eleSubmitNext.id = "stsh_submit_suggestion_next";
  1363. eleSubmitNext.classList.add("stsh_submit_suggestion_right");
  1364. eleSubmitNext.setAttribute("type", "submit");
  1365. eleSubmitNext.setAttribute("value", "Next");
  1366. eleSubmitNext.setAttribute("name", "submitandnext");
  1367. insertAfterElement(eleSubmitNext, eleSubmit);
  1368. eleSubmitNext.addEventListener("click", function(ev)
  1369. {
  1370. var textOrg = "";
  1371. var textTrn = "";
  1372. var textCur = "";
  1373. var eleTextOrg = document.querySelector(".stsh_text_org");
  1374. if (eleTextOrg)
  1375. {
  1376. textOrg = trimSpace(eleTextOrg.textContent);
  1377. }
  1378. var eleTextTrn = document.querySelector(".stsh_text_trn:not(.stsh_text_trn_empty)");
  1379. if (eleTextTrn)
  1380. {
  1381. textTrn = trimSpace(eleTextTrn.textContent);
  1382. }
  1383. var eleTextCur = document.querySelector("#suggestion_value_new");
  1384. if (eleTextCur)
  1385. {
  1386. textCur = trimSpace(eleTextCur.value);
  1387. }
  1388. if (textCur === "" || textOrg === textCur || textTrn === textCur)
  1389. {
  1390. ev.preventDefault();
  1391. var eleSubmit = document.querySelector(".stsh_text_submit");
  1392. if (eleSubmit)
  1393. {
  1394. eleSubmit.click();
  1395. }
  1396. }
  1397. });
  1398. var eleForm = eleSubmit.parentElement.parentElement;
  1399. if (eleForm.tagName === "FORM")
  1400. {
  1401. addKeyCtrlShiftEnter(eleForm, eleSubmitNext);
  1402. }
  1403. }
  1404. }
  1405. if (eleSubmitNext)
  1406. {
  1407. var canNext = !!(document.querySelector(".stsh_nav_next:not(:disabled)"));
  1408. if (!canNext)
  1409. {
  1410. // Display as disabled
  1411. eleSubmitNext.classList.add("stsh_grey");
  1412. eleSubmitNext.classList.add("stsh_cursor_default");
  1413. }
  1414. }
  1415. }
  1416. else
  1417. {
  1418. if (eleTextNew && eleSubmit)
  1419. {
  1420. var eleNew = document.createElement("input");
  1421. eleNew.id = "stsh_submit_suggestion_space";
  1422. eleNew.classList.add("stsh_submit_suggestion_right");
  1423. eleNew.setAttribute("type", "button");
  1424. eleNew.setAttribute("value", "Submit Empty (2 Newlines)");
  1425. insertAfterElement(eleNew, eleSubmit);
  1426. eleNew.addEventListener("click", function(ev)
  1427. {
  1428. var eleTextNew = document.querySelector("#suggestion_value_new");
  1429. if (eleTextNew)
  1430. {
  1431. //eleTextNew.value = String.fromCharCode(160);
  1432. eleTextNew.value = "\n\n";
  1433. eleTextNew.focus();
  1434. ev.preventDefault();
  1435. var eleSubmit = document.querySelector(".stsh_text_submit");
  1436. if (eleSubmit)
  1437. {
  1438. eleSubmit.click();
  1439. }
  1440. }
  1441. });
  1442. }
  1443. }
  1444. }
  1445. var app = regApp.exec(key.replace("%23", ""));
  1446. if (app && key.indexOf("faq") < 0 && key.indexOf("glossary") < 0)
  1447. {
  1448. if (key.indexOf("SharedFiles_App_") === 0)
  1449. {
  1450. insertView += '<a class="stsh_a_button" target="_blank" '
  1451. + ' href="http://steamcommunity.com/workshop/browse?appid='
  1452. + app + '">Workshop</a>';
  1453. }
  1454. insertView += '<a class="stsh_a_button" target="_blank" '
  1455. + ' href="http://steamcommunity.com/app/'
  1456. + app + '">Community</a>'
  1457. insertView += '<a class="stsh_a_button" target="_blank" '
  1458. + ' href="http://store.steampowered.com/app/'
  1459. + app + '">App</a>';
  1460. }
  1461. if (insertSearch)
  1462. {
  1463. insert += ' <br/> &nbsp; Search: <div class="stsh_nav_group"> ' + insertSearch + " </div>";
  1464. }
  1465. if (insertView)
  1466. {
  1467. insert += ' <br/> &nbsp; View: <div class="stsh_nav_group"> ' + insertView + " </div>";
  1468. }
  1469. var insertBefore =
  1470. ' \
  1471. <input id="stsh_refresh" value="Refresh" onclick="return false;" type="button"> \
  1472. <a class="stsh_a_button" target="_blank" href="' + url + '">Frame</a> \
  1473. ';
  1474. var innerNew = divNav.innerHTML
  1475. .replace('<input value="Previous', '&nbsp;&nbsp;<input value="Prev')
  1476. .replace('<input value="Close', '&nbsp;&nbsp;<input value="Close');
  1477. divNav.innerHTML = insertBefore + innerNew + insert + " <br/> ";
  1478. var eleRefresh = document.querySelector("#stsh_refresh");
  1479. if (eleRefresh)
  1480. {
  1481. eleRefresh.addEventListener("click", function()
  1482. {
  1483. reload();
  1484. });
  1485. }
  1486. }
  1487. // Regroup glossary and auto replace matched string
  1488. {
  1489. setTimeoutCustom(function()
  1490. {
  1491. var br = "<br>";
  1492. var brSpace = " <br> ";
  1493. var tag = "<a";
  1494. var colon = ">: ";
  1495. var comma = ",";
  1496. var bracket = " (";
  1497. var isEdit = false;
  1498. var p = null;
  1499. var aGls = document.querySelectorAll("a[href='glossary.php']");
  1500. for (var i = 0; i < aGls.length; i++)
  1501. {
  1502. if (aGls[i].textContent.trim() === "GLOSSARY FEATURE")
  1503. {
  1504. p = aGls[i].parentElement;
  1505. break;
  1506. }
  1507. }
  1508. if (p)
  1509. {
  1510. var glosOuters = [];
  1511. var glosInnerStart = 0;
  1512. var countGl = 0;
  1513. var glossaries = p.innerHTML.split(br);
  1514. if (glossaries.length > 2)
  1515. {
  1516. glosOuters = [p];
  1517. glosInnerStart = 2;
  1518. }
  1519. else
  1520. {
  1521. glosOuters = p.nextSibling.querySelectorAll("td");
  1522. glosInnerStart = 0;
  1523. }
  1524. var rgxKey = />[^><]+</;
  1525. var rgxKeyClean = /[><]+/g;
  1526. var rgxKeyPunct = /[\(\)\[\]\:\!]/g;
  1527. var rgxContentClean = /<[^<]*>/g;
  1528. var textOrg = "";
  1529. var textEng = "";
  1530. var isTextReplaced = false;
  1531. var isOutdated = false;
  1532.  
  1533. var eleBtnResummit = document.querySelector("input[type='submit'][value^='RESUBMIT']");
  1534. if (eleBtnResummit)
  1535. {
  1536. isTextReplaced = true;
  1537. }
  1538. else
  1539. {
  1540. var eleTextOrg = document.querySelector("#suggestion_value_new");
  1541. if (eleTextOrg)
  1542. {
  1543. textOrg = eleTextOrg.value.trim().toLowerCase();
  1544. }
  1545. if (textOrg === "" || textOrg.length > 300)
  1546. {
  1547. // Not replace on empty and long strings
  1548. isTextReplaced = true;
  1549. }
  1550. }
  1551. if (!isTextReplaced)
  1552. {
  1553. var eleTrs = document.querySelectorAll(".progress tr");
  1554. isOutdated = (eleTrs.length >= 3);
  1555. if (isOutdated)
  1556. {
  1557. textEng = eleTrs[eleTrs.length - 1].firstElementChild.textContent.trim().toLowerCase();
  1558. }
  1559. }
  1560. for (var i = 0; i < glosOuters.length; i++)
  1561. {
  1562. var glosOuter = glosOuters[i];
  1563. var glosInners = glosOuter.innerHTML.split(br);
  1564. isEdit = false;
  1565. for (var j = glosInnerStart; j < glosInners.length; j++)
  1566. {
  1567. var glossary = glosInners[j].trim();
  1568. if (glossary.length > 0 && glossary.indexOf(tag) === 0)
  1569. {
  1570. var colonIndex = glossary.indexOf(colon);
  1571. var contentHead = glossary.substr(0, colonIndex + 3);
  1572. var contentAll = glossary.substr(colonIndex + 3);
  1573. var contentWords = contentAll.split(comma);
  1574. var contentFirst = contentWords[0].trim();
  1575. for (var k = 0; k < contentWords.length; k++)
  1576. {
  1577. var contentNew = contentWords[k].trim();
  1578. var contentSub = null;
  1579. var bracketPos = contentNew.indexOf(" (");
  1580. if (bracketPos > -1)
  1581. {
  1582. contentSub = contentNew.substr(bracketPos);
  1583. contentNew = contentNew.substr(0, bracketPos);
  1584. }
  1585. contentNew = " <span id='stsh_gls_" + countGl
  1586. + "' onclick='clickToSelect(this)'>"
  1587. + contentNew + "</span>";
  1588. //+ "<span style='color: white; cursor: pointer;'>^</span>";
  1589. if (contentSub)
  1590. {
  1591. contentNew += "<span "
  1592. + "onclick='clickToSelect(this.previousElementSibling)'>"
  1593. + contentSub + "</span>";
  1594. }
  1595. contentWords[k] = contentNew;
  1596. countGl++;
  1597. }
  1598. if (!isTextReplaced)
  1599. {
  1600. var keys = contentHead.match(rgxKey);
  1601. if (keys && keys.length > 0)
  1602. {
  1603. var key = keys[0].replace(rgxKeyClean, "").trim().toLowerCase();
  1604. var contentClean = contentFirst.replace(rgxContentClean, "");
  1605. var contentLower = contentClean.toLowerCase();
  1606. var textCur = "";
  1607. if (key === textOrg.replace(rgxKeyPunct, ""))
  1608. {
  1609. textCur = textOrg;
  1610. }
  1611. else if (key === textEng.replace(rgxKeyPunct, ""))
  1612. {
  1613. textCur = textEng;
  1614. }
  1615. if (textCur !== "" && key !== contentLower)
  1616. {
  1617. var rgxReplace = new RegExp(key, "i");
  1618. eleTextOrg.value = textCur.replace(rgxReplace, contentClean);
  1619. //console.log("Replaced: " + eleTextOrg.value);
  1620. isTextReplaced = true;
  1621. }
  1622. }
  1623. }
  1624. glosInners[j] = contentHead + contentWords.join(comma);
  1625. isEdit = true;
  1626. }
  1627. }
  1628. if (isEdit && false)
  1629. {
  1630. // old feature
  1631. glosOuter.innerHTML = glosInners.join(brSpace);
  1632. }
  1633. }
  1634. }
  1635. }, 200);
  1636. }
  1637. // Insert clicked word in last textarea
  1638. {
  1639. var eleTextLast = null;
  1640. if (document.activeElement && document.activeElement.tagName === "TEXTAREA")
  1641. {
  1642. eleTextLast = document.activeElement;
  1643. }
  1644. var elesText = document.querySelectorAll
  1645. (" \
  1646. #suggestion_value_new \
  1647. , .stsh_text_addComment \
  1648. , #add_to_discussion \
  1649. , textarea[name^='autoreplace'] \
  1650. ");
  1651. for (var i = 0; i < elesText.length; i++)
  1652. {
  1653. elesText[i].addEventListener('focus', function(ev)
  1654. {
  1655. eleTextLast = ev.target;
  1656. });
  1657. }
  1658. setTimeoutCustom(function()
  1659. {
  1660. var elesInsert = document.querySelectorAll(".insertword");
  1661. for (var i = 0; i < elesInsert.length; i++)
  1662. {
  1663. removeAllEventListeners(elesInsert[i]);
  1664. }
  1665. function insertAtCaret(txtarea, text)
  1666. {
  1667. // Edit from STS
  1668. var scrollPos = txtarea.scrollTop;
  1669. var strPos = 0;
  1670. var strLength = 0;
  1671. var br = ((txtarea.selectionStart || txtarea.selectionStart === 0) ? "ff" : (document.selection ? "ie" : false));
  1672. if (br === "ie")
  1673. {
  1674. txtarea.focus();
  1675. var range = document.selection.createRange();
  1676. range.moveStart('character', -txtarea.value.length);
  1677. strPos = range.text.length;
  1678. }
  1679. else if (br === "ff")
  1680. {
  1681. strPos = txtarea.selectionStart;
  1682. strLength = txtarea.selectionEnd - txtarea.selectionStart;
  1683. }
  1684. var front = (txtarea.value).substring(0, strPos);
  1685. var back = (txtarea.value).substring(strPos + strLength, txtarea.value.length);
  1686. txtarea.value = front + text + back;
  1687. strPos = strPos + text.length;
  1688. if (br === "ie")
  1689. {
  1690. txtarea.focus();
  1691. var range = document.selection.createRange();
  1692. range.moveStart('character', -txtarea.value.length);
  1693. range.moveStart('character', strPos);
  1694. range.moveEnd('character', 0);
  1695. range.select();
  1696. }
  1697. else if (br === "ff")
  1698. {
  1699. txtarea.selectionStart = strPos;
  1700. txtarea.selectionEnd = strPos;
  1701. txtarea.focus();
  1702. }
  1703. txtarea.scrollTop = scrollPos;
  1704. }
  1705. elesInsert = document.querySelectorAll(".insertword");
  1706. for (var i = 0; i < elesInsert.length; i++)
  1707. {
  1708. //elesInsert[i].classList.add("stsh_unselectable");
  1709. elesInsert[i].addEventListener("click", function(ev)
  1710. {
  1711. if (eleTextLast)
  1712. {
  1713. insertAtCaret(eleTextLast , ev.target.textContent.trim());
  1714. }
  1715. });
  1716. }
  1717. }, 500);
  1718. }
  1719. // Restyle glossary
  1720. {
  1721. var eleP = null;
  1722. var elesA = document.querySelectorAll("a[href='glossary.php']");
  1723. for (var i = 0; i < elesA.length; i++)
  1724. {
  1725. if (elesA[i].textContent.trim() === "GLOSSARY FEATURE")
  1726. {
  1727. eleP = elesA[i].parentElement;
  1728. break;
  1729. }
  1730. }
  1731. if (eleP)
  1732. {
  1733. var nodeText = eleP.firstElementChild.nextSibling;
  1734. if (nodeText.nodeType === document.TEXT_NODE)
  1735. {
  1736. var ele = document.createElement("span");
  1737. ele.textContent = nodeText.textContent;
  1738. nodeText.parentElement.removeChild(nodeText);
  1739. insertAfterElement(ele, eleP.firstElementChild);
  1740. }
  1741. var eleHead;
  1742. if (eleP.nextElementSibling.tagName === "TABLE")
  1743. {
  1744. eleHead = eleP.nextElementSibling;
  1745. }
  1746. else
  1747. {
  1748. eleHead = eleP;
  1749. }
  1750. eleHead.classList.add("stsh_glossary_header");
  1751. var elesTerm = eleHead.querySelectorAll("a[href*='://translation.steampowered.com/translate.php?search_input=']");
  1752. for (var i = 0; i < elesTerm.length; i++)
  1753. {
  1754. elesTerm[i].classList.add("stsh_glossary_term");
  1755. }
  1756. {
  1757. var eleSpan = null;
  1758. if (eleHead.tagName === "TABLE")
  1759. {
  1760. eleSpan = eleHead.previousElementSibling.querySelector("span");
  1761. }
  1762. else
  1763. {
  1764. eleSpan = eleHead.querySelector("span");
  1765. }
  1766. eleSpan.textContent = eleSpan.textContent
  1767. .replace(" (click to copy to top)", "");
  1768. eleSpan.title = "Click to copy to suggestion or comment";
  1769. eleSpan.classList.add("stsh_cursor_help");
  1770. eleSpan.classList.add("stsh_glossary_help");
  1771. }
  1772. }
  1773. }
  1774. // Restyle same token
  1775. {
  1776. var widthMax = 0;
  1777. var elesFile = document.querySelectorAll(
  1778. "#suggestionmain > div > p > a[href*='/translate.php?keyonly=1&search_input=']");
  1779. for (var i = 0; i < elesFile.length; i++)
  1780. {
  1781. elesFile[i].classList.add("stsh_sametoken_file");
  1782. var width = elesFile[i].offsetWidth;
  1783. if (width > widthMax)
  1784. {
  1785. widthMax = width;
  1786. }
  1787. }
  1788. for (var i = 0; i < elesFile.length; i++)
  1789. {
  1790. elesFile[i].style.minWidth = (widthMax + 4) + "px";
  1791. }
  1792. var eleHeader = null;
  1793. if (elesFile.length > 0)
  1794. {
  1795. eleHeader = elesFile[0].parentElement;
  1796. }
  1797. if (eleHeader)
  1798. {
  1799. eleHeader.classList.add("stsh_sametoken_header");
  1800. eleHeader.innerHTML = eleHeader.innerHTML.replace(
  1801. "&lt;--- currently in view above",
  1802. '<span class="stsh_blue_light stsh_sametoken_current">&lt;--- currently in view above</span>');
  1803. }
  1804. }
  1805. // Auto link http
  1806. // Format comment
  1807. {
  1808. var countSugStatus = document.querySelectorAll(
  1809. ".suggestions_list span[class^='suggestion_status_']").length;
  1810. var rgxUrl = /http[^ "]+/ig;
  1811. var rgxHostUrl = /^https?:\/\/translation\.steampowered\.com\//i;
  1812. var hostReplace = "/";
  1813. var eleComments = document.querySelectorAll
  1814. (" \
  1815. .suggestion_signature > i:nth-child(3) \
  1816. , .suggestion_signature div:nth-child(1) > i:nth-child(4) \
  1817. , .suggestion_signature div:nth-child(1) > i:nth-child(6) \
  1818. , *[class^='row'] > td:nth-child(2) \
  1819. ");
  1820. for (var i = 0; i < eleComments.length; i++)
  1821. {
  1822. var comment = eleComments[i].innerHTML + " ";
  1823. if (comment.indexOf("<a") === -1)
  1824. {
  1825. var commentUrls = comment.match(rgxUrl) || [];
  1826. for (var j = 0; j < commentUrls.length; j++)
  1827. {
  1828. var urlDecode = commentUrls[j];
  1829. try
  1830. {
  1831. urlDecode = decodeURIComponent(commentUrls[j])
  1832. .replace(/#/g, "%23").replace(/&amp;/g, "&");
  1833. //console.log(urlDecode);
  1834. if (countSugStatus === 0 && rgxHostUrl.test(urlDecode))
  1835. {
  1836. var query = getQueryByName("search_input", urlDecode);
  1837. if (query !== "")
  1838. {
  1839. urlDecode = query;
  1840. }
  1841. else
  1842. {
  1843. urlDecode = urlDecode.replace(rgxHostUrl, hostReplace);
  1844. }
  1845. }
  1846. }
  1847. catch (ex)
  1848. {
  1849. console.error("FormatComment", ex.message);
  1850. }
  1851. var commentUrl = commentUrls[j] + " ";
  1852. comment = comment.replace(commentUrl, "<a target='_blank' href='"
  1853. + commentUrls[j] + "' >" + urlDecode + "</a> ");
  1854. }
  1855. }
  1856. comment = comment.trim();
  1857. var commentHead = "";
  1858. if (comment.indexOf("Comment:") === 0)
  1859. {
  1860. eleComments[i].classList.add("stsh_text_comment_header");
  1861. comment = comment
  1862. .replace("Comment:", "Comment: <span class='stsh_text_comment'>")
  1863. + "</span>";
  1864. }
  1865. else
  1866. {
  1867. var indexHead = comment.indexOf(":</font>");
  1868. if (indexHead > -1)
  1869. {
  1870. commentHead = comment.substr(0, indexHead + 8);
  1871. comment = comment.substr(indexHead + 8);
  1872. }
  1873. }
  1874. comment = comment
  1875. .replace(/ \/\/ /g, " <span class='stsh_white stsh_pad'>//</span> ")
  1876. .replace(/\/ /g, "<span class='stsh_white stsh_pad'>/</span> ")
  1877. .replace(/ \//g, " <span class='stsh_white stsh_pad'>/</span>")
  1878. .replace(/\-+\&gt\;/g, "<span class='stsh_white stsh_pad'>$&</span>")
  1879. .replace(/ &gt; /g, " <span class='stsh_white stsh_pad'>&gt;</span> ")
  1880. .replace(/(\-\-)([^\&])/g, "<span class='stsh_white stsh_pad'>--</span>$2")
  1881. .replace(/\, /g, "<span class='stsh_white stsh_pad'>, </span>")
  1882. .replace(/\| /g, "<span class='stsh_white stsh_pad'>| </span>")
  1883. .replace(/\* /g, "<span class='stsh_white stsh_pad'><br>* </span>")
  1884. .replace(/Past application on/g,
  1885. "<span class='stsh_white stsh_pad'><br>Past application on </span>");
  1886. eleComments[i].innerHTML = commentHead + comment;
  1887. var eleAs = eleComments[i].querySelectorAll("a");
  1888. for (var j = 0; j < eleAs.length; j++)
  1889. {
  1890. var href = eleAs[j].getAttribute("href");
  1891. if (href.indexOf("#") > -1)
  1892. {
  1893. eleAs[j].setAttribute("href", href.replace(/\#/g,"%23"));
  1894. }
  1895. }
  1896. //if (comment.indexOf("Comment:") !== 0)
  1897. {
  1898. // Discussion comment
  1899. var rgxImg = /(\.(jpg|png|gif)|\/ugc\/)/i;
  1900. var rgxLongUrl = /^https?\:\/\/translation\.steampowered\.com\/translate\.php\?search_input\=/i;
  1901. var elesA = eleComments[i].querySelectorAll("a");
  1902. for (var j = 0; j < elesA.length; j++)
  1903. {
  1904. var href = elesA[j].getAttribute("href");
  1905. if (rgxImg.test(href))
  1906. {
  1907. if (elesA[j].querySelectorAll("img").length === 0)
  1908. {
  1909. var ele = document.createElement("img");
  1910. ele.classList.add("stsh_comment_img");
  1911. ele.setAttribute("src", href);
  1912. ele.setAttribute("title", href);
  1913. ele.setAttribute("onclick",
  1914. " \
  1915. if (this.style.minWidth !== '850px') \
  1916. { \
  1917. this.style.minWidth = this.naturalWidth < 850 ? this.naturalWidth + 'px' : '850px'; \
  1918. } \
  1919. else \
  1920. { \
  1921. this.style.minWidth = '400px'; \
  1922. } \
  1923. ");
  1924. insertAfterElement(ele, elesA[j]);
  1925. }
  1926. }
  1927. else
  1928. {
  1929. var content = elesA[j].textContent;
  1930. if (rgxLongUrl.test(content))
  1931. {
  1932. //console.log(elesA[j]);
  1933. if (!elesA[j].parentElement.parentElement.parentElement
  1934. .querySelector(".suggestion_signature .lbAction[name^='mymodcomment']"))
  1935. {
  1936. elesA[j].textContent = content.replace(rgxLongUrl, "").replace(/\+/g, " ");
  1937. }
  1938. }
  1939. }
  1940. }
  1941. }
  1942. }
  1943. }
  1944. // Restyle token info
  1945. {
  1946. var divIntro = document.querySelector("#suggestionmain > div.smallcopy");
  1947. if (divIntro)
  1948. {
  1949. var qBranch = getQueryByName("branch");
  1950. var htmlEdit = "You are editing";
  1951. var htmlEditReplace = "";
  1952. var htmlToken = "Token <";
  1953. var htmlTokenReplace = "Token: <";
  1954. var htmlToken2 = "token-key";
  1955. var htmlToken2Replace = "Token";
  1956. var htmlLiveLinkMoved =
  1957. '\
  1958. <font style="color:red;">This FAQ likely does not exist anymore!</font>\
  1959. The generated <a href="https://support.steampowered.com/kb_article.php?ref="\
  1960. target="_blank">live link</a> seems dead or is redirecting.\
  1961. ';
  1962. var htmlLiveLinkMovedReplace =
  1963. '\
  1964. <font class="stsh_red stsh_cursor_help"\
  1965. title="The generated live link seems dead or is redirecting.">\
  1966. This FAQ likely does not exist anymore!</font>\
  1967. ';
  1968. var htmlLiveLinkMovedWithLiveLink =
  1969. '\
  1970. <font style="color:red;">This FAQ likely does not exist anymore!</font> The generated \
  1971. <a href="https://support.steampowered.com/kb_article.php?ref=\
  1972. ';
  1973. var htmlLiveLinkMovedWithLiveLinkReplace =
  1974. '<a href="https://support.steampowered.com/kb_article.php?ref=';
  1975. var htmlLiveLinkMovedWithLiveLink2 =
  1976. '" target="_blank">live link</a> seems dead or is redirecting.';
  1977. var htmlLiveLinkMovedWithLiveLink2Replace =
  1978. '\
  1979. " target="_blank">Live link</a> - \
  1980. <font class="stsh_red stsh_cursor_help"\
  1981. title="The generated live link seems dead or is redirecting.">\
  1982. This FAQ likely does not exist anymore!</font>';
  1983. var htmlLiveLink = 'target="_blank">Live link';
  1984. var htmlLiveLinkReplace = 'target="_blank">Live link'; // Change in condition
  1985. var htmlFile = " of <";
  1986. var htmlFileReplace =
  1987. ' <br>File: <font class="stsh_info_file stsh_blue" onclick="clickToSelect(this)">' + qBranch + '</font> >> <';
  1988. var htmlFrom = "<br>Added on <";
  1989. var htmlFromReplace = " &nbsp;&nbsp;Added: <";
  1990. var htmlUpdated = ">. Updated on <";
  1991. var htmlUpdatedReplace = "> &nbsp;&nbsp;Updated: <";
  1992. var htmlUpdated2 = "<br> Updated on <";
  1993. var htmlUpdated2Replace = " &nbsp;&nbsp;Updated: <";
  1994. var htmlSugg = 'You have <font style="';
  1995. var htmlSuggReplace =
  1996. 'You have <font title="Enter and submit new suggestions below. Do not alter HTML tags or variables." class="stsh_cursor_help" style="';
  1997. var htmlIntro =
  1998. "Enter and submit new suggestions below. Do not alter HTML tags or variables.";
  1999. var htmlIntroReplace =
  2000. ' \
  2001. &nbsp;&nbsp;\
  2002. <a href="mailto:translationserver@valvesoftware.com" \
  2003. title="Please report token issues by posting a TOKEN DISCUSSION \r\nor email to translationserver@valvesoftware.com" \
  2004. class="stsh_cursor_help">\
  2005. <font class="stsh_white">Report Tokens</font></a>\
  2006. ';
  2007. var htmlContact =
  2008. '\
  2009. <br>Please report token issues by posting a <font style="color:#a4b23c;">TOKEN DISCUSSION</font> tagged\
  2010. <input style="border:none; color:#FFFFFF; background-color:#111111; cursor:pointer;"\
  2011. onclick="tosts(\'truncated\')" value="[sts_admin][truncated]" type="button">or\
  2012. <input style="border:none; color:#FFFFFF; background-color:#111111; cursor:pointer;"\
  2013. onclick="tosts(\'typo\');" value="[sts_admin][typo]" type="button">or\
  2014. <input style="border:none; color:#FFFFFF; background-color:#111111; cursor:pointer;"\
  2015. onclick="tosts(\'unlockpls\')" value="[sts_admin][unlockpls]" type="button">or by \
  2016. <a href="mailto:translationserver@valvesoftware.com">email</a>.\
  2017. ';
  2018. var htmlContactReplace = '';
  2019. var htmlContact2 =
  2020. '\
  2021. <br>Please report token issues by posting a <font style="color:#a4b23c;">TOKEN DISCUSSION</font> tagged\
  2022. <input style="border:none; color:#FFFFFF; background-color:#111111; cursor:pointer;" type="button"\
  2023. onclick="tosts(\'truncated\')" value="[sts_admin][truncated]">or\
  2024. <input style="border:none; color:#FFFFFF; background-color:#111111; cursor:pointer;" type="button"\
  2025. onclick="tosts(\'typo\');" value="[sts_admin][typo]">or\
  2026. <input style="border:none; color:#FFFFFF; background-color:#111111; cursor:pointer;" type="button"\
  2027. onclick="tosts(\'unlockpls\')" value="[sts_admin][unlockpls]">or by \
  2028. <a href="mailto:translationserver@valvesoftware.com">email</a>.\
  2029. ';
  2030. var htmlContact2Replace = '';
  2031. var rgxTestEmail =
  2032. /<br><font style="color:#a4b23c;">This is part of email message .+ - you can test it by following this link:<\/font> /i;
  2033. var htmlTestEmailReplace = '';
  2034. var rgxTestEmail2 =
  2035. /<a href="test_email\.php\?filename=.+\&amp;lang=[a-z]+" target="_blank">Test<\/a>/i;
  2036. var htmlTestEmail2Replace = '';
  2037. var htmlsTestEmail = rgxTestEmail.exec(divIntro.innerHTML);
  2038. if (htmlsTestEmail)
  2039. {
  2040. var htmlTestEmail = htmlsTestEmail[0]
  2041. .replace('<br><font style="color:#a4b23c;">This is part of email message ', "")
  2042. .replace(' - you can test it by following this link:</font> ', "");
  2043. var htmlTestEmail2 = "";
  2044. var htmlsTestEmail2 = rgxTestEmail2.exec(divIntro.innerHTML);
  2045. if (htmlsTestEmail2)
  2046. {
  2047. htmlTestEmail2 = htmlsTestEmail2[0].replace('<a href="', "")
  2048. .replace('" target="_blank">Test</a>', "");
  2049. }
  2050. htmlIntroReplace += ' &nbsp;&nbsp;Test: <a href="' + htmlTestEmail2
  2051. + '" title="You can test email by following this link." target="_blank">'
  2052. + htmlTestEmail + '</a>';
  2053. }
  2054. if (key !== "")
  2055. {
  2056. htmlIntroReplace +=
  2057. ' \
  2058. <br>Share: \
  2059. <font class="stsh_token_share stsh_green stsh_truncate" onclick="clickToSelect(this)">\
  2060. https://translation.steampowered.com/translate.php?search_input=' + key + '\
  2061. </font> <br>\
  2062. ';
  2063. }
  2064. var urlLiveLink = "https://support.steampowered.com/kb_article.php?ref=";
  2065. var eleLiveLink = divIntro.querySelector("a[href^='" + urlLiveLink + "']");
  2066. if (eleLiveLink)
  2067. {
  2068. htmlLiveLinkReplace = 'target="_blank" title="Live link">'
  2069. + eleLiveLink.getAttribute("href").replace(urlLiveLink, "");
  2070. }
  2071. var isComplete = (divIntro.innerHTML.indexOf(htmlContact) > -1);
  2072. divIntro.innerHTML = divIntro.innerHTML
  2073. .replace(htmlEdit, htmlEditReplace)
  2074. .replace(htmlToken, htmlTokenReplace)
  2075. .replace(htmlToken2, htmlToken2Replace)
  2076. .replace(htmlLiveLinkMoved, htmlLiveLinkMovedReplace)
  2077. .replace(htmlLiveLinkMovedWithLiveLink, htmlLiveLinkMovedWithLiveLinkReplace)
  2078. .replace(htmlLiveLinkMovedWithLiveLink2, htmlLiveLinkMovedWithLiveLink2Replace)
  2079. .replace(htmlLiveLink, htmlLiveLinkReplace)
  2080. .replace(htmlFile, htmlFileReplace)
  2081. .replace(htmlFrom, htmlFromReplace)
  2082. .replace(htmlUpdated, htmlUpdatedReplace)
  2083. .replace(htmlUpdated2, htmlUpdated2Replace)
  2084. .replace(htmlSugg, htmlSuggReplace)
  2085. .replace(htmlIntro, htmlIntroReplace)
  2086. .replace(htmlContact, htmlContactReplace)
  2087. .replace(htmlContact2, htmlContact2Replace)
  2088. .replace(rgxTestEmail, htmlTestEmailReplace)
  2089. .replace(rgxTestEmail2, htmlTestEmail2Replace)
  2090. .trim();
  2091. var eleToken = document.querySelector("a[href^='Us_And_Them.php?']");
  2092. if (eleToken)
  2093. {
  2094. if (eleToken.textContent !== "Token")
  2095. {
  2096. eleToken.classList.add("stsh_token_name");
  2097. eleToken.classList.add("stsh_truncate");
  2098. }
  2099. }
  2100. if (!isComplete)
  2101. {
  2102. var stsh_introReplace_start = getTimeMs();
  2103. var stsh_introReplace_itv = setIntervalCustom(function(params)
  2104. {
  2105. var divIntro = params[0];
  2106. var htmlContact = params[1];
  2107. var htmlContactReplace = params[2];
  2108. var stsh_introReplace_isEnd = false;
  2109. var stsh_introReplace_cur = getTimeMs();
  2110. if (divIntro.innerHTML.indexOf(htmlContact) > -1)
  2111. {
  2112. divIntro.innerHTML = divIntro.innerHTML
  2113. .replace(htmlContact, htmlContactReplace);
  2114. stsh_introReplace_isEnd = true;
  2115. }
  2116. if (stsh_introReplace_isEnd || stsh_introReplace_cur - stsh_introReplace_start > 10000)
  2117. {
  2118. clearInterval(stsh_introReplace_itv);
  2119. }
  2120. }, 100, [divIntro, htmlContact, htmlContactReplace]);
  2121. }
  2122. }
  2123. }
  2124. // Restyle token discussion
  2125. {
  2126. var eleDiscuss = document.querySelector("a[name='tokendiscussion']");
  2127. if (eleDiscuss)
  2128. {
  2129. var htmlHeader = "TOKEN DISCUSSION (keep global comments English please!):";
  2130. var htmlHeaderReplace = "TOKEN DISCUSSION:";
  2131. var eleHeader = eleDiscuss.nextElementSibling;
  2132. if (eleHeader)
  2133. {
  2134. eleHeader.setAttribute("title", "Keep global comments English please!");
  2135. eleHeader.classList.add("stsh_cursor_help");
  2136. eleHeader.textContent = eleHeader.textContent.replace(htmlHeader, htmlHeaderReplace);
  2137. }
  2138. var eleParent = eleDiscuss.parentElement;
  2139. eleParent.classList.add("stsh_discussion_header");
  2140. if (eleParent.nextElementSibling)
  2141. {
  2142. eleParent.nextElementSibling.classList.add("stsh_discussion_section");
  2143. }
  2144. var elesInput = document.querySelectorAll("input[value='[stsadmin]']");
  2145. if (elesInput.length === 2)
  2146. {
  2147. elesInput[1].parentElement.removeChild(elesInput[1]);
  2148. }
  2149. var eleSpan = document.createElement("span");
  2150. eleSpan.innerHTML =
  2151. '\
  2152. <input style="border:none; color:#888888; background-color:#111111; cursor:pointer;"\
  2153. onclick="tosts(\'truncated\')" value="[sts_admin][truncated]" type="button">\
  2154. <input style="border:none; color:#888888; background-color:#111111; cursor:pointer;"\
  2155. onclick="tosts(\'typo\');" value="[sts_admin][typo]" type="button">\
  2156. <input style="border:none; color:#888888; background-color:#111111; cursor:pointer;"\
  2157. onclick="tosts(\'unlockpls\')" value="[sts_admin][unlockpls]" type="button">\
  2158. ';
  2159. eleParent.appendChild(eleSpan);
  2160. var eleCopy = document.querySelector("#autocopy");
  2161. if (eleCopy)
  2162. {
  2163. eleCopy.previousElementSibling.classList.add("stsh_autoCopy_header");
  2164. }
  2165. var eleFriendDiscuss = document.querySelector(".friend_block_discussions");
  2166. if (eleFriendDiscuss)
  2167. {
  2168. if (eleCopy)
  2169. {
  2170. insertBeforeElement(document.createElement("br"), eleCopy.previousElementSibling);
  2171. }
  2172. var eleTableDiscuss = eleFriendDiscuss.parentElement.parentElement.parentElement.parentElement;
  2173. if (eleTableDiscuss.tagName === "TABLE")
  2174. {
  2175. eleTableDiscuss.classList.add("stsh_discussion_table");
  2176. }
  2177. }
  2178. }
  2179. }
  2180. // Move up glossary
  2181. {
  2182. function moveUpGlossary()
  2183. {
  2184. var eleDiscuss = document.querySelector(".stsh_discussion_header");
  2185. if (eleDiscuss)
  2186. {
  2187. var eleGlosGroup = document.createElement("div");
  2188. eleGlosGroup.classList.add("stsh_glossary_group");
  2189. insertBeforeElement(eleGlosGroup, eleDiscuss);
  2190. var eleHead = document.querySelector(".stsh_glossary_header");
  2191. if (eleHead)
  2192. {
  2193. if (!(eleHead.childNodes.length === 5
  2194. && eleHead.childNodes[4].nodeType === document.TEXT_NODE
  2195. && eleHead.childNodes[4].nodeValue === "No results"))
  2196. {
  2197. eleGlosGroup.appendChild(document.createElement("br"));
  2198. if (eleHead.tagName === "TABLE")
  2199. {
  2200. eleGlosGroup.appendChild(eleHead.previousElementSibling);
  2201. }
  2202. eleGlosGroup.appendChild(eleHead);
  2203. }
  2204. }
  2205. }
  2206. }
  2207. var eleCopy = document.querySelector(".stsh_autoCopy_header");
  2208. if (eleCopy)
  2209. {
  2210. var eleHead = document.querySelector(".stsh_glossary_header");
  2211. if (eleHead)
  2212. {
  2213. insertAfterElement(eleCopy.nextElementSibling, eleHead);
  2214. insertAfterElement(eleCopy, eleHead);
  2215. insertAfterElement(document.createElement("br"), eleHead);
  2216. insertAfterElement(document.createElement("br"), eleCopy.nextElementSibling);
  2217. }
  2218. }
  2219. var eleFriendDiscuss = document.querySelector(".friend_block_discussions");
  2220. if (!eleFriendDiscuss)
  2221. {
  2222. moveUpGlossary();
  2223. }
  2224. else
  2225. {
  2226. var eleHelp = document.querySelector(".stsh_glossary_help");
  2227. if (eleHelp)
  2228. {
  2229. var eleBtn = document.createElement("input");
  2230. eleBtn.classList.add("stsh_glossary_move");
  2231. eleBtn.setAttribute("type", "button");
  2232. eleBtn.setAttribute("onclick", "return false;");
  2233. eleBtn.value = "Move up";
  2234. eleBtn.title = "Glossary is displayed below when discussion is active. "
  2235. + "\nClick here to move glossary up.";
  2236. insertAfterElement(eleBtn, eleHelp);
  2237. eleBtn.addEventListener("click", function(ev)
  2238. {
  2239. var eleTarget = ev.target;
  2240. eleTarget.classList.add("stsh_hidden");
  2241. moveUpGlossary();
  2242. });
  2243. }
  2244. }
  2245. }
  2246. // Add shortcut keys
  2247. {
  2248. var elesForm = document.querySelectorAll(".lbAction");
  2249. for (var i = 0; i < elesForm.length; i++)
  2250. {
  2251. var eleForm = elesForm[i];
  2252. var eleSubmit = eleForm.querySelector("input[type=submit]");
  2253. if (eleSubmit)
  2254. {
  2255. addKeyCtrlEnter(eleForm, eleSubmit);
  2256. }
  2257. }
  2258. var elesInputApprove = document.querySelectorAll(".stsh_action_approve");
  2259. if (elesInputApprove.length > 0)
  2260. {
  2261. var eleBind = elesInputApprove[0];
  2262. addKeyAlt(document, eleBind, 219); // [
  2263. addKeyAlt(document, eleBind, "BracketLeft"); // [
  2264. addKeyAlt(document, eleBind, 79); // O
  2265. addKeyAlt(document, eleBind, 65); // A
  2266. disableAfterClick(eleBind);
  2267. }
  2268. var eleInputApproveNext = document.querySelector(".stsh_action_approve_next");
  2269. if (eleInputApproveNext)
  2270. {
  2271. var eleBind = null;
  2272. if (!eleInputApproveNext.disabled)
  2273. {
  2274. // Can go next
  2275. if (elesInputApprove.length === 1)
  2276. {
  2277. // Go next if only 1 suggestion
  2278. eleBind = eleInputApproveNext;
  2279. }
  2280. else if (elesInputApprove.length > 1)
  2281. {
  2282. // Only approve if more than 1 suggestion
  2283. eleBind = elesInputApprove[0];
  2284. }
  2285. }
  2286. else
  2287. {
  2288. // Can't go next
  2289. if (elesInputApprove.length > 0)
  2290. {
  2291. var eleBind = elesInputApprove[0];
  2292. }
  2293. }
  2294. if (eleBind)
  2295. {
  2296. addKeyAlt(document, eleBind, 221); // ]
  2297. addKeyAlt(document, eleBind, "BracketRight"); // ]
  2298. addKeyAlt(document, eleBind, 80); // P
  2299. addKeyAlt(document, eleBind, 83); // S
  2300. addKeyCtrl(document, eleBind, 220); // Backslash
  2301. addKeyCtrl(document, eleBind, "Backslash"); // Backslash
  2302. addKeyCtrl(document, eleBind, 45, "Ins", 1|2); // INS
  2303. disableAfterClick(eleBind);
  2304. }
  2305. }
  2306. var eleInputDecline = document.querySelector(".stsh_action_decline");
  2307. if (eleInputDecline)
  2308. {
  2309. var eleBind = eleInputDecline;
  2310. addKeyCtrl(document, eleBind, 46, "Del", 1|2); // DEL
  2311. disableAfterClick(eleBind);
  2312. var eleInpueDeclineNext = eleInputDecline.nextElementSibling;
  2313. if (eleInpueDeclineNext && eleInpueDeclineNext.value.indexOf("Next") > -1
  2314. && !eleInpueDeclineNext.disabled)
  2315. {
  2316. var eleBind = eleInpueDeclineNext;
  2317. addKeyCtrlShift(document, eleBind, 46, "Del", 2); // DEL
  2318. disableAfterClick(eleBind);
  2319. }
  2320. }
  2321. else
  2322. {
  2323. var eleReconsider = document.querySelector(".suggestion_status_approved > a, .suggestion_status_declined > a");
  2324. if (eleReconsider)
  2325. {
  2326. if (eleReconsider.parentElement.classList.contains("suggestion_status_approved"))
  2327. {
  2328. var eleBind = eleReconsider;
  2329. addKeyCtrl(document, eleBind, 46, "Del", 2|16); // DEL
  2330. }
  2331. else
  2332. {
  2333. if (!eleReconsider.parentElement.parentElement
  2334. .querySelector(".suggestion_signature .lbAction[name^='mymodcomment']"))
  2335. {
  2336. var eleBind = eleReconsider;
  2337. addKeyAlt(document, eleBind, 221); // ]
  2338. addKeyAlt(document, eleBind, "BracketRight"); // ]
  2339. addKeyAlt(document, eleBind, 80); // P
  2340. addKeyAlt(document, eleBind, 83); // S
  2341. addKeyCtrl(document, eleBind, 220); // Backslash
  2342. addKeyCtrl(document, eleBind, "Backslash"); // Backslash
  2343. addKeyCtrl(document, eleBind, 45, "Ins", 2|16); // INS
  2344. }
  2345. }
  2346. }
  2347. }
  2348. var elesTextRemoveComment = document.querySelectorAll(".stsh_text_removeComment");
  2349. if (elesTextRemoveComment.length > 0)
  2350. {
  2351. // Remove last comment
  2352. var i = elesTextRemoveComment.length - 1;
  2353.  
  2354. var eleBind = elesTextRemoveComment[i];
  2355. addKeyCtrl(document, eleBind, 8, "Bksp", 2|16); // Backspace
  2356. }
  2357. var inputPrev = document.querySelector("#suggestions_nav > input[value^='Prev']");
  2358. if (inputPrev)
  2359. {
  2360. var eleBind = inputPrev;
  2361. addKeyCtrl(document, eleBind, 219, "[", 1|2); // [
  2362. addKeyCtrl(document, eleBind, "BracketLeft"); // [
  2363. disableAfterClick(eleBind);
  2364. eleBind.classList.add("stsh_nav_prev");
  2365. eleBind.parentElement.removeChild(eleBind.nextSibling); // Remove space
  2366. }
  2367. var inputNext = document.querySelector("#suggestions_nav > input[value~='Next']");
  2368. if (inputNext)
  2369. {
  2370. var eleBind = inputNext;
  2371. addKeyCtrl(document, eleBind, 221, "]", 1|2); // ]
  2372. addKeyCtrl(document, eleBind, "BracketRight"); // ]
  2373. disableAfterClick(eleBind);
  2374. eleBind.classList.add("stsh_nav_next");
  2375. }
  2376. }
  2377. // Check special chars
  2378. // Check combining diacritical marks
  2379. {
  2380. var h1s = document.querySelectorAll(".progress h1");
  2381. if (h1s.length === 2)
  2382. {
  2383. var h1Org = h1s[0];
  2384. var h1Trn = h1s[1];
  2385. var tdOrg = eleTextOrg;
  2386. var tdTrn = eleTextTrn;
  2387. if (tdOrg && tdTrn)
  2388. {
  2389. var strOrg = trimSpace(tdOrg.textContent);
  2390. var strTrn = trimSpace(tdTrn.textContent);
  2391. // Check special chars
  2392. {
  2393. var statusTrnArr = checkSpecialCharMatched(strOrg, strTrn);
  2394. var statusTrnMatched = statusTrnArr[0];
  2395. var spOrg = statusTrnArr[1];
  2396. var spTrn = statusTrnArr[2];
  2397. if (spOrg > 0)
  2398. {
  2399. var spTitle = "Please check special chars by pressing Display special chars button.";
  2400. var spanSpOrg = document.createElement("span");
  2401. spanSpOrg.id = "stsh_spanSpOrg";
  2402. spanSpOrg.classList.add("stsh_blue");
  2403. spanSpOrg.classList.add("stsh_cursor_help");
  2404. spanSpOrg.title = spTitle;
  2405. spanSpOrg.innerHTML = " SpecialChar: " + spOrg;
  2406. h1Org.parentElement.appendChild(spanSpOrg);
  2407. // Translated
  2408. if (strTrn !== "")
  2409. {
  2410. var spanSpTrn = document.createElement("span");
  2411. spanSpTrn.id = "stsh_spanSpTrn";
  2412. spanSpTrn.classList.add("stsh_cursor_help");
  2413. spanSpTrn.title = spTitle;
  2414. if (statusTrnMatched === 0)
  2415. {
  2416. spanSpTrn.classList.add("stsh_green");
  2417. }
  2418. else
  2419. {
  2420. spanSpTrn.classList.add("stsh_red");
  2421. }
  2422. var outputTrn = " SpecialChar: " + spTrn;
  2423. if (statusTrnMatched === 0)
  2424. {
  2425. outputTrn += " (Matched)";
  2426. }
  2427. else if (statusTrnMatched === 1)
  2428. {
  2429. outputTrn += " (Order not matched)";
  2430. }
  2431. else
  2432. {
  2433. outputTrn += " (Not matched)";
  2434. }
  2435. spanSpTrn.innerHTML = outputTrn;
  2436. h1Trn.parentElement.appendChild(spanSpTrn);
  2437. }
  2438. // Suggested
  2439. var divSugs = document.querySelectorAll(".suggestion_text");
  2440. for (var i = 0; i < divSugs.length; i++)
  2441. {
  2442. var divSug = divSugs[i];
  2443. var strSug = trimSpace(divSug.textContent);
  2444. var statusSugArr = checkSpecialCharMatched(strOrg, strSug);
  2445. var statusSugMatched = statusSugArr[0];
  2446. var spSug = statusSugArr[2];
  2447. var spanSpSug = document.createElement("span");
  2448. spanSpSug.classList.add("stsh_spanSpSug");
  2449. spanSpSug.classList.add("stsh_cursor_help");
  2450. spanSpSug.title = spTitle;
  2451. if (statusSugMatched === 0)
  2452. {
  2453. spanSpSug.classList.add("stsh_green");
  2454. }
  2455. else
  2456. {
  2457. spanSpSug.classList.add("stsh_red");
  2458. }
  2459. var outputSug = " SpecialChar: " + spSug;
  2460. if (statusSugMatched === 0)
  2461. {
  2462. outputSug += " (Matched)";
  2463. }
  2464. else if (statusSugMatched === 1)
  2465. {
  2466. outputSug += " (Order not matched)";
  2467. }
  2468. else
  2469. {
  2470. outputSug += " (Not matched)";
  2471. }
  2472. spanSpSug.innerHTML = outputSug;
  2473. divSug.insertBefore(spanSpSug, divSug.firstChild);
  2474. }
  2475. }
  2476. }
  2477. // Check diacritical marks
  2478. {
  2479. var hasDct = false;
  2480. // Translated
  2481. var dctTrn = countDiacriticalMark(strTrn);
  2482. if (dctTrn > 0)
  2483. {
  2484. hasDct = true;
  2485. }
  2486. var countsSug = [];
  2487. // Suggested
  2488. var divSugs = document.querySelectorAll(".suggestion_text");
  2489. for (var i = 0; i < divSugs.length; i++)
  2490. {
  2491. var divSug = divSugs[i];
  2492. var strSug = trimSpace(divSug.textContent);
  2493. var dctSug = countDiacriticalMark(strSug);
  2494. if (dctSug > 0)
  2495. {
  2496. hasDct = true;
  2497. }
  2498. countsSug.push(dctSug);
  2499. }
  2500. if (hasDct)
  2501. {
  2502. var dctTitleGood = "Combining Diacritical Marks not found. \nThis is good typing method.";
  2503. var dctTitleBad = "Combining Diacritical Marks found. \nPlease change typing method.";
  2504. var spanDctTrn = document.createElement("span");
  2505. spanDctTrn.id = "stsh_spanDctTrn";
  2506. spanDctTrn.classList.add("stsh_cursor_help");
  2507. if (dctTrn > 0)
  2508. {
  2509. spanDctTrn.classList.add("stsh_red");
  2510. spanDctTrn.title = dctTitleBad;
  2511. }
  2512. else
  2513. {
  2514. spanDctTrn.classList.add("stsh_green");
  2515. spanDctTrn.title = dctTitleGood;
  2516. }
  2517. var outputDctTrn = " DiacriticalMark: " + dctTrn;
  2518. spanDctTrn.innerHTML = outputDctTrn;
  2519. h1Trn.parentElement.appendChild(spanDctTrn);
  2520. for (var i = 0; i < divSugs.length; i++)
  2521. {
  2522. var divSug = divSugs[i];
  2523. var dctSug = countsSug[i];
  2524. var spanDctSug = document.createElement("span");
  2525. spanDctSug.classList.add("stsh_spanDctSug");
  2526. spanDctSug.classList.add("stsh_cursor_help");
  2527. if (dctSug > 0)
  2528. {
  2529. spanDctSug.classList.add("stsh_red");
  2530. spanDctSug.title = dctTitleBad;
  2531. }
  2532. else
  2533. {
  2534. spanDctSug.classList.add("stsh_green");
  2535. spanDctSug.title = dctTitleGood;
  2536. }
  2537. var outputDctSug = " DiacriticalMark: " + dctSug;
  2538. spanDctSug.innerHTML = outputDctSug;
  2539. divSug.insertBefore(spanDctSug, divSug.firstChild);
  2540. }
  2541. }
  2542. }
  2543. }
  2544. }
  2545. }
  2546. // Trim string in same token
  2547. {
  2548. var p = document.querySelector("#suggestionmain > div:nth-child(5) > p:nth-child(4)");
  2549. if (p)
  2550. {
  2551. for (var i = 0; i < p.childNodes.length; i++)
  2552. {
  2553. var child = p.childNodes[i];
  2554. if (child.nodeName === "#text")
  2555. {
  2556. child.nodeValue = child.nodeValue.trim();
  2557. }
  2558. }
  2559. }
  2560. }
  2561. // Display newlines
  2562. // Display specialChars
  2563. // Display HTML tags
  2564. // Display hidden contents
  2565. // Minimize images
  2566. {
  2567. if (eleTextOrg && eleTextTrn)
  2568. {
  2569. var htmlOrg = eleTextOrg.innerHTML.trim();
  2570. var htmlTrn = eleTextTrn.innerHTML.trim();
  2571. var h2SugHeader = document.querySelector("#suggestionmain > div > h2");
  2572. // Display newlines
  2573. if ((htmlOrg.indexOf("\n") > -1 || htmlOrg.indexOf("\\n") > -1
  2574. || htmlTrn.indexOf("\n") > -1 || htmlTrn.indexOf("\\n") > -1)
  2575. /*&& htmlOrg.indexOf("<br") < 0
  2576. && htmlOrg.indexOf("<p") < 0 && htmlOrg.indexOf("<div") < 0 && htmlOrg.indexOf("<li") < 0*/)
  2577. {
  2578. if (h2SugHeader)
  2579. {
  2580. var btn = document.createElement("input");
  2581. btn.id = "stsh_btn_displayNewlines";
  2582. btn.setAttribute("class", "stsh_btn_right");
  2583. btn.setAttribute("type", "button");
  2584. btn.setAttribute("value", "Display newlines");
  2585. h2SugHeader.appendChild(btn);
  2586. function displayNewlines(ele)
  2587. {
  2588. if (ele)
  2589. {
  2590. ele.innerHTML = ele.innerHTML.trim()
  2591. .replace(/\<span[^\>]+class=\"stsh_[\s\S]+?\/span\>/ig, "")
  2592. .replace(/\n/g, "\n<br>")
  2593. .replace(/\\n/g, ' <span class="stsh_grey">\\n</span><br>')
  2594. .replace(/\\r \\n/g, ' <span class="stsh_grey">\\r\\n</span><br>')
  2595. .replace(/\<br\>[\s]+/g, "<br>&nbsp;");
  2596. }
  2597. }
  2598. btn.addEventListener("click", function(ev)
  2599. {
  2600. ev.target.disabled = true;
  2601. var eleBtnHtmlTags = document.querySelector("#stsh_btn_displayHtmlTags");
  2602. if (eleBtnHtmlTags)
  2603. {
  2604. eleBtnHtmlTags.disabled = true;
  2605. }
  2606. var tdOrg = document.querySelector(".stsh_text_org");
  2607. var tdTrn = document.querySelector(".stsh_text_trn:not(.stsh_text_trn_empty)");
  2608. displayNewlines(tdOrg);
  2609. displayNewlines(tdTrn);
  2610. var divSugs = document.querySelectorAll(".suggestion_text");
  2611. for (var i = 0; i < divSugs.length; i++)
  2612. {
  2613. var divSug = divSugs[i];
  2614. displayNewlines(divSug);
  2615. }
  2616. var textarea = document.querySelector("#suggestion_value_new");
  2617. if (textarea)
  2618. {
  2619. textarea.focus();
  2620. }
  2621. });
  2622. }
  2623. }
  2624. // Display specialChars
  2625. if (hasSpecialChar(htmlOrg) || hasSpecialChar(htmlTrn))
  2626. {
  2627. if (h2SugHeader)
  2628. {
  2629. var btn = document.createElement("input");
  2630. btn.id = "stsh_btn_displaySpecialChars";
  2631. btn.setAttribute("class", "stsh_btn_right");
  2632. btn.setAttribute("type", "button");
  2633. btn.setAttribute("value", "Display special chars");
  2634. h2SugHeader.appendChild(btn);
  2635. function replaceSpecialChars(str, unicodeNumber)
  2636. {
  2637. var rgx = new RegExp("\\u" + padZeroHex(unicodeNumber, 4), "g");
  2638. return str.replace(rgx, '<span class="stsh_grey">[' + padZeroHex(unicodeNumber, 2) + ']</span>');
  2639. }
  2640. function displaySpecialChars(ele)
  2641. {
  2642. if (ele)
  2643. {
  2644. var strInner = trimSpace(ele.innerHTML);
  2645. for (var i = 0; i < 32; i++)
  2646. {
  2647. if (hasSpecialChar(strInner))
  2648. {
  2649. if (isSpecialChar(i))
  2650. {
  2651. strInner = replaceSpecialChars(strInner, i);
  2652. }
  2653. }
  2654. else
  2655. {
  2656. break;
  2657. }
  2658. }
  2659. ele.innerHTML = strInner;
  2660. }
  2661. }
  2662. btn.addEventListener("click", function(ev)
  2663. {
  2664. ev.target.disabled = true;
  2665. var tdOrg = document.querySelector(".stsh_text_org");
  2666. var tdTrn = document.querySelector(".stsh_text_trn:not(.stsh_text_trn_empty)");
  2667. displaySpecialChars(tdOrg);
  2668. displaySpecialChars(tdTrn);
  2669. var divSugs = document.querySelectorAll(".suggestion_text");
  2670. for (var i = 0; i < divSugs.length; i++)
  2671. {
  2672. var divSug = divSugs[i];
  2673. displaySpecialChars(divSug);
  2674. }
  2675. var textarea = document.querySelector("#suggestion_value_new");
  2676. if (textarea)
  2677. {
  2678. textarea.focus();
  2679. }
  2680. });
  2681. }
  2682. }
  2683. // Display HTML tags
  2684. if (htmlOrg.indexOf("<") > -1
  2685. || (htmlTrn.indexOf("<") > -1 && !eleTextTrn.classList.contains("stsh_text_trn_empty"))
  2686. || htmlOrg.indexOf("[/") > -1)
  2687. {
  2688. if (h2SugHeader)
  2689. {
  2690. var btn = document.createElement("input");
  2691. btn.id = "stsh_btn_displayHtmlTags";
  2692. btn.setAttribute("class", "stsh_btn_right");
  2693. btn.setAttribute("type", "button");
  2694. btn.setAttribute("value", "Display HTML tags");
  2695. btn.setAttribute("title"
  2696. , "Some closing tags and attributes are autogenerated by web browser. \nPlease use with care!");
  2697. h2SugHeader.appendChild(btn);
  2698. function displayHtmlTags(ele)
  2699. {
  2700. if (ele)
  2701. {
  2702. ele.innerHTML = ele.innerHTML.trim()
  2703. .replace(/\<span[^\>]+class=\"stsh_[\s\S]+?\/span\>/ig, "");
  2704. var isSkip = false;
  2705. var isBb = (ele.textContent.indexOf("[/") > -1);
  2706. if (ele.classList.contains("stsh_text_org"))
  2707. {
  2708. if (ele.querySelector("span[style='color:#ff0000;']"))
  2709. {
  2710. ele.innerHTML = ele.innerHTML.replace(/<[\/]?span[^>]*>/ig, "");
  2711. }
  2712. if (ele.querySelector("font[style='BACKGROUND-COLOR: blue']"))
  2713. {
  2714. ele.innerHTML = ele.innerHTML.replace(/<[\/]?font[^>]*>/ig, "");
  2715. }
  2716. }
  2717. else if (ele.classList.contains("stsh_text_trn"))
  2718. {
  2719. if (ele.classList.contains("stsh_text_trn_empty"))
  2720. {
  2721. isSkip = true;
  2722. }
  2723. else if (ele.querySelector("span[style='color:#ff0000;']"))
  2724. {
  2725. ele.innerHTML = ele.innerHTML.replace(/<[\/]?span[^>]*>/ig, "");
  2726. }
  2727. }
  2728. else if (ele.classList.contains("suggestion_text"))
  2729. {
  2730. if (ele.querySelector("span[style='color:red;']"))
  2731. {
  2732. ele.innerHTML = ele.innerHTML.replace(/<[\/]?span[^>]*>/ig, "");
  2733. }
  2734. if (ele.querySelector("font[face='Times New Roman']"))
  2735. {
  2736. ele.innerHTML = ele.innerHTML.replace(/<[\/]?font[^>]*>/ig, "");
  2737. }
  2738. }
  2739. if (!isSkip)
  2740. {
  2741. ele.textContent = ele.innerHTML.trim();
  2742. var newHtml = ele.innerHTML;
  2743. if (!isBb)
  2744. {
  2745. newHtml = newHtml
  2746. .replace(/&lt;script[\s\S]+?\/script&gt;/ig,
  2747. "<br>&lt;script&gt;...&lt;/script&gt;<br>")
  2748. .replace(/&lt;style[\s\S]+?\/style&gt;/ig,
  2749. "<br>&lt;style&gt;...&lt;/style&gt;<br>")
  2750. .replace(/&amp;/ig, "&")
  2751. .replace(/\n/ig, "\n<br>")
  2752. .replace(/&lt;/ig, '<span class="stsh_grey">&lt;')
  2753. .replace(/=""&gt;/ig, "&gt;")
  2754. .replace(/&gt;/ig, "&gt;</span>")
  2755. .replace(/br&gt;/ig, "br&gt;<br>")
  2756. .replace(/&lt;li/ig, "<br>&lt;li");
  2757. }
  2758. else
  2759. {
  2760. newHtml = newHtml
  2761. .replace(/\n/ig, "\n<br>")
  2762. .replace(/\[/ig, '<span class="stsh_grey">[')
  2763. .replace(/\]/ig, "]</span>")
  2764. .replace(/&lt;font face="Times New Roman"&gt;-&lt;\/font&gt;/ig, "-")
  2765. .replace(/&amp;nbsp;/ig, " ");
  2766. }
  2767. ele.innerHTML = newHtml;
  2768. }
  2769. }
  2770. }
  2771. btn.addEventListener("click", function(ev)
  2772. {
  2773. ev.target.disabled = true;
  2774. var eleBtnNewlines = document.querySelector("#stsh_btn_displayNewlines");
  2775. if (eleBtnNewlines)
  2776. {
  2777. eleBtnNewlines.disabled = true;
  2778. }
  2779. var tdOrg = document.querySelector(".stsh_text_org");
  2780. var tdTrn = document.querySelector(".stsh_text_trn:not(.stsh_text_trn_empty)");
  2781. displayHtmlTags(tdOrg);
  2782. displayHtmlTags(tdTrn);
  2783. var divSugs = document.querySelectorAll(".suggestion_text");
  2784. for (var i = 0; i < divSugs.length; i++)
  2785. {
  2786. var divSug = divSugs[i];
  2787. displayHtmlTags(divSug);
  2788. }
  2789. var textarea = document.querySelector("#suggestion_value_new");
  2790. if (textarea)
  2791. {
  2792. textarea.focus();
  2793. }
  2794. });
  2795. }
  2796. }
  2797. // Display hidden contents
  2798. // Sample: https://translation.steampowered.com/translate.php?search_input=faq_418_answer
  2799. var hasHidden = false;
  2800. {
  2801. hasHidden = !!(eleTextOrg.querySelector("*[style='display: none;']")
  2802. || eleTextTrn.querySelector("*[style='display: none;']"));
  2803. if (!hasHidden)
  2804. {
  2805. var elesSug = document.querySelectorAll(".suggestion_text");
  2806. if (elesSug.length > 0)
  2807. {
  2808. hasHidden = !!(elesSug[0].querySelector("*[style='display: none;']"));
  2809. }
  2810. }
  2811. }
  2812. if (hasHidden)
  2813. {
  2814. var countHidden = 0;
  2815. var elesHidden = eleTextOrg.querySelectorAll("*[style='display: none;']");
  2816. for (var i = 0; i < elesHidden.length; i++)
  2817. {
  2818. if (elesHidden[i].childElementCount > 1
  2819. || (elesHidden[i].firstElementChild
  2820. && elesHidden[i].firstElementChild.tagName !== "STYLE"))
  2821. {
  2822. countHidden++;
  2823. break;
  2824. }
  2825. }
  2826. hasHidden = countHidden > 0;
  2827. }
  2828. if (!hasHidden)
  2829. {
  2830. hasHidden = !!(eleTextOrg.querySelector(".collapse, .dropdown-before")
  2831. || eleTextTrn.querySelector(".collapse, .dropdown-before"));
  2832. }
  2833. if (hasHidden)
  2834. {
  2835. if (h2SugHeader)
  2836. {
  2837. var btn = document.createElement("input");
  2838. btn.id = "stsh_btn_displayHidden";
  2839. btn.setAttribute("class", "stsh_btn_right");
  2840. btn.setAttribute("type", "button");
  2841. btn.setAttribute("value", "Display hidden contents");
  2842. btn.setAttribute("title", "Toggle show/hide contents that hidden by CSS."
  2843. + " \nHidden contents shown in gray boxes.");
  2844. btn.dataset.modeNext = "show";
  2845. h2SugHeader.appendChild(btn);
  2846. function showHidden(ele, mode)
  2847. {
  2848. if (ele)
  2849. {
  2850. if (mode === "show")
  2851. {
  2852. var elesHidden = ele.querySelectorAll(
  2853. "*[style='display: none;'], .collapse, .dropdown-before");
  2854. for (var i = 0; i < elesHidden.length; i++)
  2855. {
  2856. elesHidden[i].classList.add("stsh_showHidden");
  2857. }
  2858. }
  2859. else
  2860. {
  2861. var elesHidden = ele.querySelectorAll(".stsh_showHidden");
  2862. for (var i = 0; i < elesHidden.length; i++)
  2863. {
  2864. elesHidden[i].classList.remove("stsh_showHidden");
  2865. }
  2866. }
  2867. }
  2868. }
  2869. btn.addEventListener("click", function(ev)
  2870. {
  2871. var eleTarget = ev.target;
  2872. var mode = "show";
  2873. if (eleTarget.dataset.modeNext === "show")
  2874. {
  2875. mode = "show";
  2876. eleTarget.dataset.modeNext = "hide";
  2877. }
  2878. else
  2879. {
  2880. mode = "hide";
  2881. eleTarget.dataset.modeNext = "show";
  2882. }
  2883. var tdOrg = document.querySelector(".stsh_text_org");
  2884. var tdTrn = document.querySelector(".stsh_text_trn:not(.stsh_text_trn_empty)");
  2885. showHidden(tdOrg, mode);
  2886. showHidden(tdTrn, mode);
  2887. var divSugs = document.querySelectorAll(".suggestion_text");
  2888. for (var i = 0; i < divSugs.length; i++)
  2889. {
  2890. var divSug = divSugs[i];
  2891. showHidden(divSug, mode);
  2892. }
  2893. var textarea = document.querySelector("#suggestion_value_new");
  2894. if (textarea)
  2895. {
  2896. textarea.focus();
  2897. }
  2898. });
  2899. }
  2900. }
  2901. // Minimize images
  2902. if (eleTextOrg.querySelector("img"))
  2903. {
  2904. if (h2SugHeader)
  2905. {
  2906. var btn = document.createElement("input");
  2907. btn.id = "stsh_btn_minimizeImages";
  2908. btn.setAttribute("class", "stsh_btn_right");
  2909. btn.setAttribute("type", "button");
  2910. btn.setAttribute("value", "Minimize images");
  2911. btn.setAttribute("title", "Toggle reduced/normal image sizes");
  2912. btn.dataset.modeNext = "min";
  2913. h2SugHeader.appendChild(btn);
  2914. function minimizeImages(ele, mode)
  2915. {
  2916. if (ele)
  2917. {
  2918. if (mode === "min")
  2919. {
  2920. var elesImg = ele.querySelectorAll("img:not(.stsh_img_min)");
  2921. for (var i = 0; i < elesImg.length; i++)
  2922. {
  2923. elesImg[i].classList.add("stsh_img_min");
  2924. }
  2925. }
  2926. else
  2927. {
  2928. var elesImg = ele.querySelectorAll("img.stsh_img_min");
  2929. for (var i = 0; i < elesImg.length; i++)
  2930. {
  2931. elesImg[i].classList.remove("stsh_img_min");
  2932. }
  2933. }
  2934. }
  2935. }
  2936. btn.addEventListener("click", function(ev)
  2937. {
  2938. var eleTarget = ev.target;
  2939. var mode = "min";
  2940. if (eleTarget.dataset.modeNext === "min")
  2941. {
  2942. mode = "min";
  2943. eleTarget.dataset.modeNext = "unmin";
  2944. }
  2945. else
  2946. {
  2947. mode = "unmin";
  2948. eleTarget.dataset.modeNext = "min";
  2949. }
  2950. var tdOrg = document.querySelector(".stsh_text_org");
  2951. var tdTrn = document.querySelector(".stsh_text_trn:not(.stsh_text_trn_empty)");
  2952. minimizeImages(tdOrg, mode);
  2953. minimizeImages(tdTrn, mode);
  2954. var divSugs = document.querySelectorAll(".suggestion_text");
  2955. for (var i = 0; i < divSugs.length; i++)
  2956. {
  2957. var divSug = divSugs[i];
  2958. minimizeImages(divSug, mode);
  2959. }
  2960. var textarea = document.querySelector("#suggestion_value_new");
  2961. if (textarea)
  2962. {
  2963. textarea.focus();
  2964. }
  2965. });
  2966. }
  2967. }
  2968. }
  2969. }
  2970. // Open comment when decline
  2971. // Paste last comment
  2972. {
  2973. var countComment = 0;
  2974. var elesComment = [];
  2975. var countSug = document.querySelectorAll(".suggestions_list .suggestion").length;
  2976. if (countSug > 0)
  2977. {
  2978. var textOrg = "";
  2979. if (eleTextOrg)
  2980. {
  2981. textOrg = trimSpace(eleTextOrg.innerHTML).substr(0, 1000).toLowerCase();
  2982. }
  2983. var isSameTextOrg = textOrg === GM_getValue("textLastOrg_Comment", "");
  2984. var textLastCur = GM_getValue("textLastCur_Comment", "");
  2985. var isSetComment = false;
  2986. var countSugDeclined = document.querySelectorAll(
  2987. ".suggestions_list span[class='suggestion_status_declined']").length;
  2988. if (countSug !== countSugDeclined)
  2989. {
  2990. var elesSugCheck = document.querySelectorAll(".suggestions_list span[class^='suggestion_status_']");
  2991. if (countSug === elesSugCheck.length)
  2992. {
  2993. var eleSugDeclined = document.querySelector(".suggestions_list span[class='suggestion_status_declined']");
  2994. if (eleSugDeclined && eleSugDeclined === elesSugCheck[0] && eleSugDeclined.querySelector("a"))
  2995. {
  2996. countSugDeclined = countSug;
  2997. }
  2998. }
  2999. }
  3000. if (countSug === countSugDeclined)
  3001. {
  3002. var elesSugA = document.querySelectorAll(".suggestions_list span[class^='suggestion_status_'] a");
  3003. for (var i = 0; i < elesSugA.length; i++)
  3004. {
  3005. var eleComment = elesSugA[i].parentElement.parentElement.nextSibling;
  3006. if (eleComment.nodeName === "DIV" && eleComment.classList.contains("copy"))
  3007. {
  3008. if (elesSugA[i].parentElement.classList.contains("suggestion_status_declined"))
  3009. {
  3010. countComment++;
  3011. elesComment.push(eleComment);
  3012. }
  3013. }
  3014. }
  3015. if (countComment === elesSugA.length)
  3016. {
  3017. var isFocus = false;
  3018. for (var i = 0; i < elesComment.length; i++)
  3019. {
  3020. elesComment[i].style.display = "block";
  3021. if (!isFocus)
  3022. {
  3023. var eleTxt = elesComment[i].querySelector(".stsh_text_addComment");
  3024. if (eleTxt)
  3025. {
  3026. eleTxt.focus();
  3027. // Auto paste last comment
  3028. {
  3029. if (isSameTextOrg)
  3030. {
  3031. if (textLastCur !== "")
  3032. {
  3033. eleTxt.value = textLastCur;
  3034. isSetComment = true;
  3035. }
  3036. setTimeoutCustom(function(ele)
  3037. {
  3038. // paste again after script ran
  3039. if (ele)
  3040. {
  3041. var textLastCur = GM_getValue("textLastCur_Comment", "");
  3042. if (textLastCur !== "")
  3043. {
  3044. ele.value = textLastCur;
  3045. //ele.selectionStart = 0;
  3046. //ele.selectionEnd = ele.value.length;
  3047. }
  3048. }
  3049. }, 250, eleTxt);
  3050. }
  3051. }
  3052. /*
  3053. // Typonion
  3054. var eleSugOuter = elesComment[i].parentElement.parentElement.parentElement.parentElement;
  3055. if (eleSugOuter.classList.contains("suggestion"))
  3056. {
  3057. var eleOnion = eleSugOuter.querySelector(".suggestion_text font[style='color:#01ec00;']");
  3058. if (eleOnion)
  3059. {
  3060. eleTxt.value = "onion";
  3061. }
  3062. }
  3063. */
  3064. var eleSugComment = elesComment[i].parentElement
  3065. .parentElement.parentElement.querySelector(".stsh_text_comment font");
  3066. if (eleSugComment && eleSugComment.textContent.trim() ==
  3067. "ATTENTION - English string was updated. This suggestion might be outdated.")
  3068. {
  3069. eleTxt.value = "outdated";
  3070. isSetComment = true;
  3071. }
  3072. isFocus = true;
  3073. }
  3074. }
  3075. }
  3076. }
  3077. }
  3078. if (isSameTextOrg && !isSetComment && textLastCur !== "")
  3079. {
  3080. // paste last comment to all hidden comment inputs
  3081. var elesTxt = document.querySelectorAll(".stsh_text_addComment");
  3082. for (var i = 0; i < elesTxt.length; i++)
  3083. {
  3084. elesTxt[i].value = textLastCur;
  3085. isSetComment = true;
  3086. }
  3087. }
  3088. }
  3089. }
  3090. // Convert time
  3091. {
  3092. var rgxTime = /\d{2}-\d{2}-\d{4}, \d{2}:\d{2} [AP]M/;
  3093. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
  3094. var eleFriends = document.querySelectorAll(".friend_block_avatar, .friend_block_discussions, .suggestions_list");
  3095. for (var i = 0; i < eleFriends.length; i++)
  3096. {
  3097. var nodes = [];
  3098. if (eleFriends[i].classList.contains("friend_block_avatar"))
  3099. {
  3100. nodes = eleFriends[i].childNodes;
  3101. if (nodes.length === 1)
  3102. {
  3103. // Correct HTML tags that auto generated
  3104. nodes = eleFriends[i].childNodes[0].childNodes;
  3105. }
  3106. }
  3107. else if (eleFriends[i].classList.contains("friend_block_discussions"))
  3108. {
  3109. nodes = eleFriends[i].parentElement.nextElementSibling.childNodes[2].childNodes;
  3110. }
  3111. else if (eleFriends[i].classList.contains("suggestions_list"))
  3112. {
  3113. if (!eleFriends[i].querySelector(".suggestion"))
  3114. {
  3115. nodes = eleFriends[i].childNodes;
  3116. }
  3117. }
  3118. for (var j = 0; j < nodes.length; j++)
  3119. {
  3120. var nodeVal = nodes[j].nodeValue;
  3121. if (nodeVal)
  3122. {
  3123. var dateTimes = rgxTime.exec(nodeVal);
  3124. if (dateTimes)
  3125. {
  3126. var dateTime = dateTimes[0];
  3127. var month = dateTime.substr(0, 2);
  3128. var day = dateTime.substr(3, 2);
  3129. var year = dateTime.substr(6, 4);
  3130. var hour = dateTime.substr(12, 2);
  3131. var minute = dateTime.substr(15, 2);
  3132. var period = dateTime.substr(18, 2);
  3133. if (period === "AM")
  3134. {
  3135. if (hour === "12")
  3136. {
  3137. hour = "00"
  3138. }
  3139. }
  3140. else if (period === "PM")
  3141. {
  3142. hour = parseInt(hour) + 12;
  3143. if (hour === 24)
  3144. {
  3145. hour = 12;
  3146. }
  3147. }
  3148. var dateTimeStd = year + "-" + month + "-" + day;
  3149. if (isDstUs(year, month, day, hour))
  3150. {
  3151. dateTimeStd += "T" + hour + ":" + minute + ":00-0700";
  3152. }
  3153. else
  3154. {
  3155. dateTimeStd += "T" + hour + ":" + minute + ":00-0800";
  3156. }
  3157. var dateStd = new Date(dateTimeStd);
  3158. if (dateStd.toLocaleString() !== "Invalid Date")
  3159. {
  3160. var gmt = dateStd.getTimezoneOffset() / 60 * -1;
  3161. var gmtStr = " GMT";
  3162. if (gmt > 0)
  3163. {
  3164. gmtStr += "+" + gmt;
  3165. }
  3166. else if (gmt < 0)
  3167. {
  3168. gmtStr += "-" + gmt;
  3169. }
  3170. var dateNew = dateStd.getDate()
  3171. + " " + months[dateStd.getMonth()]
  3172. + " " + dateStd.getFullYear()
  3173. + ", " + padZero(dateStd.getHours(), 2)
  3174. + ":" + padZero(dateStd.getMinutes(), 2)
  3175. + gmtStr;
  3176. //console.log("Time: " + dateTimeStd);
  3177. //console.log("Time: " + dateTime + " -> " + dateNew);
  3178. //var dateNew2 = dateStd.toLocaleString() + gmtStr;
  3179. //console.log("Time: " + dateTime + " -> " + dateNew2);
  3180. var nodeValBegin = nodeVal.substr(0, nodeVal.indexOf(dateTime));
  3181. var nodeValEnd = nodeVal.substr(nodeVal.indexOf(dateTime) + dateTime.length);
  3182. nodes[j].nodeValue = nodeValBegin;
  3183. var ele = document.createElement("span");
  3184. ele.classList.add("stsh_time_convert");
  3185. ele.classList.add("stsh_cursor_help");
  3186. ele.setAttribute("title", dateTime);
  3187. ele.textContent = dateNew;
  3188. insertAfterElement(ele, nodes[j]);
  3189. if (nodeValEnd !== "")
  3190. {
  3191. insertAfterElement(document.createTextNode(nodeValEnd), ele);
  3192. }
  3193. }
  3194. else
  3195. {
  3196. console.log("Invalid Date: " + dateTimeStd);
  3197. }
  3198. }
  3199. }
  3200. }
  3201. }
  3202. }
  3203. // Add Steam profile links
  3204. {
  3205. var eleSpans = document.querySelectorAll("span[title='Send this user a private message']");
  3206. for (var i = 0; i < eleSpans.length; i++)
  3207. {
  3208. var href = eleSpans[i].parentElement.firstElementChild.getAttribute("href");
  3209. if (href && href.indexOf("user_activity.php?user=") === 0)
  3210. {
  3211. var profile = href.replace("user_activity.php?user=", "");
  3212. var ele = document.createElement("a");
  3213. ele.classList.add("stsh_steamProfile");
  3214. ele.setAttribute("target", "_blank");
  3215. ele.setAttribute("title", "View Steam profile");
  3216. ele.setAttribute("href", "http://steamcommunity.com/profiles/" + profile);
  3217. ele.textContent = " Steam ";
  3218. insertBeforeElement(ele, eleSpans[i]);
  3219. }
  3220. }
  3221. }
  3222. // Add auto approve
  3223. {
  3224. if (elesInputApprove.length > 0)
  3225. {
  3226. var eleInput = document.createElement("input");
  3227. eleInput.id = "stsh_autoApprove";
  3228. eleInput.setAttribute("type", "checkbox");
  3229. eleInput.setAttribute("value", "auto");
  3230. eleInput.textContent = "";
  3231. var eleLabel = document.createElement("label");
  3232. eleLabel.classList.add("stsh_autoApprove_label");
  3233. eleLabel.classList.add("stsh_unselectable");
  3234. eleLabel.setAttribute("for", "stsh_autoApprove");
  3235. eleLabel.setAttribute("title", "Please use with care!");
  3236. eleLabel.textContent = " Auto Approve Next ";
  3237. elesInputApprove[0].parentElement.appendChild(eleInput);
  3238. elesInputApprove[0].parentElement.appendChild(eleLabel);
  3239. function autoApprove()
  3240. {
  3241. var tm = 2000;
  3242. console.log("AutoApprove: Next in " + tm + "ms");
  3243. setTimeoutCustom(function ()
  3244. {
  3245. var eleCheck = document.querySelector("#stsh_autoApprove");
  3246. if (eleCheck && eleCheck.checked)
  3247. {
  3248. var isClicked = false;
  3249. var ele = document.querySelector(".stsh_action_approve_next");
  3250. if (ele && !ele.disabled && isVisible())
  3251. {
  3252. var isOutdated = false;
  3253. var eleSugComment = ele.parentElement
  3254. .parentElement.parentElement.querySelector(".stsh_text_comment font");
  3255. if (eleSugComment && eleSugComment.textContent.trim() ==
  3256. "ATTENTION - English string was updated. This suggestion might be outdated.")
  3257. {
  3258. isOutdated = true;
  3259. }
  3260. if (!isOutdated)
  3261. {
  3262. isClicked = true;
  3263. GM_setValue("timeAutoApproveLast", getUnixTimestamp());
  3264. ele.click();
  3265. }
  3266. }
  3267. if (!isClicked)
  3268. {
  3269. eleCheck.checked = false;
  3270. GM_setValue("isAutoApprove", "false");
  3271. }
  3272. }
  3273. }, tm);
  3274. }
  3275. var tmDiff = getUnixTimestamp() - GM_getValue("timeAutoApproveLast", 0);
  3276. if (tmDiff > 10)
  3277. {
  3278. // > 10s
  3279. eleInput.checked = false;
  3280. GM_setValue("isAutoApprove", "false");
  3281. }
  3282. if (window !== window.parent)
  3283. {
  3284. var eleOuter = window.parent.document.querySelector("#suggestions_box_outer");
  3285. if (eleOuter)
  3286. {
  3287. if (eleOuter.style.display === "none")
  3288. {
  3289. // Closed iFrame
  3290. eleInput.checked = false;
  3291. GM_setValue("isAutoApprove", "false");
  3292. }
  3293. }
  3294. }
  3295. if (GM_getValue("isAutoApprove", 0) === "true")
  3296. {
  3297. eleInput.checked = true;
  3298. autoApprove();
  3299. }
  3300.  
  3301. eleInput.addEventListener("click", function (e)
  3302. {
  3303. var ele = e.target;
  3304. if (ele.checked)
  3305. {
  3306. GM_setValue("isAutoApprove", "true");
  3307. autoApprove();
  3308. }
  3309. else
  3310. {
  3311. GM_setValue("isAutoApprove", "false");
  3312. }
  3313. });
  3314. }
  3315. }
  3316. // Warn when remove
  3317. // Suggest to remove
  3318. // Add remove & next
  3319. {
  3320. var canNext = !!(document.querySelector(".stsh_nav_next:not(:disabled)"));
  3321. var elesRemove = document.querySelectorAll(".stsh_action_remove");
  3322. for (var i = 0; i < elesRemove.length; i++)
  3323. {
  3324. var isDisabled = false;
  3325. var oldClick = elesRemove[i].getAttribute("onclick");
  3326. if (oldClick && oldClick.indexOf("location.href") === 0)
  3327. {
  3328. var eleSug = elesRemove[i].parentElement.parentElement.parentElement.parentElement;
  3329. if (eleSug.classList.contains("suggestion"))
  3330. {
  3331. /*
  3332. // Typonion
  3333. var eleOnion = eleSug.querySelector(".suggestion_text font[style='color:#01ec00;']");
  3334. if (eleOnion)
  3335. {
  3336. var newClick = "if (!confirm(\"Warning: You will delete your onion. Press Cancel to go back.\")) return false; "
  3337. + oldClick;
  3338. elesRemove[i].setAttribute("onclick", newClick);
  3339. elesRemove[i].setAttribute("title", "Do not remove your onion!");
  3340. elesRemove[i].style.color = "#777";
  3341. elesRemove[i].style.cursor = "not-allowed";
  3342. }
  3343. else
  3344. */
  3345. {
  3346. var eleComment = elesRemove[i].previousElementSibling.previousElementSibling;
  3347. if (eleComment)
  3348. {
  3349. // Mod comment
  3350. if (eleComment.textContent.trim().indexOf("Comment:") === 0)
  3351. {
  3352. // Mod commented, suggest to do not remove
  3353. var newClick = "if (!confirm(\"Warning: You should not remove this suggestion."
  3354. + " Press OK if you really want.\")) return false; "
  3355. + oldClick;
  3356. elesRemove[i].setAttribute("onclick", newClick);
  3357. elesRemove[i].setAttribute("title",
  3358. "Your suggestion has a mod's comment! Should not remove this suggestion.");
  3359. elesRemove[i].classList.add("stsh_grey");
  3360. elesRemove[i].classList.add("stsh_cursor_notallowed");
  3361. isDisabled = true;
  3362. }
  3363. else
  3364. {
  3365. // No mod comment, suggest to remove
  3366. elesRemove[i].setAttribute("title",
  3367. "Please remove this suggestion to save admin time.");
  3368. elesRemove[i].classList.add("stsh_green");
  3369. elesRemove[i].classList.add("stsh_border_green");
  3370. }
  3371. }
  3372. else
  3373. {
  3374. eleComment = elesRemove[i].parentElement.parentElement.previousElementSibling;
  3375. if (eleComment.tagName === "I")
  3376. {
  3377. // User comment
  3378. var comment = eleComment.textContent.trim();
  3379. if (comment.indexOf("ATTENTION - English string was updated.") > -1)
  3380. {
  3381. // Outdated, suggest to edit and remove
  3382. elesRemove[i].setAttribute("title",
  3383. "Please edit and remove this outdated suggestion.");
  3384. elesRemove[i].classList.add("stsh_green");
  3385. elesRemove[i].classList.add("stsh_border_green");
  3386. isDisabled = true;
  3387. }
  3388. }
  3389. }
  3390. }
  3391. }
  3392. }
  3393. // Add remove & next
  3394. {
  3395. elesRemove[i].classList.add("stsh_border_left");
  3396. var eleNext = document.createElement("input");
  3397. eleNext.value = "Next";
  3398. eleNext.classList.add("stsh_action_remove_next");
  3399. eleNext.classList.add("stsh_border_right");
  3400. eleNext.setAttribute("type", "button");
  3401. if (canNext && !isDisabled)
  3402. {
  3403. eleNext.title = "Remove & Next";
  3404. var onclick = elesRemove[i].getAttribute("onclick")
  3405. .replace("';", "&ynext=true';");
  3406. eleNext.setAttribute("onclick", onclick);
  3407. eleNext.classList.add("stsh_yellow_light");
  3408. }
  3409. else
  3410. {
  3411. eleNext.disabled = true;
  3412. }
  3413. insertAfterElement(eleNext, elesRemove[i]);
  3414. }
  3415. }
  3416. }
  3417. // Suggest to decline outdated
  3418. {
  3419. if (document.querySelector(".stsh_action_approve"))
  3420. {
  3421. var elesAttention = document.querySelectorAll(".stsh_text_comment > font > i > b");
  3422. for (var i = 0; i < elesAttention.length; i++)
  3423. {
  3424. if (elesAttention[i].textContent.trim()
  3425. === "ATTENTION - English string was updated. This suggestion might be outdated.")
  3426. {
  3427. var eleAction = elesAttention[i]
  3428. .parentElement.parentElement
  3429. .parentElement.parentElement
  3430. .nextElementSibling;
  3431. var eleApprove = eleAction.querySelector(".stsh_action_approve");
  3432. var eleApproveNext = null;
  3433. var eleDecline = null;
  3434. if (eleApprove)
  3435. {
  3436. eleApproveNext = eleApprove.nextElementSibling;
  3437. var oldClick = eleApprove.getAttribute("onclick");
  3438. if (oldClick && oldClick.indexOf("location.href") === 0)
  3439. {
  3440. var newClick = "if (!confirm(\"Warning: Please decline outdated suggestion."
  3441. + " Press OK if you really want to approve.\")) return false; "
  3442. + oldClick;
  3443. eleApprove.setAttribute("onclick", newClick);
  3444. eleApprove.setAttribute("title", "Please decline outdated suggestion.");
  3445. eleApprove.classList.add("stsh_grey");
  3446. eleApprove.classList.add("stsh_cursor_notallowed");
  3447. }
  3448. }
  3449. if (eleApproveNext)
  3450. {
  3451. eleDecline = eleApproveNext.nextElementSibling;
  3452. if (!eleApproveNext.disabled)
  3453. {
  3454. var oldClick = eleApproveNext.getAttribute("onclick");
  3455. if (oldClick && oldClick.indexOf("location.href") === 0)
  3456. {
  3457. var newClick = "if (!confirm(\"Warning: Please decline outdated suggestion."
  3458. + " Press OK if you really want to approve.\")) return false; "
  3459. + oldClick;
  3460. eleApproveNext.setAttribute("onclick", newClick);
  3461. eleApproveNext.setAttribute("title", "Please decline outdated suggestion.");
  3462. eleApproveNext.classList.add("stsh_grey");
  3463. eleApproveNext.classList.add("stsh_cursor_notallowed");
  3464. }
  3465. }
  3466. }
  3467. if (eleDecline)
  3468. {
  3469. eleDecline.setAttribute("title", "Please decline outdated suggestion.");
  3470. eleDecline.classList.add("stsh_green");
  3471. eleDecline.classList.add("stsh_border_green_left");
  3472. }
  3473. }
  3474. }
  3475. }
  3476. }
  3477. // Clean language markers that link to Steam
  3478. {
  3479. var rgxLang = /\?l=[a-z]+$/i;
  3480. var elesFriend = document.querySelectorAll(".friend_block_discussions");
  3481. for (var i = 0; i < elesFriend.length; i++)
  3482. {
  3483. var eleDiscuss = elesFriend[i].parentElement.nextElementSibling;
  3484. if (!eleDiscuss.querySelector("font[style='color:#EDB687;']"))
  3485. {
  3486. var elesA = eleDiscuss.querySelectorAll("a[href*='steam']");
  3487. for (var j = 0; j < elesA.length; j++)
  3488. {
  3489. var href = elesA[j].getAttribute("href");
  3490. if (rgxLang.test(href))
  3491. {
  3492. elesA[j].setAttribute("href", href.replace(rgxLang, ""));
  3493. }
  3494. }
  3495. }
  3496. }
  3497. }
  3498. // Auto paste last suggestion
  3499. {
  3500. if (!/edit/i.test(getQueryByName("action")))
  3501. {
  3502. //var eleTextOrg = document.querySelector(".stsh_text_org");
  3503. if (eleTextOrg)
  3504. {
  3505. var textOrg = trimSpace(eleTextOrg.innerHTML).toLowerCase();
  3506. if (textOrg === GM_getValue("textLastOrg", ""))
  3507. {
  3508. var eleTextCur = document.querySelector("#suggestion_value_new");
  3509. if (eleTextCur)
  3510. {
  3511. var textLastCur = GM_getValue("textLastCur", "");
  3512. if (textLastCur !== "")
  3513. {
  3514. eleTextCur.value = textLastCur;
  3515. }
  3516. }
  3517. setTimeoutCustom(function()
  3518. {
  3519. var eleTextCur = document.querySelector("#suggestion_value_new");
  3520. if (eleTextCur)
  3521. {
  3522. var textLastCur = GM_getValue("textLastCur", "");
  3523. if (textLastCur !== "")
  3524. {
  3525. eleTextCur.value = textLastCur;
  3526. }
  3527. }
  3528. }, 250);
  3529. }
  3530. }
  3531. }
  3532. var elesTextSubmit = document.querySelectorAll(".stsh_text_submit, #stsh_submit_suggestion_next");
  3533. for (var i = 0; i < elesTextSubmit.length; i++)
  3534. {
  3535. elesTextSubmit[i].addEventListener("click", function()
  3536. {
  3537. var eleTextOrg = document.querySelector(".stsh_text_org");
  3538. if (eleTextOrg)
  3539. {
  3540. var textOrg = trimSpace(eleTextOrg.innerHTML);
  3541. if (textOrg.length < 1000)
  3542. {
  3543. var eleTextCur = document.querySelector("#suggestion_value_new");
  3544. if (eleTextCur)
  3545. {
  3546. var textCur = eleTextCur.value;
  3547. GM_setValue("textLastOrg", textOrg.toLowerCase());
  3548. GM_setValue("textLastCur", textCur);
  3549. }
  3550. }
  3551. }
  3552. });
  3553. }
  3554. }
  3555. // Auto store last comment
  3556. {
  3557. //console.log("textLastOrg_Comment: " + GM_getValue("textLastOrg_Comment", ""));
  3558. //console.log("textLastCur_Comment: " + GM_getValue("textLastCur_Comment", ""));
  3559. function storeLastComment(eleTextComment, isRemoved)
  3560. {
  3561. if (eleTextComment)
  3562. {
  3563. var eleTextOrg = document.querySelector(".stsh_text_org");
  3564. if (eleTextOrg)
  3565. {
  3566. var textOrg = trimSpace(eleTextOrg.innerHTML).substr(0, 1000).toLowerCase();
  3567. if (isRemoved)
  3568. {
  3569. if (textOrg === GM_getValue("textLastOrg_Comment", ""))
  3570. {
  3571. // When remove comment, don't store if original text is the same
  3572. return;
  3573. }
  3574. }
  3575. var textCur = trimSpace(eleTextComment.value || eleTextComment.textContent);
  3576. if (textCur !== "outdated")
  3577. {
  3578. GM_setValue("textLastOrg_Comment", textOrg);
  3579. GM_setValue("textLastCur_Comment", textCur);
  3580. }
  3581. }
  3582. }
  3583. }
  3584. var elesTextRemoveComment = document.querySelectorAll(".stsh_text_removeComment");
  3585. for (var i = 0; i < elesTextRemoveComment.length; i++)
  3586. {
  3587. elesTextRemoveComment[i].addEventListener("click", function(ev)
  3588. {
  3589. var target = null;
  3590. if (ev.target.tagName === "FONT")
  3591. {
  3592. target = ev.target.parentElement;
  3593. }
  3594. else
  3595. {
  3596. target = ev.target;
  3597. }
  3598. var eleTextComment = target
  3599. .parentElement.parentElement.parentElement.parentElement
  3600. .querySelector(".stsh_text_comment");
  3601. storeLastComment(eleTextComment, true);
  3602. });
  3603. }
  3604. var elesSubmitComment = document.querySelectorAll(".stsh_submit_comment");
  3605. for (var i = 0; i < elesSubmitComment.length; i++)
  3606. {
  3607. elesSubmitComment[i].addEventListener("click", function(ev)
  3608. {
  3609. var eleTextComment = ev.target.previousElementSibling;
  3610. if (eleTextComment.tagName !== "TEXTAREA")
  3611. {
  3612. eleTextComment = eleTextComment.previousElementSibling;
  3613. }
  3614. storeLastComment(eleTextComment, false);
  3615. });
  3616. }
  3617. }
  3618. // Mark showing
  3619. {
  3620. var eleStatus = window.parent.document.querySelector("#stsh_showing_random");
  3621. if (eleStatus)
  3622. {
  3623. eleStatus.dataset.random = getTimeMs();
  3624. }
  3625. }
  3626. // Delta
  3627. {
  3628. var eleFile = document.querySelector(".stsh_info_file");
  3629. if (eleFile)
  3630. {
  3631. if (eleFile.textContent.trim() === "STEAM/DELTA")
  3632. {
  3633. document.body.classList.add("stsh_delta");
  3634. }
  3635. }
  3636. }
  3637. // Clean link remove my comment
  3638. {
  3639. var elesRemoveMyComment = document.querySelectorAll(
  3640. ".suggestion_signature .lbAction[name^='myFrm'] a[onclick*='.submit()']");
  3641. for (var i = 0; i < elesRemoveMyComment.length; i++)
  3642. {
  3643. elesRemoveMyComment[i].removeAttribute("href");
  3644. elesRemoveMyComment[i].classList.add("stsh_text_removeMyComment");
  3645. }
  3646. }
  3647. // Hide cursor when typing
  3648. // Expand textarea when typing
  3649. {
  3650. var tmTextChange = 0;
  3651. function autoHideCursor(ele)
  3652. {
  3653. if (ele)
  3654. {
  3655. ele.addEventListener("input", function(ev)
  3656. {
  3657. var ele = ev.target;
  3658. ele.style.setProperty("cursor", "none", "important");
  3659. clearTimeout(tmTextChange);
  3660. tmTextChange = setTimeoutCustom(function(ele)
  3661. {
  3662. ele.style.setProperty("cursor", "auto", "important");
  3663. }, 3000, ele);
  3664. });
  3665. ele.addEventListener("mousemove", function(ev)
  3666. {
  3667. var ele = ev.target;
  3668. clearTimeout(tmTextChange);
  3669. ele.style.setProperty("cursor", "auto", "important");
  3670. });
  3671. }
  3672. }
  3673. function autoExpandEvent(ev)
  3674. {
  3675. var ele = ev.target;
  3676. var maxHeight = ele.param_MaxHeight;
  3677. var styleHeight = parseInt(ele.style.height)
  3678. || parseInt(window.getComputedStyle(ele).height)
  3679. || maxHeight;
  3680. var heightDiff = ele.scrollHeight - styleHeight;
  3681. //console.log("ele.scrollHeight:"+ele.scrollHeight+", styleHeight:"+styleHeight+", heightDiff:"+heightDiff);
  3682. // When press a button
  3683. // Chrome: heightDiff === 4
  3684. // Firefox: heightDiff === 0
  3685. if ((heightDiff > 0 && heightDiff !== 4) && ele.scrollHeight < maxHeight)
  3686. {
  3687. ele.style.height = (ele.scrollHeight + 2) + "px";
  3688. }
  3689. else if (ele.scrollHeight > maxHeight && ele.scrollHeight - maxHeight < 100)
  3690. {
  3691. ele.style.height = maxHeight + "px";
  3692. }
  3693. }
  3694. function autoExpandEventTextarea(ele, maxHeight)
  3695. {
  3696. if (ele)
  3697. {
  3698. ele.param_MaxHeight = maxHeight;
  3699. ele.addEventListener("input", autoExpandEvent);
  3700. ele.addEventListener("keyup", autoExpandEvent);
  3701. }
  3702. }
  3703. var elesTextarea = document.querySelectorAll("textarea");
  3704. for (var i = 0; i < elesTextarea.length; i++)
  3705. {
  3706. autoExpandEventTextarea(elesTextarea[i], 500);
  3707. autoHideCursor(elesTextarea[i]);
  3708. }
  3709. }
  3710. // Focus on mod action
  3711. {
  3712. var elesFormRemoveComment = document.querySelectorAll(".suggestion_signature .lbAction[name^='mymodcomment']");
  3713. for (var i = 0; i < elesFormRemoveComment.length; i++)
  3714. {
  3715. var action = elesFormRemoveComment[i].getAttribute("action");
  3716. if (action.indexOf("#stsh_modcomment") < 0)
  3717. {
  3718. elesFormRemoveComment[i].setAttribute("action", action + "#stsh_modcomment");
  3719. }
  3720. }
  3721. var elesSubmitComment = document.querySelectorAll(
  3722. ".suggestion_signature > div > div > .copy > form > div > .stsh_submit_comment");
  3723. for (var i = 0; i < elesSubmitComment.length; i++)
  3724. {
  3725. var eleForm = elesSubmitComment[i].parentElement.parentElement;
  3726. if (eleForm.tagName === "FORM")
  3727. {
  3728. var action = eleForm.getAttribute("action");
  3729. if (action.indexOf("#stsh_modcomment") < 0)
  3730. {
  3731. eleForm.setAttribute("action", action + "#stsh_modcomment");
  3732. }
  3733. }
  3734. }
  3735. if (/reconsider|approve|decline/i.test(getQueryByName("action")) || url.indexOf("#stsh_modcomment") > -1)
  3736. {
  3737. setTimeoutCustom(function()
  3738. {
  3739. if (eleTextNew.scrollHeight > 480 || eleTextOrg.scrollHeight > 480)
  3740. {
  3741. scrollToElement(".suggestions_list", -40);
  3742. }
  3743. else if (eleTextNew.scrollHeight > 110 || eleTextOrg.scrollHeight > 200)
  3744. {
  3745. var elesEdit = document.querySelectorAll(".stsh_action_edit");
  3746. if (elesEdit.length > 1)
  3747. {
  3748. scrollToElement(".suggestions_list", -40);
  3749. }
  3750. }
  3751. }, 200);
  3752. }
  3753. }
  3754. // Add char and word count
  3755. {
  3756. function countCharWord(ele)
  3757. {
  3758. var countChar = 0;
  3759. var countWord = 0;
  3760. if (ele)
  3761. {
  3762. var text = ele.value || (ele.value === "" ? "" : ele.textContent);
  3763. countChar = text.length;
  3764. var arrWord = trimSpace(text).split(/\s+/);
  3765. if (arrWord.length === 1)
  3766. {
  3767. if (trimSpace(arrWord[0]).length > 0)
  3768. {
  3769. countWord = 1;
  3770. }
  3771. }
  3772. else
  3773. {
  3774. countWord = arrWord.length;
  3775. }
  3776. }
  3777. return "Char: " + countChar + " :: Word: " + countWord;
  3778. }
  3779. var elesText = document.querySelectorAll("#suggestion_value_new, .stsh_text_addComment, #add_to_discussion");
  3780. for (var i = 0; i < elesText.length; i++)
  3781. {
  3782. var eleCounter = document.createElement("div");
  3783. eleCounter.classList.add("stsh_counter");
  3784. eleCounter.classList.add("stsh_blue_light");
  3785. eleCounter.dataset.counter = countCharWord(elesText[i]);
  3786. eleCounter.title = "Chars and words are approximate values";
  3787. insertAfterElement(eleCounter, elesText[i]);
  3788. elesText[i].addEventListener("input", function(ev)
  3789. {
  3790. var eleTarget = ev.target;
  3791. var eleCounter = eleTarget.nextElementSibling;
  3792. if (eleCounter && eleCounter.classList.contains("stsh_counter"))
  3793. {
  3794. eleCounter.dataset.counter = countCharWord(eleTarget);
  3795. }
  3796. });
  3797. }
  3798. elesText = document.querySelectorAll(".stsh_text_org, .stsh_text_trn:not(.stsh_text_trn_empty), .suggestion_text");
  3799. for (var i = 0; i < elesText.length; i++)
  3800. {
  3801. ////
  3802. }
  3803. }
  3804. // Add events mark edited
  3805. {
  3806. if (window !== window.parent)
  3807. {
  3808. var eleOuter = window.parent.document.querySelector("#suggestions_box_outer");
  3809. if (eleOuter)
  3810. {
  3811. eleOuter.dataset.stshTextEdited = "false";
  3812. eleOuter.title = "";
  3813. var markEdited = function(ev)
  3814. {
  3815. if (!ev.ctrlKey && !ev.altKey)
  3816. {
  3817. if (eleOuter && eleOuter.dataset)
  3818. {
  3819. eleOuter.dataset.stshTextEdited = "true";
  3820. eleOuter.title = "When some texts were edited. \nYou must double click to close suggestion box.";
  3821. removeEventsMarkEdited();
  3822. }
  3823. }
  3824. };
  3825. var removeEventsMarkEdited = function()
  3826. {
  3827. var elesText = document.querySelectorAll("#suggestion_value_new, .stsh_text_addComment, #add_to_discussion");
  3828. for (var i = 0; i < elesText.length; i++)
  3829. {
  3830. elesText[i].removeEventListener("keydown", markEdited);
  3831. }
  3832. };
  3833. var elesText = document.querySelectorAll("#suggestion_value_new, .stsh_text_addComment, #add_to_discussion");
  3834. for (var i = 0; i < elesText.length; i++)
  3835. {
  3836. elesText[i].addEventListener("keydown", markEdited);
  3837. }
  3838. }
  3839. }
  3840. }
  3841. } // End suggestions.php
  3842.  
  3843. if (url.indexOf("translate.php") > -1)
  3844. {
  3845. var searchText = getQueryByName("search_input");
  3846. if (searchText !== "")
  3847. {
  3848. document.title = searchText + " - " + document.title;
  3849. }
  3850. else
  3851. {
  3852. var fileID = getQueryByName("file_ID");
  3853. if (fileID !== "")
  3854. {
  3855. var eleFile = document.querySelector("#leftAreaContainer label[for='chosenfile']");
  3856. if (eleFile)
  3857. {
  3858. var file = eleFile.textContent.trim();
  3859. if (file.indexOf("Limit search results to CURRENT FILE: ") === 0)
  3860. {
  3861. file = file.replace("Limit search results to CURRENT FILE: ", "");
  3862. var fileNew = file.split("#").reverse().join(" # ").trim();
  3863. document.title = fileNew + " - " + document.title;
  3864. }
  3865. }
  3866. }
  3867. else
  3868. {
  3869. var eleInput = document.querySelector("#search_input");
  3870. if (eleInput)
  3871. {
  3872. var valInput = eleInput.value.trim();
  3873. if (valInput.indexOf("SUGGESTIONS FROM: ") === 0)
  3874. {
  3875. document.title = valInput.replace("SUGGESTIONS FROM: ", "") + " - " + document.title;
  3876. }
  3877. }
  3878. }
  3879. }
  3880. var outer = document.querySelector("#suggestions_box_outer");
  3881. if (outer)
  3882. {
  3883. outer.setAttribute("onclick", "doubleClickHideSuggestion(this);");
  3884. outer.dataset.stshHideSuggestion = 0;
  3885. outer.dataset.stshTextEdited = "false";
  3886. }
  3887. var divBtn = document.createElement("div");
  3888. document.body.appendChild(divBtn);
  3889. divBtn.innerHTML =
  3890. ' \
  3891. <div class="stsh_showing_group"> \
  3892. <span class="stsh_showing_header">Hide</span>\
  3893. <br/> &nbsp; <input id="stsh_showing_keyApp" value="App" data-hidekey="0" class="stsh_btn_short stsh_showing_key" type="button" /> \
  3894. <input id="stsh_showing_keyGame" value="Game" data-hidekey="1" class="stsh_btn_short stsh_showing_key" type="button" /> \
  3895. <br/> &nbsp; <input id="stsh_showing_keyFaq" value="FAQ" data-hidekey="2" class="stsh_btn_short stsh_showing_key" type="button" /> \
  3896. <input id="stsh_showing_keySupport" value="Support" data-hidekey="3" class="stsh_btn_short stsh_showing_key" type="button" /> \
  3897. <br/> &nbsp; <input id="stsh_showing_keyPromo" value="Promo" data-hidekey="4" class="stsh_btn_short stsh_showing_key" type="button" /> \
  3898. <input id="stsh_showing_keyEmail" value="Email" data-hidekey="5" class="stsh_btn_short stsh_showing_key" type="button" /> \
  3899. <br/> \
  3900. <br/> &nbsp; <input id="stsh_showing_strNotMatch" value="Hide not similar" data-hidestr="0" class="stsh_btn_long stsh_showing_str" type="button" /> \
  3901. <br/> &nbsp; <input id="stsh_showing_strLong" value="Hide very long" data-hidestr="1" class="stsh_btn_long stsh_showing_str" type="button" /> \
  3902. \
  3903. <br/> &nbsp; <span class="stsh_showing_header">Hide Suggestions</span>\
  3904. <br/> &nbsp; <input id="stsh_showing_notTranslated" value="Not Translated (0)" data-hidestatus="0" class="stsh_btn_long stsh_showing_status" type="button" /> \
  3905. <br/> &nbsp; <input id="stsh_showing_suggested" value="Suggested (0)" data-hidestatus="1" class="stsh_btn_long stsh_showing_status" type="button" /> \
  3906. <br/> &nbsp; <input id="stsh_showing_resuggested" value="Resuggested (0)" data-hidestatus="2" class="stsh_btn_long stsh_showing_status" type="button" /> \
  3907. <br/> &nbsp; <input id="stsh_showing_approved" value="Approved (0)" data-hidestatus="3" class="stsh_btn_long stsh_showing_status" type="button" /> \
  3908. <br/> &nbsp; <input id="stsh_showing_declined" value="Declined (0)" data-hidestatus="4" class="stsh_btn_long stsh_showing_status" type="button" /> \
  3909. <br/> &nbsp; <input id="stsh_showing_translated" value="Translated (0)" data-hidestatus="5" class="stsh_btn_long stsh_showing_status" type="button" /> \
  3910. \
  3911. <br/> &nbsp; <span class="stsh_showing_header">Sort by</span>\
  3912. <br/> &nbsp; <input id="stsh_sort_key" value="Key" data-sort="0" class="stsh_btn_short stsh_sort" type="button" /> \
  3913. <input id="stsh_sort_string" value="String" data-sort="1" class="stsh_btn_short stsh_sort" type="button" /> \
  3914. <br/> &nbsp; <input id="stsh_sort_word" value="Word" data-sort="2" class="stsh_btn_short stsh_sort" type="button" /> \
  3915. <input id="stsh_sort_length" value="Length" data-sort="3" class="stsh_btn_short stsh_sort" type="button" /> \
  3916. <br/> \
  3917. <br/> &nbsp; <input id="stsh_showing_refresh" value="Refresh" class="stsh_btn" type="button" onclick="hideSuggestionsBox(); return false;" /> \
  3918. <br/> &nbsp; <input id="stsh_showing_all" value="Show All" class="stsh_btn" type="button" /> \
  3919. <br/> \
  3920. </div> \
  3921. <div id="stsh_showing_current"></div> \
  3922. <div id="stsh_showing"></div> \
  3923. ';
  3924.  
  3925. // Count showing
  3926. function countShowing()
  3927. {
  3928. var trKeys = document.querySelectorAll("#keylist > table:nth-child(1) > tbody:nth-child(1) > tr");
  3929. var countAll = document.querySelectorAll("#keylist .copysmall").length;
  3930. var countShow = 0;
  3931. var countSuggest = 0;
  3932. var countResuggest = 0;
  3933. var countApprove = 0;
  3934. var countDecline = 0;
  3935. var countNotTranslated = 0;
  3936. var countTranslated = 0;
  3937. var txtApprove = "ready for Admin";
  3938. var txtDecline = "ready for removal";
  3939. var txtSuggest = "suggestion";
  3940. for (var i = 0; i < trKeys.length; i++)
  3941. {
  3942. if (!trKeys[i].classList.contains("stsh_hidden"))
  3943. {
  3944. var eleCounter = trKeys[i].querySelector("tr.copysmall > td:nth-child(3)");
  3945. if (eleCounter)
  3946. {
  3947. countShow++;
  3948. var txtCounter = eleCounter.textContent.trim();
  3949. if (txtCounter.indexOf(txtApprove) > -1)
  3950. {
  3951. countApprove++;
  3952. }
  3953. else if (txtCounter.indexOf(txtDecline) > -1)
  3954. {
  3955. countDecline++;
  3956. }
  3957. else if (txtCounter.indexOf(txtSuggest) > -1)
  3958. {
  3959. var eleNotTranslated = trKeys[i].querySelector("span.token_nottranslated");
  3960. if (eleNotTranslated)
  3961. {
  3962. countSuggest++;
  3963. }
  3964. else
  3965. {
  3966. countResuggest++;
  3967. }
  3968. }
  3969. else
  3970. {
  3971. var eleNotTranslated = trKeys[i].querySelector("span.token_nottranslated");
  3972. if (eleNotTranslated)
  3973. {
  3974. countNotTranslated++;
  3975. }
  3976. else
  3977. {
  3978. countTranslated++;
  3979. }
  3980. }
  3981. }
  3982. else
  3983. {
  3984. var eleTd = trKeys[i].querySelector("td");
  3985. if (eleTd)
  3986. {
  3987. if (eleTd.textContent.trim() === "")
  3988. {
  3989. trKeys[i].parentElement.removeChild(trKeys[i]);
  3990. }
  3991. }
  3992. }
  3993. }
  3994. }
  3995. var eleShowing = document.querySelector("#stsh_showing");
  3996. if (eleShowing)
  3997. {
  3998. var newHtml = "Showing: <span class=\"stsh_showing_counter\">" + countShow + " of " + countAll + "</span>"
  3999. + "<!-- " + countNotTranslated + ", " + countSuggest + ", " + countResuggest
  4000. + ", " + countApprove + ", " + countDecline + ", " + countTranslated + " -->";
  4001. if (eleShowing.innerHTML !== newHtml)
  4002. {
  4003. eleShowing.innerHTML = newHtml;
  4004.  
  4005. var elesBtnShowingStatus = document.querySelectorAll(".stsh_showing_status");
  4006. if (elesBtnShowingStatus.length === 6)
  4007. {
  4008. var counterArr = [countNotTranslated, countSuggest, countResuggest
  4009. , countApprove, countDecline, countTranslated ];
  4010. var counterTextArr = ["Not Translated", "Suggested", "Resuggested"
  4011. , "Approved", "Declined", "Translated" ];
  4012.  
  4013. for (var i = 0; i < elesBtnShowingStatus.length; i++)
  4014. {
  4015. elesBtnShowingStatus[i].value = counterTextArr[i] + " ("+ counterArr[i] +")" ;
  4016. };
  4017. }
  4018. }
  4019. }
  4020. var eleShowingCur = document.querySelector("#stsh_showing_current");
  4021. if (eleShowingCur)
  4022. {
  4023. var eleOuter = document.querySelector("#suggestions_box_outer");
  4024. if (eleOuter)
  4025. {
  4026. if (eleOuter.style.display !== "none")
  4027. {
  4028. if (eleShowingCur.style.display !== "initial")
  4029. eleShowingCur.style.display = "initial";
  4030. var eleIframe = document.querySelector("#suggestions_iframe");
  4031. if (eleIframe)
  4032. {
  4033. var iUrl = eleIframe.contentWindow.location.href;
  4034. var listId = parseInt(getQueryByName("list_id", iUrl)) || 0;
  4035. listId += 1;
  4036. var newHtml = "Current: <span class=\"stsh_showing_counter\">" + listId + " of " + countShow + "</span>";
  4037. if (eleShowingCur.innerHTML !== newHtml)
  4038. {
  4039. eleShowingCur.innerHTML = newHtml;
  4040. }
  4041. }
  4042. }
  4043. else
  4044. {
  4045. if (eleShowingCur.style.display !== "none")
  4046. {
  4047. eleShowingCur.style.display = "none";
  4048. eleShowingCur.innerHTML = "";
  4049. }
  4050. }
  4051. }
  4052. }
  4053. }
  4054. countShowing();
  4055. var obTarget_count = document.querySelector("#keylist_container");
  4056. if (obTarget_count)
  4057. {
  4058. var tmOb_count = -1;
  4059. var obMu_count = new MutationObserver(function(mutations)
  4060. {
  4061. mutations.forEach(function(mutation)
  4062. {
  4063. if (mutation.type !== "attributes"
  4064. || mutation.target.tagName === "TR")
  4065. {
  4066. clearTimeout(tmOb_count);
  4067. tmOb_count = setTimeoutCustom(function(mutation)
  4068. {
  4069. countShowing();
  4070. //console.log("countShowing: " + tmOb_count);
  4071. }, 50, mutation);
  4072. }
  4073. });
  4074. });
  4075. var obConfig_count = { childList: true, subtree: true, attributes: true, attributeFilter: ["class"] };
  4076. obMu_count.observe(obTarget_count, obConfig_count);
  4077. }
  4078. // Waiting for iframe
  4079. {
  4080. var obTarget_countRand = document.createElement("div");
  4081. obTarget_countRand.id = "stsh_showing_random";
  4082. obTarget_countRand.dataset.random = "0";
  4083. document.body.appendChild(obTarget_countRand);
  4084. var obMu_countRand = new MutationObserver(function(mutations)
  4085. {
  4086. mutations.forEach(function(mutation)
  4087. {
  4088. countShowing();
  4089. });
  4090. });
  4091.  
  4092. var obConfig_countRand = { attributes: true, attributeFilter: ["data-random"] };
  4093. obMu_countRand.observe(obTarget_countRand, obConfig_countRand);
  4094. }
  4095. // End Count showing
  4096.  
  4097. // Line Counter
  4098. function addLineCounter()
  4099. {
  4100. var elesCounter = document.querySelectorAll(".stsh_lineCounter");
  4101. if (elesCounter.length > 0)
  4102. {
  4103. var j = 1;
  4104. for (var i = 0; i < elesCounter.length; i++)
  4105. {
  4106. if (!elesCounter[i].parentElement.parentElement.parentElement
  4107. .parentElement.classList.contains("stsh_hidden"))
  4108. {
  4109. if (elesCounter[i].textContent.trim() != j)
  4110. {
  4111. // Compare string with int using loose equality
  4112. elesCounter[i].textContent = j;
  4113. }
  4114. j++;
  4115. }
  4116. }
  4117. }
  4118. else
  4119. {
  4120. var elesDiv = document.querySelectorAll("#keylist td:nth-child(1) > div");
  4121. for (var i = 0; i < elesDiv.length; i++)
  4122. {
  4123. var eleNew = document.createElement("span");
  4124. eleNew.classList.add("stsh_lineCounter_outer");
  4125. eleNew.innerHTML =
  4126. ' <span class="stsh_lineCounter"> ' + (i + 1) + ' </span> ';
  4127. elesDiv[i].appendChild(eleNew);
  4128. }
  4129. }
  4130. }
  4131. addLineCounter();
  4132. var obTarget_line = document.querySelector("#keylist_container");
  4133. if (obTarget_line)
  4134. {
  4135. var tmOb_line = -1;
  4136. var obMu_line = new MutationObserver(function(mutations)
  4137. {
  4138. mutations.forEach(function(mutation)
  4139. {
  4140. if (mutation.type !== "attributes"
  4141. || mutation.target.tagName === "TR")
  4142. {
  4143. clearTimeout(tmOb_line);
  4144. tmOb_line = setTimeoutCustom(function(mutation)
  4145. {
  4146. addLineCounter();
  4147. //console.log("addLineCounter: " + tmOb_line);
  4148. }, 50, mutation);
  4149. }
  4150. });
  4151. });
  4152. var obConfig_line = { childList: true, subtree: true, attributes: true, attributeFilter: ["class"] };
  4153. obMu_line.observe(obTarget_line, obConfig_line);
  4154. }
  4155. // End Line Counter
  4156. // Hide & sort suggestions
  4157. {
  4158. function hideStatus(mode)
  4159. {
  4160. /*
  4161. mode:
  4162. 0: notTranslated
  4163. 1: suggested
  4164. 2: resuggested
  4165. 3: approved
  4166. 4: declined
  4167. 5: translated
  4168. */
  4169.  
  4170. //console.log("hideStatus: " + mode);
  4171. if (mode < 0 || mode > 5) return;
  4172.  
  4173. var display = "none";
  4174. var txtApprove = "ready for Admin";
  4175. var txtDecline = "ready for removal";
  4176. var txtSuggest = "suggestion";
  4177. var trKeys = document.querySelectorAll("#keylist > table:nth-child(1) > tbody:nth-child(1) > tr");
  4178. for (var i = 0; i < trKeys.length; i++)
  4179. {
  4180. if (!trKeys[i].classList.contains("stsh_hidden"))
  4181. {
  4182. var curMode = -1;
  4183.  
  4184. var eleCounter = trKeys[i].querySelector("tr.copysmall > td:nth-child(3)");
  4185. if (eleCounter)
  4186. {
  4187.  
  4188. var txtCounter = eleCounter.textContent.trim();
  4189. if (txtCounter.indexOf(txtApprove) > -1)
  4190. {
  4191. curMode = 3; // Approved
  4192. }
  4193. else if (txtCounter.indexOf(txtDecline) > -1)
  4194. {
  4195. curMode = 4; // Declined
  4196. }
  4197. else if (txtCounter.indexOf(txtSuggest) > -1)
  4198. {
  4199. var eleNotTranslated = trKeys[i].querySelector("span.token_nottranslated");
  4200. if (eleNotTranslated)
  4201. {
  4202. curMode = 1; // Suggested
  4203. }
  4204. else
  4205. {
  4206. curMode = 2; // Resuggested
  4207. }
  4208. }
  4209. else
  4210. {
  4211. var eleNotTranslated = trKeys[i].querySelector("span.token_nottranslated");
  4212. if (eleNotTranslated)
  4213. {
  4214. curMode = 0; // Not Translated
  4215. }
  4216. else
  4217. {
  4218. curMode = 5; // Translated
  4219. }
  4220. }
  4221. }
  4222.  
  4223. if (curMode === mode)
  4224. {
  4225. trKeys[i].classList.add("stsh_hidden");
  4226. }
  4227. }
  4228. }
  4229. }
  4230. function sortKey(mode)
  4231. {
  4232. /*
  4233. mode:
  4234. 0: key
  4235. 1: string
  4236. 2: word
  4237. 3: length
  4238. */
  4239. if (mode < 0) return;
  4240. var keyArr = new Array();
  4241. var valArr = new Array();
  4242. var dot = "...";
  4243. var dotLengthMinus = 0 - dot.length;
  4244. var strNotTranslated = "NOT TRANSLATED";
  4245. var strTr = "";
  4246. var eleKeys = document.querySelectorAll
  4247. (" \
  4248. #keylist > table:nth-child(1) \
  4249. > tbody:nth-child(1) > tr > td:nth-child(1) > div:nth-child(1) \
  4250. > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(1) \
  4251. ");
  4252. for (var i = 0; i < eleKeys.length; i++)
  4253. {
  4254. try
  4255. {
  4256. /*
  4257. key:
  4258. tr: is translated
  4259. sg: is suggested
  4260. dt: has dot
  4261. sb: spacebar count
  4262. sc: special char count
  4263. sp: has special char
  4264. ln: length
  4265. lt: length translated
  4266. st: spacebar count translated
  4267. */
  4268. var dot = "...";
  4269. var dotLengthMinus = 0 - dot.length;
  4270. var isDot = false;
  4271. var isSuggested = false;
  4272. var isTranslated = false;
  4273. var key = eleKeys[i].textContent.trim() + " ";
  4274. var str = "";
  4275. if (mode !== 0)
  4276. {
  4277. str = eleKeys[i].parentElement.nextSibling.nextSibling.firstElementChild.textContent.trim();
  4278. isDot = (str.substr(dotLengthMinus) === dot);
  4279. isSuggested = (eleKeys[i].nextElementSibling.nextElementSibling.textContent.trim() !== "");
  4280. strTr = eleKeys[i].parentElement.nextElementSibling.lastElementChild.textContent.trim();
  4281. isTranslated = (strTr !== strNotTranslated);
  4282. }
  4283. if (mode === 0)
  4284. {
  4285. // mode: key
  4286. if (key.indexOf("GLOSSARY") === 0)
  4287. {
  4288. key = "0" + key;
  4289. }
  4290. }
  4291. if (mode === 1)
  4292. {
  4293. // mode: string
  4294. key = (isTranslated ? "tr00_ " : "tr99_ ") + strTr
  4295. + (isSuggested ? " _sg00" : " _sg99") + " ___ " + key;
  4296. key = str + " ___ " + key;
  4297. }
  4298. else if (mode === 2)
  4299. {
  4300. // mode: word
  4301. key = (isTranslated ? "tr00_" : "tr99_")
  4302. + "st" + padZero(strTr.split(" ").length, 2) + "_"
  4303. + "lt" + padZero(strTr.length, 3) + " "
  4304. + strTr + (isSuggested ? " _sg00" : " _sg99") + " ___ " + key;
  4305. key = (isDot ? "dt99_" : "dt00_")
  4306. + "sb" + padZero(str.split(" ").length, 2)
  4307. + "_sc" + padZero(str.split(/[^a-z0-9 ]/i).length, 2)
  4308. + " ___ " + str + " ___ " + key;
  4309. }
  4310. else if (mode === 3)
  4311. {
  4312. // length
  4313. var length = 0;
  4314. if (str[0] === "<" || str[0] === "[")
  4315. {
  4316. length = str.length + 800;
  4317. }
  4318. else if (str.indexOf("<") > 0 || str.indexOf("[") > 0)
  4319. {
  4320. length = str.length + 600;
  4321. }
  4322. else
  4323. {
  4324. length = str.length;
  4325. }
  4326. key = (isTranslated ? "tr00_" : "tr99_") + "lt" + padZero(strTr.length, 3) + " "
  4327. + strTr + (isSuggested ? " _sg00" : " _sg99") + " ___ " + key;
  4328. key = (isDot ? "dt99_" : "dt00_")
  4329. + "sp" + (str.split(/[^a-z0-9]/i).length > 1 ? "99_" : "00_")
  4330. + "ln" + padZero(length, 3)
  4331. + " ___ " + str + " ___ " + key;
  4332. }
  4333. key = key.toLowerCase();
  4334. keyArr.push(key);
  4335. var eleParent = eleKeys[i].parentElement.parentElement.parentElement
  4336. .parentElement.parentElement.parentElement;
  4337. //eleParent.dataset.stshKey = key;
  4338. //console.log("Key: " + key);
  4339. valArr[key] = eleParent.outerHTML.trim();
  4340. }
  4341. catch (ex)
  4342. {
  4343. console.error("sortKey", ex.message);
  4344. }
  4345. }
  4346. var keyArrTmp = keyArr.slice();
  4347. keyArr.sort();
  4348. var isSame = true;
  4349. for (var i = 0; i < keyArr.length; i++)
  4350. {
  4351. if (keyArr[i] !== keyArrTmp[i])
  4352. {
  4353. isSame = false;
  4354. }
  4355. }
  4356. if (!isSame)
  4357. {
  4358. var eleTable = document.querySelector("#keylist > table:nth-child(1) > tbody:nth-child(1)");
  4359. if (eleTable)
  4360. {
  4361. var newInner = "";
  4362. for (var i = 0; i < keyArr.length; i++)
  4363. {
  4364. newInner += valArr[keyArr[i]];
  4365. }
  4366. eleTable.innerHTML = newInner;
  4367. }
  4368. }
  4369. }
  4370. var activeHideStatus = [0, 0, 0, 0, 0, 0];
  4371. // notTranslated, suggested, resuggested, approved, declined, translated
  4372. var activeHideKey = [0, 0, 0, 0, 0, 0];
  4373. // app, game, faq, support, promo, email
  4374. var activeHideStr = [0, 0];
  4375. // notMatch, long
  4376. var activeSort = -1;
  4377. var eleBtnShowAll = document.querySelector("#stsh_showing_all");
  4378. if (eleBtnShowAll)
  4379. {
  4380. eleBtnShowAll.addEventListener("click", function()
  4381. {
  4382. var elesBtnShowing = document.querySelectorAll(
  4383. ".stsh_showing_status, .stsh_showing_key, .stsh_showing_str");
  4384. for (var i = 0; i < elesBtnShowing.length; i++)
  4385. {
  4386. elesBtnShowing[i].disabled = false;
  4387. }
  4388. for (var i = 0; i < activeHideStatus.length; i++)
  4389. {
  4390. activeHideStatus[i] = 0;
  4391. }
  4392. for (var i = 0; i < activeHideKey.length; i++)
  4393. {
  4394. activeHideKey[i] = 0;
  4395. }
  4396. for (var i = 0; i < activeHideStr.length; i++)
  4397. {
  4398. activeHideStr[i] = 0;
  4399. }
  4400. activeSort = -1;
  4401. hideKey(-1); // Show all
  4402. countShowing();
  4403. });
  4404. }
  4405.  
  4406. var elesBtnShowingStatus = document.querySelectorAll(".stsh_showing_status");
  4407. for (var i = 0; i < elesBtnShowingStatus.length; i++)
  4408. {
  4409. elesBtnShowingStatus[i].addEventListener("click", function(ev)
  4410. {
  4411. var mode = parseInt(ev.target.dataset.hidestatus) || 0;
  4412. activeHideStatus[mode] = 1;
  4413. hideStatus(mode);
  4414. ev.target.disabled = true;
  4415. });
  4416. }
  4417. var obTarget_hider = document.querySelector("#keylist_container");
  4418. if (obTarget_hider)
  4419. {
  4420. var obMu_hider = new MutationObserver(function(mutations)
  4421. {
  4422. mutations.forEach(function(mutation)
  4423. {
  4424. //console.log("obMu_hider");
  4425. for (var i = 0; i < activeHideStatus.length; i++)
  4426. {
  4427. if (activeHideStatus[i] === 1)
  4428. {
  4429. hideStatus(i);
  4430. }
  4431. }
  4432. for (var i = 0; i < activeHideKey.length; i++)
  4433. {
  4434. if (activeHideKey[i] === 1)
  4435. {
  4436. hideKey(i);
  4437. }
  4438. }
  4439. for (var i = 0; i < activeHideStr.length; i++)
  4440. {
  4441. if (activeHideStr[i] === 1)
  4442. {
  4443. hideStr(i);
  4444. }
  4445. }
  4446. sortKey(activeSort);
  4447. });
  4448. });
  4449. var obConfig_hider = { childList: true };
  4450. obMu_hider.observe(obTarget_hider, obConfig_hider);
  4451. }
  4452.  
  4453. var elesBtnSort = document.querySelectorAll(".stsh_sort");
  4454. for (var i = 0; i < elesBtnSort.length; i++)
  4455. {
  4456. elesBtnSort[i].addEventListener("click", function(ev)
  4457. {
  4458. var mode = parseInt(ev.target.dataset.sort) || 0;
  4459. activeSort = mode;
  4460. sortKey(activeSort);
  4461. });
  4462. }
  4463.  
  4464. function setVisibleKey(startKey, visible)
  4465. {
  4466. // Use ("", true) to show all
  4467. startKey = startKey.toLowerCase();
  4468. var display = visible !== true ? "none" : "";
  4469. var eleKeys = document.querySelectorAll
  4470. (" \
  4471. #keylist > table:nth-child(1) \
  4472. > tbody:nth-child(1) > tr > td:nth-child(1) > div:nth-child(1) \
  4473. > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(1) \
  4474. ");
  4475. for (var i = 0; i < eleKeys.length; i++)
  4476. {
  4477. try
  4478. {
  4479. if (eleKeys[i].textContent.trim().toLowerCase().indexOf(startKey) > -1)
  4480. {
  4481. var eleTarget = eleKeys[i].parentElement.parentElement.parentElement
  4482. .parentElement.parentElement.parentElement;
  4483. if (visible && eleTarget.classList.contains("stsh_hidden"))
  4484. {
  4485. eleTarget.classList.remove("stsh_hidden");
  4486. }
  4487. else if (!visible && !eleTarget.classList.contains("stsh_hidden"))
  4488. {
  4489. eleTarget.classList.add("stsh_hidden");
  4490. }
  4491. }
  4492. }
  4493. catch (ex)
  4494. {
  4495. console.error("setVisibleKey", ex.message);
  4496. }
  4497. }
  4498. }
  4499. function hideKey(mode)
  4500. {
  4501. /*
  4502. mode:
  4503. -1: showAll
  4504. 0: app
  4505. 1: game
  4506. 2: faq
  4507. 3: support
  4508. 4: promo
  4509. 5: email
  4510. */
  4511. if (mode === -1) // showAll
  4512. {
  4513. setVisibleKey("", true);
  4514. }
  4515. else if (mode === 0) // app
  4516. {
  4517. setVisibleKey("# storefront_english_apps.txt #", false);
  4518. setVisibleKey("# storefront_english_main.txt # #app_", false);
  4519. setVisibleKey("# community_english.txt # SharedFiles_App_", false);
  4520. setVisibleKey("# appmgmt_english.txt #", false);
  4521. setVisibleKey("STEAM/VR", false);
  4522. }
  4523. else if (mode === 1) // game
  4524. {
  4525. setVisibleKey("GAMES/", false);
  4526. setVisibleKey("TF_", false);
  4527. }
  4528. else if (mode === 2) // faq
  4529. {
  4530. setVisibleKey("# support_faq_english.txt #", false);
  4531. }
  4532. else if (mode === 3) // support
  4533. {
  4534. setVisibleKey("# supportui_english.txt #", false);
  4535. setVisibleKey("# help_english.txt #", false);
  4536. }
  4537. else if (mode === 4) // promo
  4538. {
  4539. setVisibleKey("#promo", false);
  4540. setVisibleKey("#hardware", false);
  4541. setVisibleKey("ControllerBinding", false);
  4542. setVisibleKey("Library_Controller", false);
  4543. setVisibleKey("STEAM/HARDWARE", false);
  4544. setVisibleKey("STEAM/DELTA", false);
  4545. setVisibleKey("GAMES/KILLINGFLOOR2", false);
  4546. }
  4547. else if (mode === 5) // email
  4548. {
  4549. setVisibleKey("#email", false);
  4550. }
  4551. }
  4552. var elesBtnShowingKey = document.querySelectorAll(".stsh_showing_key");
  4553. for (var i = 0; i < elesBtnShowingKey.length; i++)
  4554. {
  4555. elesBtnShowingKey[i].addEventListener("click", function(ev)
  4556. {
  4557. var mode = parseInt(ev.target.dataset.hidekey) || 0;
  4558. activeHideKey[mode] = 1;
  4559. hideKey(mode);
  4560. ev.target.disabled = true;
  4561. });
  4562. }
  4563. function hideStr(mode)
  4564. {
  4565. /*
  4566. mode:
  4567. 0: notMatch
  4568. 1: long
  4569. */
  4570. if (mode === 0) // notMatch
  4571. {
  4572. var searchStr = decodeURIComponent(getQueryByName("search_input")).replace(/\\+/g," ").trim();
  4573. searchStr = searchStr.toLowerCase();
  4574. var eleStrs = document.querySelectorAll
  4575. (" \
  4576. #keylist \
  4577. > table:nth-child(1) > tbody:nth-child(1) > tr > td:nth-child(1) > div:nth-child(1) \
  4578. > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(2) \
  4579. ");
  4580. for (var i = 0; i < eleStrs.length; i++)
  4581. {
  4582. try
  4583. {
  4584. var valStr = eleStrs[i].children[0].textContent.trim().toLowerCase();
  4585. var valTrn = eleStrs[i].children[2].textContent.trim().toLowerCase();
  4586. if (valStr !== searchStr && valTrn !== searchStr)
  4587. {
  4588. var eleTarget = eleStrs[i].parentElement.parentElement
  4589. .parentElement.parentElement.parentElement;
  4590. if (!eleTarget.classList.contains("stsh_hidden"))
  4591. {
  4592. eleTarget.classList.add("stsh_hidden");
  4593. }
  4594. }
  4595. }
  4596. catch (ex)
  4597. {
  4598. console.error("hideStrNotMatch", ex.message);
  4599. }
  4600. }
  4601. }
  4602. else if (mode === 1) // long
  4603. {
  4604. var dot = "...";
  4605. var dotLengthMinus = 0 - dot.length;
  4606. var eleStrs = document.querySelectorAll
  4607. (" \
  4608. #keylist \
  4609. > table:nth-child(1) > tbody:nth-child(1) > tr > td:nth-child(1) > div:nth-child(1) \
  4610. > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(2) > td:nth-child(1) \
  4611. ");
  4612. for (var i = 0; i < eleStrs.length; i++)
  4613. {
  4614. try
  4615. {
  4616. var valStr = eleStrs[i].textContent.trim();
  4617. if (valStr.substr(dotLengthMinus) === dot)
  4618. {
  4619. var eleTarget = eleStrs[i].parentElement.parentElement
  4620. .parentElement.parentElement.parentElement.parentElement;
  4621. if (!eleTarget.classList.contains("stsh_hidden"))
  4622. {
  4623. eleTarget.classList.add("stsh_hidden");
  4624. }
  4625. }
  4626. }
  4627. catch (ex)
  4628. {
  4629. console.error("hideStrLong", ex.message);
  4630. }
  4631. }
  4632. }
  4633. }
  4634. var elesBtnShowingStr = document.querySelectorAll(".stsh_showing_str");
  4635. for (var i = 0; i < elesBtnShowingStr.length; i++)
  4636. {
  4637. elesBtnShowingStr[i].addEventListener("click", function(ev)
  4638. {
  4639. var mode = parseInt(ev.target.dataset.hidestr) || 0;
  4640. activeHideStr[mode] = 1;
  4641. hideStr(mode);
  4642. ev.target.disabled = true;
  4643. });
  4644. }
  4645. } // End Hide & sort suggestions
  4646.  
  4647. resizeSuggestionBox();
  4648. // Add Frame button when iframe load failed
  4649. {
  4650. var obTarget_ifrm = document.querySelector("#suggestions_iframe");
  4651. if (obTarget_ifrm)
  4652. {
  4653. var obMu_ifrm = new MutationObserver(function(mutations)
  4654. {
  4655. mutations.forEach(function(mutation)
  4656. {
  4657. var divFrame = document.querySelector("#stsh_frame");
  4658. if (!divFrame)
  4659. {
  4660. var divOuter = document.querySelector("#suggestions_box_outer");
  4661. if (divOuter)
  4662. {
  4663. divFrame = document.createElement("div");
  4664. divFrame.id = "stsh_frame";
  4665. divOuter.appendChild(divFrame);
  4666. }
  4667. }
  4668. if (divFrame)
  4669. {
  4670. var ifrm = document.querySelector("#suggestions_iframe");
  4671. if (ifrm)
  4672. {
  4673. var src = ifrm.getAttribute("src");
  4674. var token = getQueryByName("token_key", src);
  4675. divFrame.innerHTML =
  4676. ' \
  4677. <br/><br/> \
  4678. <div id="stsh_frame_sub"> \
  4679. Token: <span class="stsh_blue">' + token + '</span> \
  4680. <br/><br/> \
  4681. <a class="stsh_a_button" target="_blank" href="' + src + '">Frame</a> \
  4682. <br/><br/> \
  4683. This frame may be blocked by ad blocker software. \
  4684. <br/> \
  4685. Please whitelist https://translation.steampowered.com to prevent this missing frame. \
  4686. </div> \
  4687. ';
  4688. }
  4689. }
  4690. });
  4691. });
  4692.  
  4693. var obConfig_ifrm = { attributes: true, attributeFilter: ["src"] };
  4694. obMu_ifrm.observe(obTarget_ifrm, obConfig_ifrm);
  4695. }
  4696. }
  4697. // Open frame if only one string
  4698. {
  4699. setTimeoutCustom(function()
  4700. {
  4701. var elesCopy = document.querySelectorAll("#keylist .copysmall");
  4702. if (elesCopy.length === 1)
  4703. {
  4704. var eleDiv = elesCopy[0].parentElement.parentElement.parentElement;
  4705. if (eleDiv.tagName === "DIV")
  4706. {
  4707. if (!isVisible())
  4708. {
  4709. eleDiv.click();
  4710. }
  4711. }
  4712. }
  4713. }, 1000);
  4714. }
  4715. // Clean timestamp
  4716. {
  4717. var eleInputTime = document.querySelector("input[name='t']");
  4718. if (eleInputTime)
  4719. {
  4720. eleInputTime.parentElement.removeChild(eleInputTime);
  4721. }
  4722. }
  4723. // fix STS search options
  4724. {
  4725. for (var i = 0; i < 6; i++)
  4726. {
  4727. var elesSort = document.querySelectorAll("#search #sort" + i);
  4728. if (elesSort.length === 2)
  4729. {
  4730. elesSort[1].id = "status" + i;
  4731. }
  4732. }
  4733. var elesLabel = document.querySelectorAll("#search label[for='sort0']");
  4734. if (elesLabel.length === 2)
  4735. {
  4736. elesLabel[1].setAttribute("for", "status0");
  4737. }
  4738. }
  4739. } // End translate.php
  4740.  
  4741. if (url.indexOf("user_activity.php") > -1)
  4742. {
  4743. var user = "";
  4744. var eleAvatar = document.querySelector(".friend_block_avatar > a[href^='https://steamcommunity.com']");
  4745. if (eleAvatar)
  4746. {
  4747. eleAvatar.href = eleAvatar.href.replace("https://steamcommunity.com", "http://steamcommunity.com");
  4748. if (eleAvatar.href.indexOf("http://steamcommunity.com/profiles/") === 0)
  4749. {
  4750. user = eleAvatar.href.replace("http://steamcommunity.com/profiles/", "");
  4751. }
  4752. var name = eleAvatar.firstElementChild.getAttribute("title");
  4753. if (name === "")
  4754. {
  4755. name = user;
  4756. }
  4757. document.title = name + " - " + document.title;
  4758. }
  4759.  
  4760. var stsh_activityAddLink_start = getTimeMs();
  4761. var stsh_activityAddLink_itv = setIntervalCustom(function(user)
  4762. {
  4763. // Add more links in user activity
  4764. var stsh_activityAddLink_isEnd = false;
  4765. var stsh_activityAddLink_cur = getTimeMs();
  4766. var h3s = document.querySelectorAll("#leftAreaContainer h3");
  4767. if (h3s.length === 2)
  4768. {
  4769. var td = h3s[1].parentElement;
  4770. var matchArr = td.innerHTML.match(/<\/h3>.+<br>/i);
  4771. if (matchArr)
  4772. {
  4773. var name = matchArr[0]
  4774. .replace("</h3>-", "")
  4775. .replace("-<br>", "")
  4776. .replace("<br>", "")
  4777. .trim();
  4778. if (name === "")
  4779. {
  4780. name = user;
  4781. }
  4782. if (name === "")
  4783. {
  4784. name = "Steam";
  4785. }
  4786. var tagNew = "";
  4787. if (user === "")
  4788. {
  4789. tagNew =
  4790. "\
  4791. </h3>\
  4792. <a id='stsh_sectionId' class='stsh_blue' target='_blank' href='http://steamcommunity.com/my'>\
  4793. " + name + "</a>, \
  4794. <a class='stsh_green' target='_blank' href='/WhereIsEsty.php'>Esty</a><br><br>\
  4795. ";
  4796. }
  4797. else
  4798. {
  4799. tagNew =
  4800. "\
  4801. </h3>\
  4802. <a id='stsh_sectionId' class='stsh_blue' target='_blank' href='http://steamcommunity.com/profiles/" + user + "'>\
  4803. " + name + "</a>, \
  4804. <a class='stsh_green' target='_blank' href='/WhereIsEsty.php?collectionof=" + user + "'>Esty</a>\
  4805. "
  4806. /*
  4807. // Typonion
  4808. + ", <a class='stsh_green' target='_blank' href='/translate.php?user="
  4809. + user + "&onionhunter=1&liststatus=1'>Onion</a>
  4810. */
  4811. + " <br><br> ";
  4812. }
  4813. td.innerHTML = td.innerHTML.replace(/<\/h3>.+<br>/i, tagNew);
  4814. stsh_activityAddLink_isEnd = true;
  4815. }
  4816. if (stsh_activityAddLink_isEnd || stsh_activityAddLink_cur - stsh_activityAddLink_start > 10000)
  4817. {
  4818. clearInterval(stsh_activityAddLink_itv);
  4819. }
  4820. }
  4821. }, 300, user);
  4822. var countWord = "";
  4823. var countSugg = "";
  4824. var inputDials = document.querySelectorAll("#leftAreaContainer input.dial");
  4825. if (inputDials.length === 2)
  4826. {
  4827. countWord = inputDials[0].getAttribute("title").replace("words", "").trim();
  4828. countSugg = inputDials[1].getAttribute("title").replace("suggestions", "").trim();
  4829. }
  4830. var tdCount = document.querySelector("#leftAreaContainer td[align='left']");
  4831. if (tdCount)
  4832. {
  4833. tdCount.innerHTML =
  4834. '\
  4835. <div style="width: 100px; display: inline-block; text-align: center;">Word: ' + countWord + '</div> \
  4836. <div style="width: 100px; display: inline-block; text-align: center; margin-left: 13px;">Suggestion: ' + countSugg + '</div>\
  4837. ';
  4838. }
  4839. var sug = document.body.textContent;
  4840. var regComment = /VIEW COMMENT/g;
  4841. var regSuggest = /VIEW SUGGESTION/g;
  4842. var strComment = "...RECEIVED A MODERATOR COMMENT";
  4843. var strPending = "...ARE PENDING";
  4844. var strApproved = "...WERE APPROVED";
  4845. var strDeclined = "...WERE DECLINED";
  4846. var strApplied = "...HAVE BEEN APPLIED WITHIN THE LAST 14 DAYS";
  4847. var strRemoved = "...HAVE BEEN REMOVED WITHIN THE LAST 14 DAYS";
  4848. var startComment = sug.indexOf(strComment);
  4849. var startPending = sug.indexOf(strPending);
  4850. var startApproved = sug.indexOf(strApproved);
  4851. var startDeclined = sug.indexOf(strDeclined);
  4852. var startApplied = sug.indexOf(strApplied);
  4853. var startRemoved = sug.indexOf(strRemoved);
  4854. var sugComment = sug.substring(startComment,startPending);
  4855. var sugPending = sug.substring(startPending,startApproved);
  4856. var sugApproved = sug.substring(startApproved,startDeclined);
  4857. var sugDeclined = sug.substring(startDeclined,startApplied);
  4858. var sugApplied = sug.substring(startApplied,startRemoved);
  4859. var sugRemoved = sug.substring(startRemoved);
  4860. var countComment = (sugComment.match(regComment) || []).length;
  4861. var countPending = (sugPending.match(regSuggest) || []).length;
  4862. var countApproved = (sugApproved.match(regSuggest) || []).length;
  4863. var countDeclined = (sugDeclined.match(regSuggest) || []).length;
  4864. var countApplied = (sugApplied.match(regSuggest) || []).length;
  4865. var countRemoved = (sugRemoved.match(regSuggest) || []).length;
  4866. var divBtn = document.createElement("div");
  4867. document.body.appendChild(divBtn);
  4868. divBtn.innerHTML =
  4869. ' \
  4870. <div style="position: fixed; z-index: 3; right: 12px; top: 84px; line-height: 24px; text-align: right;"> \
  4871. &nbsp; <input id="stsh_btnToProgress" value="To Progress" class="stsh_btn_long" type="button" \
  4872. onclick="scrollToId(\'stsh_sectionId\', -50); return false;" /><br/> \
  4873. \
  4874. &nbsp; <span class="stsh_scroll_header">Scroll To</span>\
  4875. <li class="stsh_suggestion_btn stsh_suggestion stsh_suggestion_comment"><input value="Comment (' + countComment + ')" \
  4876. class="stsh_btn_long" type="button" onclick="scrollToId(\'stsh_sectionComment\'); return false;" ></li> \
  4877. <li class="stsh_suggestion_btn stsh_suggestion stsh_suggestion_pending"><input value="Pending (' + countPending + ')" \
  4878. class="stsh_btn_long" type="button" onclick="scrollToId(\'stsh_sectionPending\'); return false;" ></li> \
  4879. <li class="stsh_suggestion_btn stsh_suggestion stsh_suggestion_approved"><input value="Approved (' + countApproved + ')" \
  4880. class="stsh_btn_long" type="button" onclick="scrollToId(\'stsh_sectionApproved\'); return false;" ></li> \
  4881. <li class="stsh_suggestion_btn stsh_suggestion stsh_suggestion_declined"><input value="Declined (' + countDeclined + ')" \
  4882. class="stsh_btn_long" type="button" onclick="scrollToId(\'stsh_sectionDeclined\'); return false;" ></li> \
  4883. <li class="stsh_suggestion_btn stsh_suggestion stsh_suggestion_applied"><input value="Applied (' + countApplied + ')" \
  4884. class="stsh_btn_long" type="button" onclick="scrollToId(\'stsh_sectionApplied\'); return false;" ></li> \
  4885. <li class="stsh_suggestion_btn stsh_suggestion stsh_suggestion_removed"><input value="Removed (' + countRemoved + ')" \
  4886. class="stsh_btn_long" type="button" onclick="scrollToId(\'stsh_sectionRemoved\'); return false;" ></li> \
  4887. <br/> \
  4888. &nbsp; <input id="stsh_btnHideSuggestion" value="Suggestions" class="stsh_btn_long" type="button" \
  4889. onclick="return false;" title="Toggle hidden/shown suggestion list" /><br/> \
  4890. <br/> \
  4891. &nbsp; <input value="Refresh" class="stsh_btn_long" type="button" onclick="window.location = window.location.href; return false;" /><br/> \
  4892. </div> \
  4893. ';
  4894.  
  4895. var divContainer = document.querySelector("#leftAreaContainer");
  4896. if (divContainer)
  4897. {
  4898. var inner = divContainer.innerHTML;
  4899. var htmlPending = /\.\.\.ARE \<a [^\<]+\>PENDING\<\/a\>/i.exec(inner);
  4900. var htmlApproved = /\.\.\.WERE \<a [^\<]+\>APPROVED\<\/a\>/i.exec(inner);
  4901. var htmlDeclined = /\.\.\.WERE \<a [^\<]+\>DECLINED\<\/a\>/i.exec(inner);
  4902. if (htmlPending && htmlApproved && htmlDeclined)
  4903. {
  4904. divContainer.innerHTML = inner
  4905. .replace("...RECEIVED A MODERATOR COMMENT",
  4906. "<span id='stsh_sectionComment' class='stsh_suggestion_header'>"
  4907. + "...RECEIVED A MODERATOR COMMENT ("
  4908. + countComment + ")</span>")
  4909. .replace(htmlPending,
  4910. "<span id='stsh_sectionPending' class='stsh_suggestion_header'>" + htmlPending + " ("
  4911. + countPending + ")</span>")
  4912. .replace(htmlApproved,
  4913. "<span id='stsh_sectionApproved' class='stsh_suggestion_header'>" + htmlApproved + " ("
  4914. + countApproved + ")</span>")
  4915. .replace(htmlDeclined,
  4916. "<span id='stsh_sectionDeclined' class='stsh_suggestion_header'>" + htmlDeclined + " ("
  4917. + countDeclined + ")</span>")
  4918. .replace("...HAVE BEEN APPLIED WITHIN THE LAST 14 DAYS",
  4919. "<span id='stsh_sectionApplied' class='stsh_suggestion_header'>"
  4920. + "...HAVE BEEN APPLIED WITHIN THE LAST 14 DAYS ("
  4921. + countApplied + ")</span>")
  4922. .replace("...HAVE BEEN REMOVED WITHIN THE LAST 14 DAYS",
  4923. "<span id='stsh_sectionRemoved' class='stsh_suggestion_header'>"
  4924. + "...HAVE BEEN REMOVED WITHIN THE LAST 14 DAYS ("
  4925. + countRemoved + ")</span>");
  4926. }
  4927. }
  4928. if (document.querySelector("#hours"))
  4929. {
  4930. var eleBtn = document.querySelector("#stsh_btnToProgress");
  4931. if (eleBtn)
  4932. {
  4933. var ele = document.createElement("input");
  4934. ele.classList.add("stsh_btn_long");
  4935. ele.setAttribute("value", "To Hours");
  4936. ele.setAttribute("type", "button");
  4937. ele.setAttribute("onclick", "scrollToElement(\"input[name*='[remarks]']\", -48); return false;");
  4938. insertAfterElement(ele, eleBtn);
  4939. ele = document.createTextNode(" \u00A0 ");
  4940. insertAfterElement(ele, eleBtn);
  4941. ele = document.createElement("br");
  4942. insertAfterElement(ele, eleBtn);
  4943. }
  4944. }
  4945. var cans = document.querySelectorAll("canvas");
  4946. for (var i = 0; i < cans.length; i++)
  4947. {
  4948. cans[i].parentElement.removeChild(cans[i]);
  4949. }
  4950. var aKeys = document.querySelectorAll("#leftAreaContainer li > a:nth-child(1)");
  4951. for (var i = 0; i < aKeys.length; i++)
  4952. {
  4953. var key = aKeys[i].textContent;
  4954. var keyArr = key.substr(21).trim().split(" >> ");
  4955. keyArr[0] = "<span style='color: #FFF !important;'>" + keyArr[0] + "</span>";
  4956. var keyNew = key.substr(0,21) + keyArr.join(" >> ") + "";
  4957. aKeys[i].innerHTML = keyNew;
  4958. }
  4959. var sugModeComment = 0;
  4960. var sugModePending = 1;
  4961. var sugModeApproved = 2;
  4962. var sugModeDeclined = 3;
  4963. var sugModeApplied = 4;
  4964. var sugModeRemoved = 5;
  4965. var sugMode = sugModeComment;
  4966. var eleSugFirst = document.querySelector
  4967. (" \
  4968. #leftAreaContainer > a[href^='translate.php?search_input='] \
  4969. , #leftAreaContainer > form > a[href^='translate.php?search_input='] \
  4970. ");
  4971. if (eleSugFirst)
  4972. {
  4973. var eleSugHeadPrev = eleSugFirst.previousElementSibling.previousElementSibling;
  4974. if (eleSugHeadPrev.id === "stsh_sectionRemoved")
  4975. {
  4976. sugMode = sugModeRemoved;
  4977. }
  4978. else if (eleSugHeadPrev.id === "stsh_sectionApplied")
  4979. {
  4980. sugMode = sugModeApplied;
  4981. }
  4982. else if (eleSugHeadPrev.id === "stsh_sectionDeclined")
  4983. {
  4984. sugMode = sugModeDeclined;
  4985. }
  4986. else if (eleSugHeadPrev.id === "stsh_sectionApproved")
  4987. {
  4988. sugMode = sugModeApproved;
  4989. }
  4990. else if (eleSugHeadPrev.id === "stsh_sectionPending")
  4991. {
  4992. sugMode = sugModePending;
  4993. }
  4994. var eleSugNext = eleSugFirst;
  4995. while (eleSugNext)
  4996. {
  4997. if (eleSugNext.tagName === "A")
  4998. {
  4999. var attrHref = eleSugNext.getAttribute("href");
  5000. if (attrHref && attrHref.indexOf("translate.php?search_input=") === 0)
  5001. {
  5002. eleSugNext.classList.add("stsh_suggestion");
  5003. if (sugMode === sugModeComment)
  5004. {
  5005. eleSugNext.classList.add("stsh_suggestion_comment");
  5006. }
  5007. else if (sugMode === sugModePending)
  5008. {
  5009. eleSugNext.classList.add("stsh_suggestion_pending");
  5010. }
  5011. else if (sugMode === sugModeApproved)
  5012. {
  5013. eleSugNext.classList.add("stsh_suggestion_approved");
  5014. }
  5015. else if (sugMode === sugModeDeclined)
  5016. {
  5017. eleSugNext.classList.add("stsh_suggestion_declined");
  5018. }
  5019. else if (sugMode === sugModeApplied)
  5020. {
  5021. eleSugNext.classList.add("stsh_suggestion_applied");
  5022. }
  5023. else if (sugMode === sugModeRemoved)
  5024. {
  5025. eleSugNext.classList.add("stsh_suggestion_removed");
  5026. }
  5027. }
  5028. }
  5029. else if (eleSugNext.tagName === "SPAN" && eleSugNext.classList.contains("stsh_suggestion_header"))
  5030. {
  5031. if (eleSugNext.id === "stsh_sectionRemoved")
  5032. {
  5033. sugMode = sugModeRemoved;
  5034. }
  5035. else if (eleSugNext.id === "stsh_sectionApplied")
  5036. {
  5037. sugMode = sugModeApplied;
  5038. }
  5039. else if (eleSugNext.id === "stsh_sectionDeclined")
  5040. {
  5041. sugMode = sugModeDeclined;
  5042. }
  5043. else if (eleSugNext.id === "stsh_sectionApproved")
  5044. {
  5045. sugMode = sugModeApproved;
  5046. }
  5047. else if (eleSugNext.id === "stsh_sectionPending")
  5048. {
  5049. sugMode = sugModePending;
  5050. }
  5051. }
  5052. eleSugNext = eleSugNext.nextElementSibling;
  5053. }
  5054. }
  5055. // Change language & correct url
  5056. {
  5057. var aProgresses = document.querySelectorAll("div > .friend_block_avatar a[onmouseout]");
  5058. for (var i = 0; i < aProgresses.length; i++)
  5059. {
  5060. var langCur = getQueryByName("lang", aProgresses[i].href);
  5061. if (langCur === "")
  5062. {
  5063. aProgresses[i].href = aProgresses[i].href + lang;
  5064. }
  5065. else
  5066. {
  5067. if (langCur !== lang)
  5068. {
  5069. //var langQuery = (url.indexOf("?") > -1) ? "&lang=" : "?lang=";
  5070. //window.location = url + langQuery + langCur;
  5071. console.log("Lang: " + langCur);
  5072. }
  5073. }
  5074. var aContent = aProgresses[i].textContent.trim();
  5075. if (aContent.indexOf("SUGGESTIONS") > -1)
  5076. {
  5077. aProgresses[i].href = aProgresses[i].href + "&listsort=5&liststatus=1&paginationrows=1000";
  5078. }
  5079. else if (aContent.indexOf("REVIEWS") > -1)
  5080. {
  5081. aProgresses[i].href = aProgresses[i].href + "&listsort=5&liststatus=3&paginationrows=1000";
  5082. }
  5083. }
  5084. }
  5085. // Hours
  5086. if (document.querySelector("#hours"))
  5087. {
  5088. function calculateHours()
  5089. {
  5090. var rgxDate = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
  5091. var rgxTime = /^(\d{1,2}:\d{2}(:\d{2})?|\d{1,2}\.\d{2})$/;
  5092. var eleFrom = document.querySelector("#stsh_hoursCalc_from");
  5093. var eleTo = document.querySelector("#stsh_hoursCalc_to");
  5094. var eleRes = document.querySelector("#stsh_hoursCalc_result");
  5095. if (eleFrom && eleTo && eleRes)
  5096. {
  5097. var rawFrom = eleFrom.value.trim();
  5098. var rawTo = eleTo.value.trim();
  5099. var valFrom = 0;
  5100. var valTo = 0;
  5101. if (rgxDate.test(rawFrom))
  5102. {
  5103. rawFrom = rawFrom.substr(11);
  5104. }
  5105. if (rgxTime.test(rawFrom))
  5106. {
  5107. var arrTime = rawFrom.split(":");
  5108. if (arrTime.length === 1)
  5109. {
  5110. arrTime = rawFrom.split(".");
  5111. }
  5112. valFrom = parseInt(arrTime[1]) + (parseInt(arrTime[0]) * 60);
  5113. }
  5114. if (rgxDate.test(rawTo))
  5115. {
  5116. rawTo = rawTo.substr(11);
  5117. }
  5118. if (rgxTime.test(rawTo))
  5119. {
  5120. var arrTime = rawTo.split(":");
  5121. if (arrTime.length === 1)
  5122. {
  5123. arrTime = rawTo.split(".");
  5124. }
  5125. valTo = parseInt(arrTime[1]) + (parseInt(arrTime[0]) * 60);
  5126. }
  5127. var valDiff = Math.abs(valTo - valFrom);
  5128. var valHr = parseInt(valDiff / 60);
  5129. var valMn = valDiff % 60;
  5130. eleRes.textContent = padZero(valHr, 2) + ":" + padZero(valMn, 2);
  5131. }
  5132. }
  5133. var curDateStr = getDateUs();
  5134. // Add hours calculator
  5135. {
  5136. var eleFinalize = document.querySelector("#hours input[name='Finalize']");
  5137. if (eleFinalize)
  5138. {
  5139. var eleFinalizeParent = eleFinalize.parentElement;
  5140. eleFinalizeParent.setAttribute("colspan", "2");
  5141. eleFinalizeParent.style.verticalAlign = "top";
  5142. var elePad = document.createElement("td");
  5143. insertBeforeElement(elePad, eleFinalizeParent);
  5144. var eleCalc = document.createElement("td");
  5145. eleCalc.classList.add("stsh_hoursCalc");
  5146. insertBeforeElement(eleCalc, eleFinalizeParent);
  5147. if (eleCalc.parentElement.previousElementSibling.querySelector("input[type='radio']"))
  5148. {
  5149. eleCalc.appendChild(document.createElement("br"));
  5150. }
  5151. var ele = document.createElement("b");
  5152. ele.textContent = " Hours Calculator (Estimated) ";
  5153. eleCalc.appendChild(ele);
  5154. eleCalc.appendChild(document.createElement("br"));
  5155. ele = document.createElement("span");
  5156. ele.innerHTML =
  5157. ' \
  5158. Enter date or time to calculate range (calculate only hours and minutes). \
  5159. <br/>You can enter date "2016-01-01 08:05:00" or time "8:05" or time "8.05".\
  5160. ';
  5161. ele.setAttribute("style", "display: inline-block; padding-bottom: 4px;");
  5162. eleCalc.appendChild(ele);
  5163. eleCalc.appendChild(document.createElement("br"));
  5164. ele = document.createElement("span");
  5165. ele.textContent = " From: ";
  5166. eleCalc.appendChild(ele);
  5167. ele = document.createElement("input");
  5168. ele.id = "stsh_hoursCalc_from";
  5169. ele.setAttribute("type", "text");
  5170. ele.setAttribute("onkeypress", "return event.keyCode !== 13;");
  5171. ele.setAttribute("autocomplete", "off");
  5172. ele.addEventListener("keyup", function()
  5173. {
  5174. calculateHours();
  5175. });
  5176. eleCalc.appendChild(ele);
  5177. ele = document.createElement("span");
  5178. ele.innerHTML = "&nbsp;&nbsp; To: ";
  5179. eleCalc.appendChild(ele);
  5180. ele = document.createElement("input");
  5181. ele.id = "stsh_hoursCalc_to";
  5182. ele.setAttribute("type", "text");
  5183. ele.setAttribute("onkeypress", "return event.keyCode !== 13;");
  5184. ele.setAttribute("autocomplete", "off");
  5185. ele.addEventListener("keyup", function()
  5186. {
  5187. calculateHours();
  5188. });
  5189. eleCalc.appendChild(ele);
  5190. ele = document.createElement("input");
  5191. ele.id = "stsh_hoursCalc_toNow";
  5192. ele.setAttribute("type", "button");
  5193. ele.setAttribute("value", "Now");
  5194. ele.setAttribute("onclick", "return false;");
  5195. ele.addEventListener("click", function()
  5196. {
  5197. var eleTo = document.querySelector("#stsh_hoursCalc_to");
  5198. eleTo.value = getTimeUs();
  5199. calculateHours();
  5200. });
  5201. eleCalc.appendChild(ele);
  5202. ele = document.createElement("span");
  5203. ele.innerHTML = "&nbsp;&nbsp; Result: ";
  5204. eleCalc.appendChild(ele);
  5205. ele = document.createElement("b");
  5206. ele.id = "stsh_hoursCalc_result"
  5207. ele.textContent = " 00:00 ";
  5208. eleCalc.appendChild(ele);
  5209. }
  5210. }
  5211. // Hilight current date
  5212. {
  5213. var elesTd = document.querySelectorAll("#hours > table > tbody > tr > td:nth-child(1)");
  5214. for (var i = 0; i < elesTd.length; i++)
  5215. {
  5216. if (elesTd[i].textContent.indexOf(curDateStr) > -1)
  5217. {
  5218. elesTd[i].parentElement.id = "stsh_hours_curDate";
  5219. elesTd[i].parentElement.classList.add("stsh_hours_curDate");
  5220. break;
  5221. }
  5222. }
  5223. }
  5224. // Auto calculate hours in current date
  5225. {
  5226. var timePendingFirst = "";
  5227. var timePendingLast = "";
  5228. var elesPending = document.querySelectorAll("#mainbody .stsh_suggestion_pending");
  5229. for (var i = 0; i < elesPending.length; i++)
  5230. {
  5231. var content = elesPending[i].textContent.trim().substr(0, 19);
  5232. if (content.substr(0, 10) === curDateStr)
  5233. {
  5234. timePendingFirst = content.substr(11, 5);
  5235. if (timePendingLast === "")
  5236. {
  5237. timePendingLast = timePendingFirst;
  5238. }
  5239. }
  5240. else
  5241. {
  5242. break;
  5243. }
  5244. }
  5245. var timeApprovedFirst = "";
  5246. var timeApprovedLast = "";
  5247. var elesApproved = document.querySelectorAll("#mainbody .stsh_suggestion_approved");
  5248. for (var i = 0; i < elesApproved.length; i++)
  5249. {
  5250. var content = elesApproved[i].textContent.trim().substr(0, 19);
  5251. if (content.substr(0, 10) === curDateStr)
  5252. {
  5253. timeApprovedFirst = content.substr(11, 5);
  5254. if (timeApprovedLast === "")
  5255. {
  5256. timeApprovedLast = timeApprovedFirst;
  5257. }
  5258. }
  5259. else
  5260. {
  5261. break;
  5262. }
  5263. }
  5264. if (timePendingFirst === "")
  5265. {
  5266. timePendingFirst = timeApprovedFirst;
  5267. }
  5268. if (timeApprovedFirst === "")
  5269. {
  5270. timeApprovedFirst = timePendingFirst;
  5271. }
  5272. if (timePendingLast === "")
  5273. {
  5274. timePendingLast = timeApprovedLast;
  5275. }
  5276. if (timeApprovedLast === "")
  5277. {
  5278. timeApprovedLast = timePendingLast;
  5279. }
  5280. var timeFirst = timeApprovedFirst < timePendingFirst ? timeApprovedFirst : timePendingFirst;
  5281. var timeLast = timeApprovedLast > timePendingLast ? timeApprovedLast : timePendingLast;
  5282. if (timeFirst !== "")
  5283. {
  5284. var eleFrom = document.querySelector("#stsh_hoursCalc_from");
  5285. if (eleFrom)
  5286. {
  5287. eleFrom.value = timeFirst;
  5288. }
  5289. var eleTo = document.querySelector("#stsh_hoursCalc_to");
  5290. if (eleTo)
  5291. {
  5292. eleTo.value = timeLast;
  5293. }
  5294. calculateHours();
  5295. }
  5296. }
  5297. // Make minutes add to hours
  5298. setTimeoutCustom(function()
  5299. {
  5300. var elesMn = document.querySelectorAll("#hours input[name*='[minutes]']");
  5301. for (var i = 0; i < elesMn.length; i++)
  5302. {
  5303. elesMn[i].setAttribute("min", "-15");
  5304. elesMn[i].setAttribute("max", "60");
  5305. elesMn[i].addEventListener("change", function(ev)
  5306. {
  5307. var eleMn = ev.target;
  5308. var eleHr = eleMn.parentElement.previousElementSibling.firstElementChild;
  5309. var valMn = parseInt(eleMn.value) || 0;
  5310. var valHr = parseInt(eleHr.value) || 0;
  5311. if (valMn < 0)
  5312. {
  5313. if (valHr > 0)
  5314. {
  5315. eleHr.value = valHr - 1;
  5316. eleMn.value = 45;
  5317. }
  5318. else
  5319. {
  5320. eleMn.value = 0;
  5321. }
  5322. }
  5323. else if (valMn > 59)
  5324. {
  5325. if (valHr < 23)
  5326. {
  5327. eleHr.value = valHr + 1;
  5328. eleMn.value = 0;
  5329. }
  5330. else
  5331. {
  5332. eleMn.value = 45;
  5333. }
  5334. }
  5335. });
  5336. }
  5337. }, 500);
  5338. // Make deferred can be clicked
  5339. {
  5340. var eleDeferred = document.querySelector("#hours td > i > span[title^='DATE']");
  5341. if (eleDeferred)
  5342. {
  5343. eleDeferred.dataset.title = eleDeferred.title;
  5344. eleDeferred.title = "Click to reveal";
  5345. eleDeferred.addEventListener("click", function(ev)
  5346. {
  5347. var ele = ev.target;
  5348. var eleDetail = document.querySelector(".stsh_deferred");
  5349. if (!eleDetail)
  5350. {
  5351. eleDetail = document.createElement("div");
  5352. eleDetail.classList.add("stsh_deferred");
  5353. ele.parentElement.parentElement
  5354. .parentElement.parentElement
  5355. .lastElementChild.firstElementChild
  5356. .appendChild(eleDetail);
  5357. }
  5358. var space = String.fromCharCode(160);
  5359. var space3 = space + space + space;
  5360. eleDetail.innerHTML = "<br/>TOTAL DEFERRED HOURS" + space3 + " <br/>"
  5361. + ele.dataset.title.substr(61).trim()
  5362. .replace(/\n/g, space3 + " <br/>")
  5363. + space3;
  5364. });
  5365. }
  5366. }
  5367. // Hide past date
  5368. {
  5369. var hidePast = function ()
  5370. {
  5371. var isHidden = false;
  5372. var elesMn = document.querySelectorAll("#hours input[name*='[minutes]']");
  5373. if (elesMn.length > 0)
  5374. {
  5375. if (elesMn[0].name === "date[1969-12-31][minutes]")
  5376. {
  5377. isHidden = true;
  5378. }
  5379. }
  5380. if (isHidden)
  5381. {
  5382. for (var i = 1, l = elesMn.length - 1; i < l; i++)
  5383. {
  5384. elesMn[i].parentElement.parentElement.classList.add("stsh_hidden");
  5385. }
  5386. }
  5387. };
  5388. setTimeoutCustom(hidePast, 500);
  5389. }
  5390. }
  5391. // In other user pages
  5392. // Hide wallet
  5393. // Hide email noti
  5394. {
  5395. var isHidden = true;
  5396. var user = GM_getValue("user", 0);
  5397. if (user)
  5398. {
  5399. var userPage = getQueryByName("user", url);
  5400. if (user === userPage)
  5401. {
  5402. isHidden = false;
  5403. }
  5404. }
  5405. if (isHidden)
  5406. {
  5407. var eleASug = document.querySelector(".friend_block_avatar > a[href*='://translation.steampowered.com/translate.php'");
  5408. if (eleASug && eleASug.textContent.trim() === "YOUR SUGGESTIONS")
  5409. {
  5410. isHidden = false;
  5411. }
  5412. }
  5413. if (isHidden && document.querySelector("#moderator_announcement"))
  5414. {
  5415. isHidden = false;
  5416. }
  5417. if (isHidden)
  5418. {
  5419. var elesAWallet = document.querySelectorAll("a[id^='walletkeys']");
  5420. for (var i = 0; i < elesAWallet.length; i++)
  5421. {
  5422. var eleCur = elesAWallet[i];
  5423. for (var j = 0; j < 5; j++)
  5424. {
  5425. eleCur.classList.add("stsh_hidden");
  5426. eleCur = eleCur.nextElementSibling;
  5427. }
  5428. }
  5429. var eleSub = document.querySelector("#subscribe");
  5430. if (eleSub)
  5431. {
  5432. eleSub.classList.add("stsh_hidden");
  5433. eleSub.previousElementSibling.classList.add("stsh_hidden");
  5434. eleSub.previousElementSibling.previousElementSibling.classList.add("stsh_hidden");
  5435. eleSub.nextElementSibling.classList.add("stsh_hidden");
  5436. eleSub.nextElementSibling.nextElementSibling.classList.add("stsh_hidden");
  5437. }
  5438. }
  5439. }
  5440. // Set visible suggestion list
  5441. {
  5442. function setVisibleSuggestion(visible)
  5443. {
  5444. var display = visible !== true ? "none" : "";
  5445. var eles = document.querySelectorAll(".copy");
  5446. for (var i = 0; i < eles.length; i++)
  5447. {
  5448. if (eles[i].id && eles[i].id.indexOf("showwalletkeys") < 0
  5449. && eles[i].id !== "abuse_report"
  5450. && eles[i].id !== "moderator_announcement")
  5451. {
  5452. if (eles[i].style.display !== display)
  5453. {
  5454. eles[i].style.display = display;
  5455. }
  5456. }
  5457. }
  5458. }
  5459. var eleHide = document.querySelector("#stsh_btnHideSuggestion");
  5460. if (eleHide)
  5461. {
  5462. var isHide = GM_getValue("profileHideSuggestion", 0);
  5463. if (isHide)
  5464. {
  5465. eleHide.dataset.modeNext = "show";
  5466. eleHide.value = "Suggestions: Hide";
  5467. setVisibleSuggestion(false);
  5468. }
  5469. else
  5470. {
  5471. eleHide.dataset.modeNext = "hide";
  5472. eleHide.value = "Suggestions: Show";
  5473. setVisibleSuggestion(true);
  5474. }
  5475. eleHide.addEventListener("click", function(ev)
  5476. {
  5477. var eleHide = ev.target;
  5478. if (eleHide.dataset.modeNext == "show")
  5479. {
  5480. eleHide.dataset.modeNext = "hide";
  5481. eleHide.value = "Suggestions: Show";
  5482. setVisibleSuggestion(true);
  5483. GM_setValue("profileHideSuggestion", 0);
  5484. }
  5485. else
  5486. {
  5487. eleHide.dataset.modeNext = "show";
  5488. eleHide.value = "Suggestions: Hide";
  5489. setVisibleSuggestion(false);
  5490. GM_setValue("profileHideSuggestion", 1);
  5491. }
  5492. });
  5493. }
  5494. }
  5495. } // End user_activity.php
  5496. if (/\/rally[0-9]{0,4}/.test(url))
  5497. {
  5498. resizeSuggestionBox();
  5499. var outer = document.querySelector("#suggestions_box_outer");
  5500. if (outer)
  5501. {
  5502. outer.setAttribute("onclick", "hideSuggestionsBox();");
  5503. }
  5504. // Set cur lang to first
  5505. {
  5506. var first = document.querySelector(".gradienttable tr:nth-child(6)");
  5507. if (first)
  5508. {
  5509. var cur = null;
  5510. var tdLangs = document.querySelectorAll(".gradienttable tr > td:nth-child(1)");
  5511. for (var i = 0; i < tdLangs.length; i++)
  5512. {
  5513. if (lang === tdLangs[i].textContent.trim().toLowerCase())
  5514. {
  5515. cur = tdLangs[i].parentElement;
  5516. break;
  5517. }
  5518. }
  5519. if (cur)
  5520. {
  5521. cur.classList.add("stsh_curLang");
  5522. first.parentElement.insertBefore(cur, first);
  5523. }
  5524. }
  5525. }
  5526. // Change row per page
  5527. {
  5528. var eleAs = document.querySelectorAll(".gradienttable tr:nth-child(6) a[href^='translate.php?']");
  5529. for (var i = 0; i < eleAs.length; i++)
  5530. {
  5531. eleAs[i].href = eleAs[i].href + "&paginationrows=1000";
  5532. }
  5533. }
  5534. var inputClose = document.querySelector("td:nth-child(3) > input:nth-child(1)");
  5535. if (inputClose)
  5536. {
  5537. inputClose.value = "Close (Esc)";
  5538. }
  5539. } // End rally.php
  5540. if (/\/rally_results_?[0-9]{0,4}/.test(url))
  5541. {
  5542. var h3 = document.querySelector("table.curved h3");
  5543. if (h3)
  5544. {
  5545. document.title = h3.textContent.trim();
  5546. }
  5547. var eleTable = document.querySelector("body > div:nth-child(1) > table:nth-child(1)");
  5548. if (eleTable)
  5549. {
  5550. eleTable.style.width = "";
  5551. }
  5552. var inputClose = document.querySelector("td:nth-child(3) > input:nth-child(1)");
  5553. if (inputClose)
  5554. {
  5555. inputClose.value = "Close (Esc)";
  5556. inputClose.focus();
  5557. }
  5558. // Add frame and background button
  5559. {
  5560. var eleTdFirst = document.querySelector("td:nth-child(1)");
  5561. if (eleTdFirst)
  5562. {
  5563. var eleTdFrame = document.createElement("td");
  5564. eleTdFrame.setAttribute("align", "right");
  5565. eleTdFrame.innerHTML =
  5566. ' <a class="stsh_a_button" target="_blank" href="' + url + '">Frame</a> ';
  5567. insertBeforeElement(eleTdFrame, eleTdFirst);
  5568. var img = document.body.style.backgroundImage;
  5569. if (img.indexOf("url(\"") === 0)
  5570. {
  5571. img = img.replace("url(\"", "").replace("\")", "");
  5572. var eleTdImage = document.createElement("td");
  5573. eleTdImage.setAttribute("align", "right");
  5574. eleTdImage.innerHTML =
  5575. ' <a class="stsh_a_button" target="_blank" href="' + img + '">View Background</a> ';
  5576. insertAfterElement(eleTdImage, eleTdFrame);
  5577. }
  5578. }
  5579. }
  5580. var inputPrev = document.querySelector("input[value^='Prev']");
  5581. if (inputPrev)
  5582. {
  5583. addKeyCtrl(document, inputPrev, 219, "[", 1|2); // [
  5584. addKeyCtrl(document, inputPrev, "BracketLeft"); // [
  5585. disableAfterClick(inputPrev);
  5586. }
  5587. var inputNext = document.querySelector("input[value^='Next']");
  5588. if (inputNext)
  5589. {
  5590. addKeyCtrl(document, inputNext, 221, "]", 1|2); // ]
  5591. addKeyCtrl(document, inputNext, "BracketRight"); // ]
  5592. disableAfterClick(inputNext);
  5593. }
  5594. // Hilight cur lang
  5595. {
  5596. var elesLang = document.querySelectorAll("table.curved > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(3) > h2:nth-child(1)");
  5597. for (var i = 0; i < elesLang.length; i++)
  5598. {
  5599. if (lang === elesLang[i].textContent.trim().toLowerCase())
  5600. {
  5601. var eleParent = elesLang[i].parentElement.parentElement.parentElement.parentElement;
  5602. //eleParent.style.backgroundColor = "#474D1A";
  5603. eleParent.classList.add("stsh_curLang");
  5604. eleParent.setAttribute("bgcolor", "#474D1A");
  5605. eleParent.setAttribute("onmouseout", "this.bgColor='#474D1A'");
  5606. eleParent.setAttribute("onmouseover", "this.bgColor='#76802B'");
  5607. break;
  5608. }
  5609. }
  5610. }
  5611. // Reset points position
  5612. {
  5613. var eleSpan = document.querySelector("h5 > span");
  5614. if (eleSpan)
  5615. {
  5616. eleSpan.parentElement.parentElement.removeAttribute("style");
  5617. }
  5618. }
  5619. } // End rally_results.php
  5620. if (/\/rallyreplay_?[0-9]{0,4}/.test(url))
  5621. {
  5622. // Set cur lang to first
  5623. {
  5624. var elesFrame = document.querySelectorAll("#leftAreaContainer div[id^='frame']");
  5625. for (var i = 0; i < elesFrame.length; i++)
  5626. {
  5627. var first = elesFrame[i].querySelector(".gradienttable tr:nth-child(6)");
  5628. if (first)
  5629. {
  5630. var cur = null;
  5631. var tdLangs = elesFrame[i].querySelectorAll(".gradienttable tr > td:nth-child(1)");
  5632. for (var j = 0; j < tdLangs.length; j++)
  5633. {
  5634. if (lang === tdLangs[j].textContent.trim().toLowerCase())
  5635. {
  5636. cur = tdLangs[j].parentElement;
  5637. break;
  5638. }
  5639. }
  5640. if (cur)
  5641. {
  5642. cur.classList.add("stsh_curLang");
  5643. first.parentElement.insertBefore(cur, first);
  5644. }
  5645. }
  5646. }
  5647. }
  5648. var eleBtn = document.querySelector("input[value='FASTEST']");
  5649. if (eleBtn)
  5650. {
  5651. var ele = document.createElement("input");
  5652. ele.setAttribute("type", "button");
  5653. ele.setAttribute("value", "RESTART");
  5654. ele.setAttribute("style", "padding: 0; border: none; background: none;");
  5655. ele.setAttribute("onclick",
  5656. " \
  5657. indexReplay = 0; \
  5658. elsFrame.eq(indexReplay).fadeOut(0, function() \
  5659. { \
  5660. indexReplay = (indexReplay + 1) % lenFrame; \
  5661. elsFrame.eq(indexReplay).fadeIn(0); \
  5662. }); \
  5663. ");
  5664. insertAfterElement(ele, eleBtn);
  5665. insertAfterElement(document.createTextNode(" | "), eleBtn);
  5666. }
  5667. } // End rallyreplay.php
  5668. if (url.indexOf("/WhereIsEsty.php") > -1)
  5669. {
  5670. resizeSuggestionBox();
  5671. var outer = document.querySelector("#suggestions_box_outer");
  5672. if (outer)
  5673. {
  5674. outer.setAttribute("onclick", "hideSuggestionsBox();");
  5675. }
  5676. var divContainer = document.querySelector("#pageContainer");
  5677. if (divContainer)
  5678. {
  5679. var ele = document.createElement("div");
  5680. ele.id = "logout";
  5681. ele.innerHTML =
  5682. ' <a class="stsh_a_button" target="_blank" href="/home.php">Home</a> ';
  5683. divContainer.appendChild(ele);
  5684. }
  5685.  
  5686. var divContent = document.querySelector("#leftAreaContainer > div");
  5687. if (divContent)
  5688. {
  5689. var countSnap = document.querySelectorAll("div.box").length;
  5690. var user = "";
  5691. var name = "";
  5692.  
  5693. var eleImg = document.querySelector("#leftAreaContainer > div > div > a > img ");
  5694. if (eleImg)
  5695. {
  5696. name = eleImg.getAttribute("title");
  5697. user = eleImg.parentElement.getAttribute("href").replace("https://steamcommunity.com/profiles/", "");
  5698. }
  5699. var ele = document.createElement("div");
  5700. ele.setAttribute("class", "stsh_snapshot");
  5701. ele.innerHTML = "<a class='stsh_blue' target='_blank' href='/user_activity.php?user="
  5702. + user + "'>" + name + "</a>"
  5703. + "<br>Snapshot: " + countSnap;
  5704.  
  5705. divContent.appendChild(ele);
  5706. }
  5707. } // End WhereIsEsty.php
  5708. if (url.indexOf("/stickerbox.php") > -1)
  5709. {
  5710. document.querySelector("textarea[name='add_comment']").focus();
  5711. var inputPrev = document.querySelector("img[src*='z0lEQVRIx5WWaWxVRRTH'");
  5712. if (inputPrev)
  5713. {
  5714. addKeyCtrl(document, inputPrev, 219); // [
  5715. addKeyCtrl(document, inputPrev, "BracketLeft"); // [
  5716. disableAfterClick(inputPrev);
  5717. }
  5718. var inputNext = document.querySelector("img[src*='40lEQVRIx5WWe0xXZRjH'");
  5719. if (inputNext)
  5720. {
  5721. addKeyCtrl(document, inputNext, 221); // ]
  5722. addKeyCtrl(document, inputNext, "BracketRight"); // ]
  5723. disableAfterClick(inputNext);
  5724. }
  5725. } // End stickerbox.php
  5726. if (/\/(home\.php|index\.php)/i.test(url))
  5727. {
  5728. // Set cur lang to first
  5729. {
  5730. var first = null;
  5731. var cur = null;
  5732. var curLang = lang.substring(0, 4);
  5733. if (curLang === "schi")
  5734. curLang = "sim.";
  5735. else if (curLang === "tchi")
  5736. curLang = "tra.";
  5737. var eleLangs = document.querySelectorAll("#overall .progress");
  5738. if (eleLangs.length > 0)
  5739. {
  5740. first = eleLangs[0];
  5741. for (var i = 0; i < eleLangs.length; i++)
  5742. {
  5743. if (curLang === eleLangs[i].textContent.trim().substring(0, 4).toLowerCase())
  5744. {
  5745. cur = eleLangs[i];
  5746. break;
  5747. }
  5748. }
  5749. if (cur)
  5750. {
  5751. cur.classList.add("stsh_blue");
  5752. var curSib1 = cur.nextSibling;
  5753. var curSib2 = curSib1.nextSibling;
  5754. var curSib3 = curSib2.nextSibling;
  5755. var curSib4 = curSib3.nextSibling;
  5756. var curSib5 = curSib4.nextSibling;
  5757. var curSib6 = curSib5.nextSibling;
  5758. insertBeforeElement(cur, first);
  5759. insertAfterElement(curSib6, cur);
  5760. insertAfterElement(curSib5, cur);
  5761. insertAfterElement(curSib4, cur);
  5762. insertAfterElement(curSib3, cur);
  5763. insertAfterElement(curSib2, cur);
  5764. insertAfterElement(curSib1, cur);
  5765. }
  5766. }
  5767. }
  5768. if (document.querySelector("#logout"))
  5769. {
  5770. var tmplHome =
  5771. ' \
  5772. <div class="stsh_home_group"> \
  5773. <span class="stsh_home_header">Shortcuts</span>\
  5774. <br/> &nbsp; <a class="stsh_a_button stsh_btn_med" target="_blank" \
  5775. href="/translate.php?search_input=DATE%3A+%DATE%&paginationrows=1000">New Today</a> &nbsp; \
  5776. <br/> &nbsp; <a class="stsh_a_button stsh_btn_med" target="_blank" href="/glossary.php">Glossary</a> &nbsp; \
  5777. \
  5778. <br/> <span class="stsh_home_header">Rally</span>\
  5779. <br/> &nbsp; <a class="stsh_a_button stsh_btn_med" target="_blank" href="/rally.php">Rally</a> &nbsp; \
  5780. %RALLY% \
  5781. \
  5782. <br/> <span class="stsh_home_header">Events</span>\
  5783. <br/> &nbsp; <a class="stsh_a_button stsh_btn_med" target="_blank" href="/rallyreplay.php">Rally Replay</a> &nbsp; \
  5784. <br/> &nbsp; <a class="stsh_a_button stsh_btn_med" target="_blank" href="/onionolooorm.php">Typonion</a> &nbsp; \
  5785. <br/> &nbsp; <a class="stsh_a_button stsh_btn_med" target="_blank" href="/dstbattle.php">DST Battle</a> &nbsp; \
  5786. <br/> &nbsp; <a class="stsh_a_button stsh_btn_med" target="_blank" href="/dota2.php">DOTA 2</a> &nbsp; \
  5787. <br/> \
  5788. </div> \
  5789. ';
  5790. tmplHome = tmplHome.replace("%DATE%", getDateUs());
  5791. // Rally
  5792. {
  5793. var date = new Date();
  5794. var yearLast = date.getUTCFullYear();
  5795. var yearFirst = 2013;
  5796. var strRally = "";
  5797. for (var i = yearLast; i >= yearFirst; i--)
  5798. {
  5799. if (i < yearLast || isRally())
  5800. {
  5801. strRally +=
  5802. ' \
  5803. <br/> &nbsp; \
  5804. <a class="stsh_a_button stsh_btn_med" target="_blank" href="/rally' + i + '.php">\
  5805. Rally ' + i + '</a> &nbsp; \
  5806. ';
  5807. }
  5808. }
  5809. tmplHome = tmplHome.replace("%RALLY%", strRally);
  5810. }
  5811. var eleNew = document.createElement("div");
  5812. eleNew.innerHTML = tmplHome;
  5813. document.body.appendChild(eleNew);
  5814. }
  5815. // Fix STS JS error
  5816. {
  5817. var eleTimer = document.querySelector("#timer");
  5818. if (!eleTimer)
  5819. {
  5820. var ele = document.createElement("div");
  5821. ele.id = "timer";
  5822. ele.classList.add("stsh_hidden");
  5823. document.body.appendChild(ele);
  5824. }
  5825. }
  5826. // Set current user
  5827. {
  5828. var eleUser = document.querySelector("#leftAreaContainer > b > a[href^='user_activity.php?user=']");
  5829. if (eleUser)
  5830. {
  5831. var user = getQueryByName("user", eleUser.href);
  5832. if (user && GM_getValue("user", 0) !== user)
  5833. {
  5834. GM_setValue("user", user);
  5835. }
  5836. }
  5837. }
  5838. } // End home.php
  5839. if (url.indexOf("/glossary.php") > -1)
  5840. {
  5841. // Add shortcuts
  5842. {
  5843. var contentGlos =
  5844. ' \
  5845. <div class="stsh_home_group"> \
  5846. <span class="stsh_home_header">Shortcuts</span> \
  5847. <br/> &nbsp; \
  5848. <a class="stsh_a_button stsh_btn_med" target="_blank" \
  5849. href="/translate.php?chosenfile=1&listfilter=1&listsort=3&paginationrows=1000&branch_ID=49&file_ID=226"> \
  5850. Glossary</a> &nbsp; \
  5851. <br/> &nbsp; \
  5852. <a class="stsh_a_button stsh_btn_med" target="_blank" \
  5853. href="/translate.php?chosenfile=1&listfilter=1&listsort=3&paginationrows=1000&branch_ID=49&file_ID=232"> \
  5854. Phrases</a> &nbsp; \
  5855. <br/> \
  5856. </div> \
  5857. ';
  5858. var eleNew = document.createElement("div");
  5859. eleNew.innerHTML = contentGlos;
  5860. document.body.appendChild(eleNew);
  5861. }
  5862. // Improve glossary links
  5863. {
  5864. var elesLink = document.querySelectorAll("#votes_container > .lbAction a[href^='./translate.php?search_input=']");
  5865. for (var i = 0; i < elesLink.length; i++)
  5866. {
  5867. elesLink[i].href = elesLink[i].href.replace("keyonly=0", "keyonly=2")
  5868. .replace("listsort=0", "listsort=4")
  5869. .replace("paginationrows=50", "paginationrows=1000");
  5870. }
  5871. }
  5872. } // End glossary.php
  5873. if (url.indexOf("/dstbattle.php") > -1)
  5874. {
  5875. // Hilight cur lang
  5876. {
  5877. var cur = null;
  5878. var elesLang = document.querySelectorAll(".gradienttable > tbody:nth-child(1) > tr > th:nth-child(1)");
  5879. for (var i = 1; i < elesLang.length; i++)
  5880. {
  5881. if (lang === elesLang[i].textContent.trim().replace(/[0-9]+\. /, "").toLowerCase())
  5882. {
  5883. cur = elesLang[i].parentElement;
  5884. break;
  5885. }
  5886. }
  5887. if (cur)
  5888. {
  5889. cur.classList.add("stsh_dst_curLang");
  5890. }
  5891. }
  5892. } // End dstbattle.php
  5893. if (url.indexOf("/statistics.php") > -1)
  5894. {
  5895. setTimeoutCustom(function()
  5896. {
  5897. var qBranch = getQueryByName("branch_ID");
  5898. var qFile = getQueryByName("file_ID");
  5899. if (qBranch === "" && qFile === "")
  5900. {
  5901. function getProgress(content)
  5902. {
  5903. content = content.trim();
  5904. var rgxNum = /[0-9]+/g;
  5905. var data = "";
  5906. if (content.indexOf("<15") > -1)
  5907. {
  5908. data = "014"
  5909. }
  5910. else if (content.indexOf("100") < 0)
  5911. {
  5912. data = "0" + (content.match(rgxNum) || ["00"])[0];
  5913. }
  5914. else
  5915. {
  5916. data = "100";
  5917. }
  5918. return data;
  5919. }
  5920. var branch = "";
  5921. var elesTr = document.querySelectorAll(".tableprogress tr");
  5922. for (var i = 0; i < elesTr.length; i++)
  5923. {
  5924. var eleH = elesTr[i].querySelector("h2");
  5925. if (eleH)
  5926. {
  5927. branch = eleH.textContent.trim();
  5928. }
  5929. else
  5930. {
  5931. var eleA = elesTr[i].querySelector("td:nth-child(2) > a:nth-child(1)[href^='translate.php']");
  5932. if (eleA)
  5933. {
  5934. elesTr[i].classList.add("stsh_stat_progress");
  5935. elesTr[i].dataset.translated = getProgress(eleA.textContent);
  5936. elesTr[i].dataset.approved = getProgress(
  5937. eleA.parentElement.nextElementSibling.firstElementChild.textContent);
  5938. elesTr[i].dataset.branch = branch;
  5939. elesTr[i].dataset.file = elesTr[i].firstElementChild.textContent.trim();
  5940. }
  5941. }
  5942. }
  5943. var eleDiv = document.createElement("div");
  5944. document.body.appendChild(eleDiv);
  5945. eleDiv.innerHTML =
  5946. ' \
  5947. <div class="stsh_showing_group"> \
  5948. <span class="stsh_showing_header">Hide</span>\
  5949. <br/> &nbsp; <input id="stsh_stat_hideGame" value="Game" class="stsh_btn_short" type="button" /> \
  5950. <input id="stsh_stat_hideSteam" value="Steam" class="stsh_btn_short" type="button" /> \
  5951. <br/> &nbsp; <input id="stsh_stat_hideApproved" value="Approved" class="stsh_btn_long" type="button" /> \
  5952. <br/> &nbsp; <input id="stsh_stat_hideCompleted" value="Completed" class="stsh_btn_long" type="button" /> \
  5953. <br/> \
  5954. <br/> &nbsp; <input id="stsh_stat_showAll" value="Show All" class="stsh_btn_long" type="button" /> \
  5955. </div> \
  5956. ';
  5957.  
  5958. var eleHideGame = document.querySelector("#stsh_stat_hideGame");
  5959. eleHideGame.addEventListener("click", function()
  5960. {
  5961. var elesProgress = document.querySelectorAll(".stsh_stat_progress:not(.stsh_hidden)");
  5962. for (var i = 0; i < elesProgress.length; i++)
  5963. {
  5964. if (elesProgress[i].dataset.branch.indexOf("games/") === 0)
  5965. {
  5966. elesProgress[i].classList.add("stsh_hidden");
  5967. }
  5968. }
  5969. });
  5970. var eleHideSteam = document.querySelector("#stsh_stat_hideSteam");
  5971. eleHideSteam.addEventListener("click", function()
  5972. {
  5973. var elesProgress = document.querySelectorAll(".stsh_stat_progress:not(.stsh_hidden)");
  5974. for (var i = 0; i < elesProgress.length; i++)
  5975. {
  5976. if (elesProgress[i].dataset.branch.indexOf("steam") === 0)
  5977. {
  5978. elesProgress[i].classList.add("stsh_hidden");
  5979. }
  5980. }
  5981. });
  5982. var eleHideApproved = document.querySelector("#stsh_stat_hideApproved");
  5983. eleHideApproved.addEventListener("click", function()
  5984. {
  5985. var elesProgress = document.querySelectorAll(".stsh_stat_progress:not(.stsh_hidden)");
  5986. for (var i = 0; i < elesProgress.length; i++)
  5987. {
  5988. if (elesProgress[i].dataset.translated === elesProgress[i].dataset.approved)
  5989. {
  5990. elesProgress[i].classList.add("stsh_hidden");
  5991. }
  5992. }
  5993. });
  5994. var eleHideCompleted = document.querySelector("#stsh_stat_hideCompleted");
  5995. eleHideCompleted.addEventListener("click", function()
  5996. {
  5997. var elesProgress = document.querySelectorAll(".stsh_stat_progress:not(.stsh_hidden)");
  5998. for (var i = 0; i < elesProgress.length; i++)
  5999. {
  6000. if (elesProgress[i].dataset.translated === "100" && elesProgress[i].dataset.approved === "100")
  6001. {
  6002. elesProgress[i].classList.add("stsh_hidden");
  6003. }
  6004. }
  6005. });
  6006. var eleShowAll = document.querySelector("#stsh_stat_showAll");
  6007. eleShowAll.addEventListener("click", function()
  6008. {
  6009. var elesProgress = document.querySelectorAll(".stsh_stat_progress.stsh_hidden");
  6010. for (var i = 0; i < elesProgress.length; i++)
  6011. {
  6012. elesProgress[i].classList.remove("stsh_hidden");
  6013. }
  6014. });
  6015. }
  6016. }, 100);
  6017. } // End statistics.php
  6018. if (url.indexOf("index.php") > -1
  6019. || url === "http://translation.steampowered.com/"
  6020. || url === "https://translation.steampowered.com/")
  6021. {
  6022. var eleDes = document.querySelector("#verify-form > form");
  6023. if (eleDes)
  6024. {
  6025. var eleSpan = document.createElement("span");
  6026. eleSpan.classList.add("stsh_autoLoginOption");
  6027.  
  6028. var eleInput = document.createElement("input");
  6029. eleInput.id = "stsh_autoLogin";
  6030. eleInput.setAttribute("type", "checkbox");
  6031. eleInput.setAttribute("value", "auto");
  6032. function autoLogin()
  6033. {
  6034. var eleImage = document.querySelector("#verify-form > form > input[class='image']");
  6035. if (eleImage)
  6036. {
  6037. setTimeoutCustom(function()
  6038. {
  6039. var eleInput = document.querySelector("#stsh_autoLogin");
  6040. if (eleInput && eleInput.checked)
  6041. {
  6042. eleImage.click();
  6043. }
  6044. }, 3000);
  6045. }
  6046. }
  6047. if (GM_getValue("autoLogin", 0) === "true")
  6048. {
  6049. eleInput.checked = true;
  6050. autoLogin();
  6051. }
  6052.  
  6053. eleInput.addEventListener("click", function (e)
  6054. {
  6055. var ele = e.target;
  6056. if (ele.checked)
  6057. {
  6058. GM_setValue("autoLogin", "true");
  6059. autoLogin();
  6060. }
  6061. else
  6062. {
  6063. GM_setValue("autoLogin", "false");
  6064. }
  6065. });
  6066.  
  6067. var eleLabel = document.createElement("label");
  6068. eleLabel.setAttribute("for", "stsh_autoLogin");
  6069. eleLabel.textContent = " Auto Login";
  6070.  
  6071. eleSpan.appendChild(eleInput);
  6072. eleSpan.appendChild(eleLabel);
  6073. eleDes.appendChild(eleSpan);
  6074. }
  6075. } // End index.php
  6076. if (url.indexOf("try_auth.php") > -1)
  6077. {
  6078. setTimeoutCustom(function()
  6079. {
  6080. document.forms[0].submit();
  6081. }, 3000);
  6082. } // End try_auth.php
  6083. window.addEventListener("beforeunload", function (e)
  6084. {
  6085. clearTimeoutAll();
  6086. clearIntervalAll();
  6087. });
  6088. } // End Main
  6089.  
  6090. function client()
  6091. {
  6092. var clientScript =
  6093. ' \
  6094. var timeoutList = new Array(); \
  6095. var intervalList = new Array(); \
  6096. \
  6097. function setTimeoutCustom(func, tm, params) \
  6098. { \
  6099. var id = setTimeout(func, tm, params); \
  6100. timeoutList.push(id); \
  6101. return id; \
  6102. } \
  6103. \
  6104. function clearTimeoutAll() \
  6105. { \
  6106. for (var i = 0; i < timeoutList.length; i++) \
  6107. { \
  6108. clearTimeout(timeoutList[i]); \
  6109. } \
  6110. } \
  6111. \
  6112. function setIntervalCustom(func, tm, params) \
  6113. { \
  6114. var id = setInterval(func, tm, params); \
  6115. intervalList.push(id); \
  6116. return id; \
  6117. } \
  6118. \
  6119. function clearIntervalAll() \
  6120. { \
  6121. for (var i = 0; i < intervalList.length; i++) \
  6122. { \
  6123. clearInterval(intervalList[i]); \
  6124. } \
  6125. } \
  6126. \
  6127. function scrollToId(id, offset) \
  6128. { \
  6129. scrollToElement("#" + id, offset); \
  6130. } \
  6131. \
  6132. function scrollToElement(selector, offset) \
  6133. { \
  6134. if (typeof offset === "undefined") \
  6135. { \
  6136. offset = -20; \
  6137. } \
  6138. \
  6139. var ele = document.querySelector(selector); \
  6140. if (ele) \
  6141. { \
  6142. ele.scrollIntoView(true); \
  6143. window.scrollBy(0, offset); \
  6144. } \
  6145. } \
  6146. \
  6147. function getTimeMs() \
  6148. { \
  6149. return (new Date()).getTime(); \
  6150. } \
  6151. \
  6152. function registerHideSuggestion() \
  6153. { \
  6154. if (typeof hideSuggestionsBox !== "undefined" || (parent && parent.hideSuggestionsBox)) \
  6155. { \
  6156. document.addEventListener("keydown", function(e) \
  6157. { \
  6158. if (e.keyCode === 27) \
  6159. { \
  6160. if (parent) \
  6161. { \
  6162. parent.hideSuggestionsBox(); \
  6163. } \
  6164. else \
  6165. { \
  6166. hideSuggestionsBox(); \
  6167. } \
  6168. } \
  6169. return false; \
  6170. }); \
  6171. } \
  6172. } \
  6173. registerHideSuggestion(); \
  6174. \
  6175. function doubleClickHideSuggestion(ele) \
  6176. { \
  6177. var maxDiff = 3000; \
  6178. var msDiff = maxDiff; \
  6179. var isEdited = false; \
  6180. \
  6181. if (ele && ele.dataset) \
  6182. { \
  6183. msDiff = getTimeMs() - (ele.dataset.stshHideSuggestion || 0); \
  6184. isEdit = ele.dataset.stshTextEdited === "true"; \
  6185. } \
  6186. \
  6187. if (!isEdit || msDiff < maxDiff) \
  6188. { \
  6189. hideSuggestionsBox(); \
  6190. ele.dataset.stshHideSuggestion = 0; \
  6191. } \
  6192. else \
  6193. { \
  6194. ele.dataset.stshHideSuggestion = getTimeMs(); \
  6195. } \
  6196. } \
  6197. \
  6198. function clickToSelect(ele) \
  6199. { \
  6200. var range = document.createRange(); \
  6201. range.setStartBefore(ele.firstChild); \
  6202. range.setEndAfter(ele.lastChild); \
  6203. var sel = window.getSelection(); \
  6204. sel.removeAllRanges(); \
  6205. sel.addRange(range); \
  6206. } \
  6207. \
  6208. function syncUrlArray() \
  6209. { \
  6210. var strStart = "showSuggestionsBox( \'"; \
  6211. var strEnd = "\' ); return false;"; \
  6212. var strCur = "&list_id="; \
  6213. var strAll = "&endnext="; \
  6214. var regPos = /&list_id=\\d+&endnext=\\d+/g; \
  6215. var isEdit = false; \
  6216. var eleDivs = []; \
  6217. var urls = []; \
  6218. \
  6219. var pattUrlTimestamp2 = /\\&t=[0-9]{6,}/g; \
  6220. var pattUrlTimestamp4 = /\\&[0-9]{6,}\\&/g; \
  6221. \
  6222. var trKeys = document.querySelectorAll("#keylist > table:nth-child(1) > tbody:nth-child(1) > tr"); \
  6223. for (var i = 0; i < trKeys.length; i++) \
  6224. { \
  6225. if (!trKeys[i].classList.contains("stsh_hidden")) \
  6226. { \
  6227. var eleDiv = trKeys[i].childNodes[0].childNodes[0]; \
  6228. if (typeof eleDiv.getAttribute !== "undefined" \
  6229. && eleDiv.getAttribute("onclick")) \
  6230. { \
  6231. eleDivs.push(eleDiv); \
  6232. } \
  6233. } \
  6234. } \
  6235. \
  6236. for (var i = 0, l = eleDivs.length; i < l; i++) \
  6237. { \
  6238. var evOld = eleDivs[i].getAttribute("onclick"); \
  6239. if (evOld) \
  6240. { \
  6241. var url = evOld.replace(strStart,"").replace(strEnd,"").replace(regPos,""); \
  6242. url = url + strCur + i + strAll + l; \
  6243. \
  6244. if (pattUrlTimestamp2.test(url)) \
  6245. { \
  6246. url = url.replace(pattUrlTimestamp2,""); \
  6247. } \
  6248. if (pattUrlTimestamp4.test(url)) \
  6249. { \
  6250. url = url.replace(pattUrlTimestamp4,"&"); \
  6251. } \
  6252. \
  6253. urls.push(url); \
  6254. \
  6255. var evNew = strStart + url + strEnd; \
  6256. if (evOld !== evNew) \
  6257. { \
  6258. eleDivs[i].setAttribute("onclick", evNew); \
  6259. isEdit = true; \
  6260. } \
  6261. } \
  6262. } \
  6263. \
  6264. if (isEdit || typeof URLarray === "undefined" || URLarray.length !== urls.length) \
  6265. { \
  6266. URLarray = urls; \
  6267. } \
  6268. } \
  6269. \
  6270. function setFrameColor(color) \
  6271. { \
  6272. var frame = document.querySelector("div#suggestions_box iframe"); \
  6273. if (frame) \
  6274. { \
  6275. if (frame.style.backgroundColor !== color) \
  6276. { \
  6277. frame.style.setProperty("background-color", color, "important"); \
  6278. } \
  6279. } \
  6280. } \
  6281. \
  6282. function padZero(num, size) \
  6283. { \
  6284. return (1e15+num+"").slice(-size); \
  6285. } \
  6286. \
  6287. function doInstant() \
  6288. { \
  6289. var url = document.documentURI; \
  6290. \
  6291. /* Fix STS JS error */ \
  6292. setTimeoutCustom(function() \
  6293. { \
  6294. if (typeof hide_list === "undefined") \
  6295. { \
  6296. hide_list = function() { /*console.log("sts: hide_list");*/ }; \
  6297. } \
  6298. }, 1000); \
  6299. \
  6300. if (url.indexOf("user_activity.php") > -1) \
  6301. { \
  6302. if (typeof $ !== "undefined") \
  6303. { \
  6304. $(".dial").css("display", "none"); \
  6305. } \
  6306. setTimeoutCustom(function() \
  6307. { \
  6308. if (typeof $ !== "undefined") \
  6309. { \
  6310. /* Restore drawing progress */ \
  6311. $(".dial").css("display", ""); \
  6312. $(".dial").knob( \
  6313. { \
  6314. "draw": function() \
  6315. { \
  6316. $(this.i).val(this.cv + "%"); \
  6317. } \
  6318. }); \
  6319. } \
  6320. }, 500); \
  6321. } \
  6322. else if (url.indexOf("translate.php") > -1) \
  6323. { \
  6324. getsuggestionURL = function(urlno) \
  6325. { \
  6326. /* Overwrite STS to remove timestamp */ \
  6327. return URLarray[urlno]; \
  6328. }; \
  6329. \
  6330. var obTarget_sync = document.querySelector("#keylist_container"); \
  6331. if (obTarget_sync) \
  6332. { \
  6333. var tmOb_sync = -1; \
  6334. var obMu_sync = new MutationObserver(function(mutations) \
  6335. { \
  6336. mutations.forEach(function(mutation) \
  6337. { \
  6338. if (mutation.type !== "attributes" \
  6339. || mutation.target.tagName === "TR") \
  6340. { \
  6341. clearTimeout(tmOb_sync); \
  6342. tmOb_sync = setTimeoutCustom(function() \
  6343. { \
  6344. syncUrlArray(); \
  6345. /*console.log("syncUrlArray: " + tmOb_sync);*/ \
  6346. }, 50); \
  6347. } \
  6348. }); \
  6349. }); \
  6350. \
  6351. var obConfig_sync = { childList: true, subtree: true, attributes: true, attributeFilter: ["class"] }; \
  6352. obMu_sync.observe(obTarget_sync, obConfig_sync); \
  6353. } \
  6354. \
  6355. /* Fix STS JS error */ \
  6356. setTimeoutCustom(function() \
  6357. { \
  6358. if (typeof getendnext === "undefined") \
  6359. { \
  6360. getendnext = function() { /*console.log("getendnext");*/ return ""; }; \
  6361. } \
  6362. }, 1000); \
  6363. } \
  6364. else if (url.indexOf("suggestions.php") > -1) \
  6365. { \
  6366. if (parent !== window) \
  6367. { \
  6368. var main = document.querySelector("#suggestionmain"); \
  6369. if (main) \
  6370. { \
  6371. var styleCp = window.getComputedStyle(main); \
  6372. if (styleCp) \
  6373. { \
  6374. var color = styleCp.backgroundColor; \
  6375. parent.setFrameColor(color); \
  6376. } \
  6377. } \
  6378. } \
  6379. } \
  6380. \
  6381. window.addEventListener("beforeunload", function (e) \
  6382. { \
  6383. clearTimeoutAll(); \
  6384. clearIntervalAll(); \
  6385. }); \
  6386. \
  6387. } \
  6388. doInstant(); \
  6389. \
  6390. ';
  6391.  
  6392. var eleClientScript = document.createElement("script");
  6393. eleClientScript.innerHTML = clientScript;
  6394. document.head.appendChild(eleClientScript);
  6395. } // End client
  6396.  
  6397. attachOnReady(initStyle);
  6398. attachOnReady(client);
  6399. attachOnReady(main);
  6400.  
  6401. })();
  6402.  
  6403. // End