STS Helper

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

当前为 2019-02-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name STS Helper
  3. // @author 7-elephant
  4. // @namespace iFantz7E.StsHelper
  5. // @version 2.66
  6. // @description In Steam Translation Server, add many features to make translate easier.
  7. // @match *://translation.steampowered.com/*
  8. // @icon https://translation.steampowered.com/public/favicon.ico
  9. // @run-at document-start
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM_addStyle
  13. // @grant GM_setClipboard
  14. // @license GPL-3.0-only
  15. // @copyright 2014, 7-elephant
  16. // @supportURL https://steamcommunity.com/id/7-elephant/
  17. // @contributionURL https://www.paypal.me/iFantz7E
  18. // ==/UserScript==
  19.  
  20. // License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
  21. // Compatibility: Firefox 14+ from Mutation Observer
  22.  
  23. // Since 4 Feb 2014
  24. // http://userscripts.org/scripts/show/325610
  25. // https://greasyfork.org/scripts/2250-sts-helper/
  26.  
  27. (function ()
  28. {
  29. "use strict";
  30. // jshint multistr:true
  31. function initStyle()
  32. {
  33. GM_addStyle
  34. (" \
  35. /* STSH Modify CSS */ \
  36. body { color: #acacac; } \
  37. #logout { \
  38. position: fixed; z-index: 1001; right: 12px; top: 10px; \
  39. line-height: 24px; text-align: right; } \
  40. input[type='button'], input[type='submit'] { \
  41. cursor: pointer; padding: 1px 9px; } \
  42. input[type='button']:disabled, input[type='submit']:disabled { \
  43. cursor: default; color: #777; } \
  44. #suggestionmain > div:nth-child(4) > form:nth-child(2) > div:nth-child(1) { \
  45. text-align: left; } \
  46. .lbAction > div > input[value^='SUBMIT'] { \
  47. width: 670px; height: 30px; border-color: #777 #333 #777 #777; } \
  48. .lbAction > div > input[value^='SUBMIT'][disabled] { border-color: #777; } \
  49. .lbAction > div > input[value^='RESUBMIT'] { \
  50. width: 561px; height: 30px; border-color: #777 #333 #777 #777; } \
  51. .lbAction > div > input[value='CANCEL'] { \
  52. width: 100px; height: 30px; margin-right: 5px; } \
  53. form.lbAction:nth-child(1) > div:nth-child(2) > input:nth-child(1) { \
  54. width: 90%; margin-top: 5px; } \
  55. .suggestion .lbAction textarea { \
  56. max-width: 700px !important; min-height: 50px; } \
  57. .progress td { vertical-align: top; } \
  58. div#suggestions_nav { \
  59. z-index: 3; position: absolute; width: 440px; \
  60. left: 543px; top: 2px; text-align: right; line-height: 24px; \
  61. color: #E1E1E1; } \
  62. #suggestionmain .smallcopy { width: 855px; min-height: 70px; max-height: 70px; } \
  63. #suggestionmain .progress { margin-top: -12px; } \
  64. #suggestionmain > div[style='padding-left: 10px;'] { padding-left: 6px !important; } \
  65. #suggestions_box { margin-top: 1px !important; position: relative; z-index: 20; } \
  66. #suggestions_iframe { min-height: 100px !important; } \
  67. #keylist td:nth-child(1) > div { \
  68. background-image: none !important; min-height: 43px; } \
  69. #keylist tr:nth-child(2n) > td:nth-child(1) > div { \
  70. background-color: #060606 !important; } \
  71. #keylist tr:nth-child(2n) > td:nth-child(1) > div:hover { \
  72. background-color: #0D0D0D !important; } \
  73. #keylist td:nth-child(1) > div:hover { \
  74. background-repeat: no-repeat; background-position: center; \
  75. background-color: #0D0D0D !important; \
  76. background-image: url('./public/images/row_over.gif') !important; } \
  77. #keylist td.progress { \
  78. color: #fff; max-width: 430px; overflow: hidden; \
  79. text-overflow: ellipsis; white-space: nowrap; } \
  80. .progress h1 { display: inline-block; } \
  81. div#suggestions_box iframe { background-color: #111 !important; } \
  82. .suggestions_list { border-right: 0px none; } \
  83. .suggestions_list:nth-child(2) { border: 0px none; } \
  84. .suggestion { \
  85. resize: both; overflow: hidden; \
  86. border: 1px solid #505050; border-top: none; \
  87. max-width: 953px; min-width: 200px; min-height: 50px; } \
  88. .suggestion:first-child { border-top: 1px solid #505050; } \
  89. .suggestion_signature { font-family: Verdana; margin-top: 4px; } \
  90. .suggestion_signature input:disabled { color: #777 !important; } \
  91. .lbAction input[value~='COMMENT'] { \
  92. vertical-align: top; margin-top: 1px; height: 52px; } \
  93. .lbAction input[value~='DISCUSS'] { \
  94. vertical-align: top; margin-top: 1px; height: 21px; top: 0px !important; } \
  95. #votes_container a[title='not translated'] { background-color: #333; } \
  96. #suggestion_value_new { min-height: 84px; max-width: 960px; min-width: 200px; overflow-y: auto; } \
  97. #hours > table > tbody > tr:nth-child(2) > th:nth-child(1) { width: 106px; text-align: center; } \
  98. #hours > table > tbody > tr:nth-child(2) > th:nth-child(3) { text-align: center; } \
  99. #hours > table > tbody > tr:nth-child(2) > th:nth-child(4) { text-align: center; } \
  100. #hours > table > tbody > tr > td:nth-child(1) { padding-right: 4px; } \
  101. #hours > table input[name*='[remarks]'] { width: 520px; } \
  102. #hours > table input[name*='[hours]'] { width: 100px; } \
  103. #hours > table input[name*='[minutes]'] { width: 100px; } \
  104. #suggestions_box_outer { overflow: hidden !important; } \
  105. #add_to_discussion { height: 19px; min-height: 19px; } \
  106. .gradienttable td > div { top: 1px !important; } \
  107. .copysmall > td:nth-child(1) { \
  108. white-space: nowrap; overflow: hidden; text-overflow: ellipsis; \
  109. display: inline-block; width: 430px; direction: ltr; } \
  110. div:hover > table > tbody > tr.copysmall > td:nth-child(1) { \
  111. direction: rtl; text-shadow: 1px 1px 1px #0D0D0D;} \
  112. #search input[type='radio'], #search input[type='checkbox'] \
  113. , #search button, #search label { cursor: pointer; } \
  114. .suggestion_error { max-width: 600px; margin-left: 80px; } \
  115. #country_list_id + #hidethis { display: block; margin-top: 8px; } \
  116. .row0:nth-child(odd), .row1:nth-child(odd), .row-1:nth-child(odd), .row-9:nth-child(odd), .row10:nth-child(odd) { \
  117. background-color: #161616; } \
  118. .row0:nth-child(even), .row1:nth-child(even), .row-1:nth-child(even), .row-9:nth-child(even), .row10:nth-child(even) { \
  119. background-color: #202020; } \
  120. .row2:nth-child(odd) { background-color: #1C2117; } \
  121. .row2:nth-child(even) { background-color: #22291B; } \
  122. #replacementstatus { \
  123. top: 0px !important; left: 176px !important; \
  124. display: block !important; opacity: 1.0 !important; } \
  125. a + br + #replacementstatus { left: 326px !important; } \
  126. #keylist_container { margin-left: 10px; } \
  127. img[src='<?=BASE_URL_CURRENT?>public/images/hr.gif'] { background-image: url('./public/images/hr.gif'); } \
  128. ");
  129. GM_addStyle
  130. (" \
  131. /* STSH Main CSS */ \
  132. .stsh_body_crop { overflow-x: hidden; } \
  133. .stsh_btn { width: 90px; } \
  134. .stsh_btn_med { min-width: 112px; } \
  135. .stsh_btn_long { min-width: 136px; } \
  136. .stsh_btn_short { min-width: 66px; } \
  137. .stsh_btn_right { position: relative; float: right; } \
  138. .stsh_text_right { \
  139. position: relative; float: right; \
  140. display: block; margin-right: 4px; text-transform: none; \
  141. font-size: 13px; font-style: normal; padding-top: 2px; } \
  142. .stsh_border_left { border-right-color: #333 !important; } \
  143. .stsh_border_right { border-left-color: #333 !important; } \
  144. .stsh_border_center { border-left-color: #333 !important; border-right-color: #333 !important; } \
  145. .stsh_border_top { border-bottom-color: #333 !important; } \
  146. .stsh_border_middle { border-top-color: #333 !important; } \
  147. .stsh_border_bottom { border-top-color: #333 !important; border-bottom-color: #333 !important; } \
  148. .stsh_suggestion_header { color: #A4B23C; } \
  149. .stsh_suggestion_comment:before { background-color: #E15417 !important; } \
  150. .stsh_suggestion_pending:before { background-color: #DDD !important; } \
  151. .stsh_suggestion_approved:before { background-color: #A4B23C !important; } \
  152. .stsh_suggestion_declined:before { background-color: #F22 !important; } \
  153. .stsh_suggestion_applied:before { background-color: #2EBCEB !important; } \
  154. .stsh_suggestion_removed:before { background-color: #777 !important; } \
  155. .stsh_suggestion { list-style: none; } \
  156. .stsh_suggestion:before { \
  157. content: ''; display: inline-block; position: relative; height: 6px; width: 6px; \
  158. border-radius: 3px; background-clip: padding-box; margin-right: -6px; \
  159. top: -1px; left: -12px; background-color: green; }\
  160. #stsh_frame { \
  161. text-align: center; position: fixed; z-index: 10; \
  162. top: 100px; left: 50%; margin-left: -322px;} \
  163. #stsh_frame_sub { \
  164. background-color: #111; width: 600px; display: inline-block; \
  165. padding: 20px; border: 2px solid #cf9e5f; } \
  166. .stsh_blue { color: #2EBCEB; } \
  167. .stsh_blue_light { color: #87BEED; } \
  168. .stsh_blue_light2 { color: #5C80A1; } \
  169. .stsh_blue_dark { color: #1B6A85; } \
  170. .stsh_green { color: #a4b23c !important; } \
  171. .stsh_green_dark { color: #3a482a; } \
  172. .stsh_red { color: #F22; } \
  173. .stsh_red_light { color: #4dc0f0; } \
  174. .stsh_white { color: #e1e1e1; } \
  175. .stsh_grey { color: #777 !important; } \
  176. .stsh_orange { color: #E15417; } \
  177. .stsh_orange_light { color: #CF8B37; } \
  178. .stsh_orange_light2 { color: #EDB687; } \
  179. .stsh_orange_light3 { color: #FFAA40; } \
  180. .stsh_orange_dark { color: #a75124; } \
  181. .stsh_aqua { color: #538583; } \
  182. .stsh_pink { color: pink; } \
  183. .stsh_yellow { color: #E0B816; } \
  184. .stsh_yellow_light { color: #E0CA70; } \
  185. .stsh_greenyellow_light { color: #D1E070; } \
  186. .stsh_purple { color: #a166f4; } \
  187. .stsh_border_green { border-color: #76802B !important; } \
  188. .stsh_border_green_left { border-color: #76802B #474D1A #76802B #76802B !important; } \
  189. .stsh_cursor_notallowed { cursor: not-allowed !important; } \
  190. .stsh_cursor_pointer { cursor: pointer !important; } \
  191. .stsh_cursor_default { cursor: default !important; } \
  192. .stsh_cursor_help { cursor: help !important; } \
  193. .stsh_inline { display: inline; } \
  194. #stsh_showing { \
  195. color: #CCDAD6; position: fixed; z-index: 1001; \
  196. right: 12px; bottom: 12px; text-align: right; line-height: 14px;} \
  197. #stsh_showing_current { \
  198. color: #CCDAD6; position: fixed; z-index: 1001; \
  199. right: 12px; bottom: 28px; text-align: right; line-height: 14px;} \
  200. .stsh_showing_counter { \
  201. display: inline-block; min-width: 60px; text-align: center; } \
  202. .stsh_showing_header { \
  203. color: #CCDAD6; display: inline-block; width: 135px; \
  204. text-align: center; padding-top: 10px; } \
  205. .stsh_showing_group { \
  206. position: fixed; z-index: 3; right: 10px; top: 74px; \
  207. line-height: 24px; text-align: right; } \
  208. .stsh_home_header { color: #CCDAD6; display: inline-block; padding-top: 10px; } \
  209. .stsh_home_group { \
  210. position: fixed; z-index: 3; right: 0px; top: 74px; \
  211. line-height: 24px; text-align: center; width: 164px; } \
  212. .stsh_home_group > div > .stsh_a_button { border-top-color: #333; border-bottom-color: #333; } \
  213. .stsh_home_group > div > .stsh_a_button:first-child { border-top-color: #777; } \
  214. .stsh_home_group > div > .stsh_a_button:last-child { border-bottom-color: #777; } \
  215. .stsh_home_group > div > div > .stsh_a_button { border-top-color: #333; border-bottom-color: #333; } \
  216. .stsh_home_group > div > div > .stsh_a_button:first-child:not(:last-child) { border-right-color: #333; } \
  217. .stsh_home_group > div > div > .stsh_a_button:last-child:not(:first-child) { border-left-color: #333; } \
  218. .stsh_home_group > div > div:first-child > .stsh_a_button { border-top-color: #777; } \
  219. .stsh_home_group > div > div:last-child > .stsh_a_button { border-bottom-color: #777; } \
  220. .stsh_home_group .stsh_a_button { cursor: pointer; } \
  221. .stsh_menu_group { \
  222. position: fixed; z-index: 3; right: 12px; top: 84px; \
  223. line-height: 24px; text-align: right; } \
  224. .stsh_group_space { margin-top: 3px; } \
  225. .stsh_scroll_header { \
  226. color: #CCDAD6; display: inline-block; width: 130px; \
  227. text-align: center; padding-top: 10px; } \
  228. #stsh_specialEvent { position: absolute; z-index: 2; right: 164px; top: 13px; } \
  229. @media screen and (min-width: 1500px) { \
  230. #stsh_specialEvent { position: fixed; } \
  231. } \
  232. .stsh_snapshot { \
  233. position: absolute; top: 320px; left: 790px; \
  234. width: 140px; text-align: center; color: #FFF; } \
  235. .stsh_text_comment_header { vertical-align: top; } \
  236. .stsh_text_comment { vertical-align: top; display: inline-block; max-width: 850px; } \
  237. .stsh_action_approve, .stsh_action_approve_next { color: #A4B23C } \
  238. .stsh_action_decline, .stsh_action_decline_next { color: #F22 } \
  239. #stsh_autoApprove { vertical-align: -2px; margin-left: 15px; margin-right: 1px; } \
  240. .stsh_unselectable { \
  241. -webkit-touch-callout: none !important; \
  242. -webkit-user-select: none !important; \
  243. -khtml-user-select: none !important; \
  244. -moz-user-select: none !important; \
  245. -ms-user-select: none !important; \
  246. user-select: none !important; } \
  247. .stsh_a_button { \
  248. background-color: #1D1D1D; \
  249. font-family: tahoma,arial,helvetica,trebuchet ms,sans-serif; \
  250. color: #E1E1E1; font-size: 13px; border: 1px solid #777; padding: 1px 9px; } \
  251. .stsh_a_button:link, .stsh_a_button:hover, .stsh_a_button:active, .stsh_a_button:visited { \
  252. color: #E1E1E1; text-decoration: none; } \
  253. .stsh_a_button.stsh_btn { \
  254. display: inline-block; padding: 0px; \
  255. height: 19px; line-height: 19px; width: 88px; } \
  256. .stsh_a_button.stsh_btn_short { \
  257. display: inline-block; padding: 0px; \
  258. height: 19px; line-height: 19px; min-width: 54px; } \
  259. .stsh_a_button.stsh_btn_med { \
  260. display: inline-block; padding: 0px; \
  261. height: 19px; line-height: 19px; min-width: 110px; } \
  262. .stsh_a_button.stsh_btn_long { \
  263. display: inline-block; padding: 0px; \
  264. height: 19px; line-height: 19px; min-width: 134px; } \
  265. .stsh_lineCounter_outer { position: relative; } \
  266. .stsh_lineCounter { \
  267. position: absolute; width: 30px; left: -35px; top: -28px; \
  268. line-height: 28px; text-align: right; \
  269. color: #ACACAC; font-size: 9px; text-shadow: 1px 1px 1px #111; } \
  270. .stsh_glossary_term { min-width: 50px; display: inline-block; } \
  271. .stsh_glossary_header { font-family: Verdana; } \
  272. .stsh_glossary_header, .stsh_glossary_header td { color: #DDD; } \
  273. .stsh_glossary_header *, .stsh_glossary_header td * { color: #858585; } \
  274. .stsh_glossary_header > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(4) { \
  275. width: 10px !important; } \
  276. .stsh_comment_img { \
  277. display: block; max-width: 400px; max-height: 225px; \
  278. margin-top: 5px; margin-bottom: 20px; } \
  279. .stsh_comment_img_zoom { cursor: zoom-in; cursor: -webkit-zoom-in; cursor: -moz-zoom-in; } \
  280. .stsh_hours_curDate { color: #A4B23C; } \
  281. .stsh_hours_curDate input { border-color: #A4B23C; } \
  282. .stsh_text_submit_right { \
  283. height: 30px; width: 214px; margin-right: 5px; border-color: #777 #777 #777 #333; } \
  284. .stsh_truncate { \
  285. white-space: nowrap; overflow: hidden; text-overflow: ellipsis; \
  286. display: inline-block; vertical-align: bottom; } \
  287. .stsh_token_name { max-width: 500px; } \
  288. .stsh_token_share { max-width: 600px; font-size: 0.8em; direction: rtl; } \
  289. .stsh_token_share:hover { direction: ltr; } \
  290. .stsh_pad { padding-left: 2px; padding-right: 2px; } \
  291. .stsh_pad_left { padding-left: 4px; } \
  292. .stsh_pad_right { padding-right: 4px; } \
  293. .stsh_margin_left { margin-left: 4px; } \
  294. .stsh_margin_right { margin-right: 4px; } \
  295. .stsh_hidden { display: none !important; } \
  296. table.gradienttable .stsh_curLang td, table.gradienttable .stsh_dst_curLang td \
  297. , table.gradienttable .stsh_dst_curLang th { \
  298. background: transparent \
  299. linear-gradient(to bottom, #171717 0%, rgba(71, 77, 26, 0.66) 40%, #121212 100%) \
  300. repeat scroll 0% 0% !important; } \
  301. .stsh_delta #suggestion_value_new { border-color: #1B6A85; } \
  302. .stsh_delta .stsh_text_submit { \
  303. color: #2EBCEB; border-color: #1B6A85 #083F52 #1B6A85 #1B6A85 !important; } \
  304. .stsh_delta .stsh_text_submit_right { \
  305. color: #2EBCEB; border-color: #1B6A85 #1B6A85 #1B6A85 #083F52 !important; } \
  306. .stsh_delta .suggestions_list, .stsh_delta .suggestion { \
  307. border-color: #083F52 !important; } \
  308. .stsh_usThem tr:nth-child(odd) { background-color: #161616; } \
  309. .stsh_usThem tr:nth-child(even) { background-color: #202020; } \
  310. .stsh_usThem_langCur { background-color: #2F3317 !important; color: #E1E1E1; } \
  311. .stsh_dst_curLang, table.gradienttable .stsh_dst_curLang th, .stsh_dst_curLang a { \
  312. color: #2ebceb; } \
  313. .stsh_text_trn .lbAction textarea { max-width: 450px !important; } \
  314. .stsh_text_trn .lbAction input[value~='COMMENT'] { height: auto; } \
  315. .stsh_text_trn .stsh_text_submit { width: 190px !important; } \
  316. .stsh_text_trn .stsh_text_submit_right { \
  317. width: 184px !important; margin-right: 16px !important; } \
  318. .stsh_text_trn .suggestion { \
  319. color: #858585; border-width: 1px solid; \
  320. margin-top: -2px; padding-top: 0px; } \
  321. .stsh_text_trn .stsh_counter:after { margin-top: 3px; } \
  322. .stsh_text_trn .suggestion_error { \
  323. max-width: 450px; margin-left: 0px; margin-top: 16px; margin-bottom: -14px; } \
  324. .stsh_text_trn #stsh_autoApprove { display: none; } \
  325. .stsh_text_trn .stsh_autoApprove_label { display: none; } \
  326. .stsh_text_trn input[value='+1'] { display: none; } \
  327. .stsh_text_trn #replacementstatus { left: 140px !important; } \
  328. .stsh_text_trn .stsh_autoReplace_notice { margin-top: 14px; padding-left: 88px; } \
  329. .stsh_text_org, .stsh_text_trn { min-height: 21px; display: block; max-width: 470px !important; } \
  330. .stsh_text_org { margin-bottom: 3px; } \
  331. .stsh_autoLoginOption { display: inline-block; vertical-align: top; line-height: 69px; padding-left: 30px; } \
  332. #stsh_autoLogin { margin-right: 0px; } \
  333. .stsh_moveSuggestionContainer { margin-top: -3px; } \
  334. #stsh_moveSuggestionBox, #stsh_moveSuggestionList { margin-right: 5px; } \
  335. #stsh_hoursCalc_from { width: 130px; } \
  336. #stsh_hoursCalc_to { width: 130px; border-right: 1px #333 solid; } \
  337. #stsh_hoursCalc_toNow { border-left: 1px #333 solid; } \
  338. .stsh_nav_prev { border-right-color: #333; } \
  339. .stsh_nav_next { border-left-color: #333; } \
  340. .stsh_nav_group { display: inline-block; } \
  341. .stsh_nav_group .stsh_a_button { \
  342. display: inline-block; text-align: center; \
  343. line-height: 17px; min-width: 40px; } \
  344. .stsh_nav_group .stsh_a_button:first-child:not(:last-child) { border-right-color: #333; } \
  345. .stsh_nav_group .stsh_a_button:last-child:not(:first-child) { border-left-color: #333; } \
  346. .stsh_nav_group .stsh_a_button:not(:first-child):not(:last-child) { \
  347. border-left-color: #333; border-right-color: #333; } \
  348. .stsh_img_min { max-width: 200px !important; height: auto !important; } \
  349. .stsh_showHidden { \
  350. display: inherit !important; background-color: #1d1d1d; padding: 1px 5px; \
  351. max-height: inherit !important; height: inherit !important; } \
  352. .stsh_discussion_header input[type='button'] { \
  353. padding: 1px 6px; } \
  354. .stsh_counter { display: inline-block; } \
  355. .stsh_counter[data-counter='Char: 0 :: Word: 0 :: Byte: 0'] { display: none; } \
  356. .stsh_counter:after { content: attr(data-counter); position: absolute; \
  357. margin-left: -280px; width: 278px; text-align: right; } \
  358. .stsh_spanStatusOrg, .stsh_spanStatusTrn { display: block; margin-top: -4px; margin-bottom: 8px; } \
  359. .stsh_spanStatusSug { display: block; margin-top: 8px; margin-bottom: 12px; } \
  360. .stsh_autoCopy_header font { color: #a4b23c !important; font-weight: normal; font-family: Verdana;} \
  361. .stsh_glossary_move { color: #e1e1e1; margin-left: 4px; } \
  362. .stsh_sametoken_file { display: inline-block; } \
  363. .stsh_marker { color: #777 !important; display: inline-block; } \
  364. .stsh_sametoken_header .stsh_marker, .stsh_text_comment .stsh_marker { color: #e1e1e1 !important; } \
  365. .stsh_glossary_header .insertword { display: inline-block; } \
  366. .stsh_glossary_header td { padding-left: 16px; padding-right: 6px; } \
  367. .stsh_glossary_header td .stsh_glossary_term { margin-left: -16px; } \
  368. .stsh_profile_count { width: 100px; display: inline-block; text-align: center; } \
  369. .stsh_profile_count_sugg { margin-left: 13px; } \
  370. .stsh_comment_resolved_label { display: block; width: 300px; margin-bottom: 10px; } \
  371. .stsh_comment_resolved { vertical-align: -2px; margin-left: 0px; margin-right: 1px; } \
  372. .stsh_suggestion_comment_detail > strong:first-child, .stsh_comment_resolved_label > strong:first-child { \
  373. min-width: 64px; display: inline-block; } \
  374. .stsh_discussion_text { display: inline; } \
  375. .stsh_discussion_text.stsh_discussion_text_long { display: block; margin-left: 20px; } \
  376. .stsh_date_group { text-align: center; } \
  377. .stsh_date_group button { line-height: 19px; } \
  378. .stsh_date_group .stsh_date_cur { border-left-color: #333; border-right-color: #333; \
  379. margin-top: 22px !important; } \
  380. .stsh_date_group .stsh_date_prev { border-right-color: #333; margin-left: 2px; } \
  381. .stsh_date_group .stsh_date_next { border-left-color: #333; } \
  382. .stsh_autoReplace_header { font-family: Verdana; } \
  383. .stsh_autoReplace_instruction { width: 870px; } \
  384. .stsh_autoReplace_text { width: 300px; cursor: auto !important; } \
  385. .stsh_checkbox_label { margin-left: 10px; } \
  386. .stsh_checkbox_label > input[type='checkbox'] { vertical-align: -2px; margin-left: 0px; margin-right: 1px; } \
  387. .stsh_usThem_translation { min-width: 400px; } \
  388. .stsh_page_userActivity .dial { display: none; } \
  389. .stsh_page_userActivity table.curved { border: 2px solid #444; } \
  390. .stsh_page_usAndThem #leftAreaContainer > table > tbody:nth-child(1) > tr > td:nth-child(1) { \
  391. vertical-align: top; } \
  392. .stsh_page_usAndThem #leftAreaContainer > table, \
  393. .stsh_page_usAndThem #leftAreaContainer > table th, \
  394. .stsh_page_usAndThem #leftAreaContainer > table td { \
  395. border: 1px solid #333; border-collapse: collapse; padding: 4px; } \
  396. .stsh_btn_display { border-left-color: #333; border-right-color: #333; } \
  397. .stsh_btn_display:first-child { border-right-color: #777; } \
  398. .stsh_btn_display:last-child { border-left-color: #777; } \
  399. .stsh_autoReplace_notice { text-align: left; padding-left: 208px; } \
  400. a + br + #replacementstatus + br + .stsh_autoReplace_notice { \
  401. text-align: center; padding-left: 0px; } \
  402. .stsh_suggestion_list_empty { \
  403. border-top: 1px solid #505050 !important; border-left: 1px solid #505050 !important; padding-left: 2px; } \
  404. .stsh_suggestion_border_approved { border-color: #76802B !important; border-top: 1px solid; } \
  405. .stsh_suggestion_border_declined { border-color: #720D0D !important; } \
  406. .stsh_suggestion_border_approved + .stsh_suggestion_border_approved { border-top: none; } \
  407. .stsh_action_edit { border-left-color: #333; } \
  408. .stsh_header_org, .stsh_header_trn { width: 484px; position: relative; } \
  409. .stsh_copy_org, .stsh_copy_trn { position: absolute; margin-left: 8px; margin-top: 22px; border-color: #555; } \
  410. .stsh_copy_new { width: 80px; height: 30px; border-left-color: #333; border-right-color: #333; } \
  411. .stsh_copy_sug { border-right-color: #333; } \
  412. .stsh_suggestion_list_header { width: 961px; } \
  413. .stsh_suggestion_list_history { padding-left: 2px; } \
  414. .stsh_suggestion_list_history_related { border-color: #4D6C87; } \
  415. .stsh_page_home font[style='color:#EDB687;'] { padding-right: 4px; } \
  416. .stsh_home_discussion_file { cursor: pointer; } \
  417. @media screen and (max-height: 600px) { .stsh_home_section_scroll { display: none; } } \
  418. .stsh_home_hideOtherLang { margin-left: 16px; margin-top: 10px; width: 152px; } \
  419. ");
  420. }
  421.  
  422. function attachOnLoad(callback)
  423. {
  424. window.addEventListener("load", function (e)
  425. {
  426. callback();
  427. });
  428. }
  429.  
  430. function attachOnReady(callback)
  431. {
  432. document.addEventListener("DOMContentLoaded", function (e)
  433. {
  434. callback();
  435. });
  436. }
  437.  
  438. function insertBeforeElement(newNode, referenceNode)
  439. {
  440. referenceNode.parentNode.insertBefore(newNode, referenceNode);
  441. }
  442.  
  443. function insertAfterElement(newNode, referenceNode)
  444. {
  445. referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
  446. }
  447.  
  448. function removeElement(node)
  449. {
  450. node.parentElement.removeChild(node);
  451. }
  452.  
  453. function getByteCount(str)
  454. {
  455. str = String(str);
  456.  
  457. var count = 0;
  458. for (var i = 0; i < str.length; i++)
  459. {
  460. var c = str.charCodeAt(i);
  461. count += c < 128 ? 1 :
  462. c < 2048 ? 2 :
  463. c < 65536 ? 3 :
  464. c < 2097152 ? 4 :
  465. c < 67108864 ? 5 :
  466. c < 2147483648 ? 6 : 0;
  467. }
  468. return count;
  469. }
  470.  
  471. function escapeRegExp(str)
  472. {
  473. if (typeof str === "string")
  474. {
  475. return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
  476. }
  477. return "";
  478. }
  479.  
  480. function addKey(eleListener, eleClick, keyCodes, keyName, keyTitleMode, keyModifierName, checkModifierCallback)
  481. {
  482. /*
  483. eleClick:
  484. element, query
  485. keyCodes:
  486. code, name, array
  487. keyTitleMode:
  488. 0: do nothing
  489. 1: append value
  490. 2: add title if not exist
  491. 4: override title
  492. 8: append textContent
  493. 16: append textContent of firstElementChild
  494. keyModifierName:
  495. Ctrl, Ctrl+Shift, Alt
  496. */
  497. keyCodes = keyCodes || [0];
  498. keyName = keyName || "";
  499. keyTitleMode = keyTitleMode || 0;
  500. keyModifierName = keyModifierName || "";
  501. if (typeof checkModifierCallback !== "function")
  502. {
  503. checkModifierCallback = function(ev)
  504. {
  505. return ev.ctrlKey && ev.shiftKey && ev.altKey;
  506. };
  507. }
  508. if (typeof eleClick === "string")
  509. {
  510. keyTitleMode = 0;
  511. }
  512. if (!Array.isArray(keyCodes))
  513. {
  514. keyCodes = [keyCodes];
  515. }
  516. if (eleListener && eleClick)
  517. {
  518. // apply title
  519. var keyTitle = keyModifierName ? keyModifierName + "+" + keyName : "";
  520. if (keyTitle !== "" && keyTitleMode !== 0)
  521. {
  522. if ((keyTitleMode & 1) === 1)
  523. {
  524. // 1: append value
  525. if (typeof eleClick.value !== "undefined")
  526. {
  527. eleClick.value += " (" + keyTitle + ")";
  528. }
  529. }
  530. if ((keyTitleMode & 2) === 2)
  531. {
  532. // 2: add title if not exist
  533. if (!eleClick.title)
  534. {
  535. eleClick.title = keyTitle;
  536. }
  537. }
  538. if ((keyTitleMode & 4) === 4)
  539. {
  540. // 4: override title
  541. eleClick.title = keyTitle;
  542. }
  543. if ((keyTitleMode & 8) === 8)
  544. {
  545. // 8: append textContent
  546. eleClick.textContent += " (" + keyTitle + ")";
  547. }
  548. if ((keyTitleMode & 16) === 16)
  549. {
  550. // 16: append textContent of firstElementChild
  551. if (eleClick.firstElementChild)
  552. {
  553. eleClick.firstElementChild.textContent += " (" + keyTitle + ")";
  554. }
  555. }
  556. }
  557. eleListener.addEventListener("keydown", function (ev)
  558. {
  559. if (checkModifierCallback(ev))
  560. {
  561. var isSameKey = false;
  562. for (var i = 0; i < keyCodes.length; i++)
  563. {
  564. var keyCode = keyCodes[i];
  565. if (typeof keyCode === "number")
  566. {
  567. isSameKey = (ev.keyCode === keyCode);
  568. }
  569. else
  570. {
  571. // Firefox 32+
  572. isSameKey = (typeof ev.code !== "undefined" && ev.code === keyCode)
  573. }
  574. if (isSameKey)
  575. {
  576. break;
  577. }
  578. }
  579. if (isSameKey)
  580. {
  581. ev.preventDefault();
  582. var eleClickCur = null;
  583. if (typeof eleClick === "string")
  584. {
  585. eleClickCur = document.querySelector(eleClick);
  586. }
  587. else
  588. {
  589. eleClickCur = eleClick;
  590. }
  591. if (eleClickCur)
  592. {
  593. eleClickCur.focus();
  594. eleClickCur.click();
  595. }
  596. return false;
  597. }
  598. }
  599. }, true);
  600. }
  601. }
  602.  
  603. function addKeyCtrl(eleListener, eleClick, keyCode, keyName, keyTitleMode)
  604. {
  605. addKey(eleListener, eleClick, keyCode, keyName, keyTitleMode, "Ctrl", function(ev)
  606. {
  607. return ev.ctrlKey && !ev.shiftKey && !ev.altKey;
  608. });
  609. }
  610.  
  611. function addKeyCtrlShift(eleListener, eleClick, keyCode, keyName, keyTitleMode)
  612. {
  613. addKey(eleListener, eleClick, keyCode, keyName, keyTitleMode, "Ctrl+Shift", function(ev)
  614. {
  615. return ev.ctrlKey && ev.shiftKey && !ev.altKey;
  616. });
  617. }
  618.  
  619. function addKeyAlt(eleListener, eleClick, keyCode, keyName, keyTitleMode)
  620. {
  621. addKey(eleListener, eleClick, keyCode, keyName, keyTitleMode, "Alt", function(ev)
  622. {
  623. return !ev.ctrlKey && !ev.shiftKey && ev.altKey;
  624. });
  625. }
  626.  
  627. function addKeyCtrlEnter(form, input)
  628. {
  629. addKeyCtrl(form, input, ["Enter", 13], "Enter", 1|2);
  630. }
  631.  
  632. function addKeyCtrlShiftEnter(form, input)
  633. {
  634. addKeyCtrlShift(form, input, ["Enter", 13], "Enter", 1|2);
  635. }
  636.  
  637. function disableAfterClick(ele)
  638. {
  639. ele.addEventListener("click", function (e)
  640. {
  641. var ele = e.target;
  642. var attrClick = ele.getAttribute("onclick");
  643. if (attrClick && attrClick.indexOf("confirm") > -1)
  644. {
  645. // skip if has confirm
  646. return;
  647. }
  648. var tagName = ele.tagName;
  649. if (tagName === "INPUT")
  650. {
  651. // don't change color after disable
  652. var styleCp = window.getComputedStyle(ele);
  653. if (styleCp)
  654. {
  655. ele.style.setProperty("color", styleCp.color, "important");
  656. }
  657. ele.disabled = true;
  658. }
  659. else if (tagName === "IMG")
  660. {
  661. ele.removeAttribute("onclick");
  662. }
  663. else if (tagName === "A")
  664. {
  665. ele.setAttribute("onclick", "return false;");
  666. }
  667. }, true);
  668. }
  669.  
  670. function removeAllEventListeners(element)
  671. {
  672. if (element)
  673. {
  674. var clone = element.cloneNode(false);
  675. while (element.firstChild)
  676. {
  677. clone.appendChild(element.firstChild);
  678. }
  679. element.parentNode.replaceChild(clone, element);
  680. }
  681. }
  682.  
  683. function focusWithoutScroll(selector)
  684. {
  685. var ele = null;
  686. if (selector instanceof HTMLElement)
  687. {
  688. ele = selector;
  689. }
  690. else
  691. {
  692. ele = document.querySelector(selector);
  693. }
  694. if (ele)
  695. {
  696. var x = window.scrollX;
  697. var y = window.scrollY;
  698. ele.focus();
  699. window.scrollTo(x, y);
  700. }
  701. }
  702.  
  703. function scrollToId(id, offset)
  704. {
  705. scrollToElement("#" + id, offset);
  706. }
  707.  
  708. function scrollToElement(selector, offset)
  709. {
  710. if (typeof offset === "undefined")
  711. {
  712. offset = -20;
  713. }
  714. var ele = null;
  715. if (selector)
  716. {
  717. if (selector instanceof HTMLElement)
  718. {
  719. ele = selector;
  720. }
  721. else
  722. {
  723. ele = document.querySelector(selector);
  724. }
  725. if (ele)
  726. {
  727. ele.scrollIntoView(true);
  728. window.scrollBy(0, offset);
  729. }
  730. }
  731. }
  732.  
  733. function resizeSuggestionBox()
  734. {
  735. var script = document.createElement('script');
  736. script.innerHTML =
  737. " \
  738. /* STSH JS - resizeSuggestionBox */ \
  739. var stsh_showSuggestionsBox_start = getTimeMs(); \
  740. var stsh_showSuggestionsBox_itv = setIntervalCustom(function() \
  741. { \
  742. var stsh_showSuggestionsBox_isEnd = false; \
  743. var stsh_showSuggestionsBox_cur = getTimeMs(); \
  744. if (typeof showSuggestionsBox !== 'undefined') \
  745. { \
  746. showSuggestionsBox = function(url) \
  747. { \
  748. /* Edit from STS */ \
  749. g_suggestionsBoxIsOpen = true; \
  750. $('suggestions_box_outer').appear( \
  751. { \
  752. duration : 0.1 \
  753. } \
  754. ); \
  755. $('suggestions_iframe').setAttribute('src', url); \
  756. if (!Prototype.Browser.IE) \
  757. { \
  758. $('suggestions_iframe').focus(); \
  759. } \
  760. $('suggestions_iframe').style.height = (document.viewport.getHeight() * 0.99) + 'px'; \
  761. return false; \
  762. }; \
  763. stsh_showSuggestionsBox_isEnd = true; \
  764. } \
  765. if (stsh_showSuggestionsBox_isEnd || stsh_showSuggestionsBox_cur - stsh_showSuggestionsBox_start > 10000) \
  766. { \
  767. clearInterval(stsh_showSuggestionsBox_itv); \
  768. } \
  769. }, 300); \
  770. ";
  771. document.head.appendChild(script);
  772.  
  773. window.addEventListener("resize", function()
  774. {
  775. var iframe = document.querySelector("#suggestions_iframe");
  776. if (iframe)
  777. {
  778. iframe.style.height = (window.innerHeight * 0.99) + "px";
  779. }
  780. });
  781. }
  782.  
  783. function isRally()
  784. {
  785. var date = new Date();
  786. var year = date.getUTCFullYear();
  787. var month = date.getUTCMonth() + 1;
  788. var day = date.getUTCDate();
  789. if ((month > 9) || (month === 9 && day >= 22) || (month === 0 && day <= 2))
  790. {
  791. return true;
  792. }
  793. return false;
  794. }
  795.  
  796. function getQueryByName(name, url)
  797. {
  798. if (!url)
  799. {
  800. url = (!window.location) ? "" : window.location.search;
  801. }
  802. name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  803. var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
  804. var results = regex.exec(url);
  805. var retVal = "";
  806. if (results)
  807. {
  808. retVal = results[1].replace(/\+/g, " ");
  809. try
  810. {
  811. retVal = decodeURIComponent(retVal);
  812. }
  813. catch (ex)
  814. {
  815. console.error("getQueryByName", ex.message);
  816. }
  817. }
  818. return retVal;
  819. }
  820.  
  821. function padZero(num, size)
  822. {
  823. return (1e15 + num + "").slice(-size);
  824. }
  825.  
  826. function padZeroHex(num, size)
  827. {
  828. return ("00000000000000000000000" + num.toString(16)).slice(-size).toUpperCase();
  829. }
  830.  
  831. function randNum(min, max)
  832. {
  833. return Math.round(Math.random() * (max - min) + min);
  834. }
  835.  
  836. function isLastIndex(src, des)
  837. {
  838. if (src !== null && src !== "" && des !== null && des !== "")
  839. {
  840. if (src.lastIndexOf(des) === src.length - 1)
  841. {
  842. return true;
  843. }
  844. }
  845. return false;
  846. }
  847.  
  848. function isSpecialChar(ch)
  849. {
  850. var chCode = -1;
  851. if (typeof ch === 'number')
  852. {
  853. chCode = ch;
  854. }
  855. else
  856. {
  857. chCode = ch.charCodeAt(0);
  858. }
  859. if ((chCode > -1 && chCode < 9) // 0-8
  860. || (chCode > 10 && chCode < 13) // 11-12
  861. || (chCode > 13 && chCode < 32)) // 14-31
  862. {
  863. return true;
  864. }
  865. return false;
  866. }
  867.  
  868. function hasSpecialChar(str)
  869. {
  870. 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]+/;
  871. return rgxSpCh.test(str);
  872. }
  873. function checkSpecialCharMatched(str1, str2)
  874. {
  875. // return (status, numSp1, numSp2)
  876. // status: 0:Match, 1:NotMatch, 2:NotEqual
  877. str1 = str1 || "";
  878. str2 = str2 || "";
  879. var strOut1 = "";
  880. var strOut2 = "";
  881. for (var i = 0; i < str1.length; i++)
  882. {
  883. if (isSpecialChar(str1[i]))
  884. {
  885. strOut1 += str1[i];
  886. }
  887. }
  888. for (var i = 0; i < str2.length; i++)
  889. {
  890. if (isSpecialChar(str2[i]))
  891. {
  892. strOut2 += str2[i];
  893. }
  894. }
  895. var retVal = 0;
  896. if (strOut1 === strOut2)
  897. retVal = 0;
  898. else if (strOut1.length === strOut2.length)
  899. retVal = 1;
  900. else
  901. retVal = 2;
  902. return new Array(retVal, strOut1.length, strOut2.length);
  903. }
  904.  
  905. function countDiacriticalMark(str)
  906. {
  907. str = str || "";
  908. var rgxDct = /[\u0300-\u036F]/g;
  909. var matchDct = str.match(rgxDct);
  910. var countDct = matchDct ? matchDct.length : 0;
  911.  
  912. return countDct;
  913. }
  914.  
  915. function countDescendantElement(ele)
  916. {
  917. var countElement = 0;
  918. if (ele instanceof Element)
  919. {
  920. var children = ele.children;
  921. countElement = children.length;
  922. for (var i = 0; i < children.length; i++)
  923. {
  924. countElement += countDescendantElement(children[i]);
  925. }
  926. }
  927. return countElement;
  928. }
  929.  
  930. function trimSpace(str)
  931. {
  932. if (str !== null)
  933. {
  934. return str.replace(/^[ \r\n\t]+/, "").replace(/[ \r\n\t]+$/, "");
  935. }
  936. return str;
  937. }
  938.  
  939. function trimTab(str)
  940. {
  941. if (str !== null)
  942. {
  943. return str.replace(/^[\r\n\t]+/, "").replace(/[\r\n\t]+$/, ""); //.replace(/\t+<\//, "<");
  944. }
  945. return str;
  946. }
  947.  
  948. function trimTabLeft(str)
  949. {
  950. if (str !== null)
  951. {
  952. return str.replace(/^[\r\n\t]+/, "");
  953. }
  954. return str;
  955. }
  956.  
  957. function trimTabRight(str)
  958. {
  959. if (str !== null)
  960. {
  961. return str.replace(/[\r\n\t]+$/, "");
  962. }
  963. return str;
  964. }
  965.  
  966. function trimElement(ele)
  967. {
  968. if (ele instanceof Element)
  969. {
  970. if (!ele.firstElementChild)
  971. {
  972. ele.textContent = trimTab(ele.textContent);
  973. }
  974. else
  975. {
  976. if (ele.firstChild.nodeType === document.TEXT_NODE)
  977. {
  978. ele.firstChild.textContent = trimTabLeft(ele.firstChild.textContent);
  979. }
  980. if (ele.lastChild.nodeType === document.TEXT_NODE)
  981. {
  982. ele.lastChild.textContent = trimTabRight(ele.lastChild.textContent);
  983. }
  984. }
  985. }
  986. return ele;
  987. }
  988.  
  989. if (!String.prototype.endsWith)
  990. {
  991. String.prototype.endsWith = function(searchString, position)
  992. {
  993. var subjectString = this.toString();
  994. if (typeof position !== 'number' || !isFinite(position)
  995. || Math.floor(position) !== position || position > subjectString.length)
  996. {
  997. position = subjectString.length;
  998. }
  999. position -= searchString.length;
  1000. var lastIndex = subjectString.indexOf(searchString, position);
  1001. return lastIndex !== -1 && lastIndex === position;
  1002. };
  1003. }
  1004.  
  1005. function reload()
  1006. {
  1007. var curHref = window.location.href;
  1008. var posHashtag = curHref.indexOf("#");
  1009. if (posHashtag > -1)
  1010. {
  1011. window.location = curHref.substr(0, posHashtag);
  1012. }
  1013. else
  1014. {
  1015. window.location = curHref;
  1016. }
  1017. }
  1018.  
  1019. function getCookie(c_name)
  1020. {
  1021. var c_value = document.cookie;
  1022. var c_start = c_value.indexOf(" " + c_name + "=");
  1023. if (c_start === -1) {
  1024. c_start = c_value.indexOf(c_name + "=");
  1025. }
  1026. if (c_start === -1) {
  1027. c_value = null;
  1028. }
  1029. else {
  1030. c_start = c_value.indexOf("=", c_start) + 1;
  1031. var c_end = c_value.indexOf(";", c_start);
  1032. if (c_end === -1) {
  1033. c_end = c_value.length;
  1034. }
  1035. c_value = unescape(c_value.substring(c_start, c_end));
  1036. }
  1037. return c_value;
  1038. }
  1039.  
  1040. var isVisible = (function()
  1041. {
  1042. var stateKey;
  1043. var eventKey;
  1044. var keys =
  1045. {
  1046. hidden: "visibilitychange",
  1047. webkitHidden: "webkitvisibilitychange",
  1048. mozHidden: "mozvisibilitychange",
  1049. msHidden: "msvisibilitychange"
  1050. };
  1051. for (stateKey in keys)
  1052. {
  1053. if (stateKey in document)
  1054. {
  1055. eventKey = keys[stateKey];
  1056. break;
  1057. }
  1058. }
  1059. return function(c)
  1060. {
  1061. if (c)
  1062. {
  1063. document.addEventListener(eventKey, c);
  1064. }
  1065. return !document[stateKey];
  1066. }
  1067. })();
  1068.  
  1069. function isDstUs(year, month, day, hour)
  1070. {
  1071. // Support: 2007 - 2029
  1072. // Params: 2016, 3, 1, 15 === 1 Mar 2016 15:00
  1073. var isDst = false;
  1074. try
  1075. {
  1076. var y = parseInt(year);
  1077. var m = parseInt(month);
  1078. var d = parseInt(day);
  1079. var h = parseInt(hour);
  1080. var checkDstUsa = function(dayMar, dayNov, m, d, h)
  1081. {
  1082. var isDst = false;
  1083. if ((m === 3 && d >= dayMar) || (m > 3 && m < 11) || (m === 11 && d <= dayNov))
  1084. isDst = true;
  1085. if ((m === 3 && d === dayMar && h < 2) || (m === 11 && d === dayNov && h >= 2))
  1086. isDst = false;
  1087. return isDst;
  1088. }
  1089. if (y === 2007 || y === 2012 || y === 2018 || y === 2029)
  1090. {
  1091. isDst = checkDstUsa(11, 4, m, d, h);
  1092. }
  1093. else if (y === 2013 || y === 2019 || y === 2024)
  1094. {
  1095. isDst = checkDstUsa(10, 3, m, d, h);
  1096. }
  1097. else if (y === 2008 || y === 2014 || y === 2025)
  1098. {
  1099. isDst = checkDstUsa(9, 2, m, d, h);
  1100. }
  1101. else if (y === 2009 || y === 2015 || y === 2020 || y === 2026)
  1102. {
  1103. isDst = checkDstUsa(8, 1, m, d, h);
  1104. }
  1105. else if (y === 2010 || y === 2021 || y === 2027)
  1106. {
  1107. isDst = checkDstUsa(14, 7, m, d, h);
  1108. }
  1109. else if (y === 2011 || y === 2016 || y === 2022)
  1110. {
  1111. isDst = checkDstUsa(13, 6, m, d, h);
  1112. }
  1113. else if (y === 2017 || y === 2023 || y === 2028)
  1114. {
  1115. isDst = checkDstUsa(12, 5, m, d, h);
  1116. }
  1117. }
  1118. catch (ex)
  1119. {
  1120. console.error("isDstUs", ex.message);
  1121. }
  1122. return isDst;
  1123. }
  1124.  
  1125. function getDateIsoUs(unixTs)
  1126. {
  1127. var dateUs = unixTs ? new Date(unixTs * 1000) : new Date();
  1128. dateUs.setTime(dateUs.getTime() - (1000 * 60 * 60 * 8)); // GMT-8
  1129. if (isDstUs(dateUs.getUTCFullYear(), dateUs.getUTCMonth() + 1, dateUs.getUTCDate(), dateUs.getUTCHours()))
  1130. {
  1131. dateUs.setTime(dateUs.getTime() + (1000 * 60 * 60 * 1)); // GMT-7
  1132. }
  1133. return dateUs.toISOString();
  1134. }
  1135.  
  1136. function getDateUs(unixTs)
  1137. {
  1138. return getDateIsoUs(unixTs).substr(0, 10);
  1139. }
  1140.  
  1141. function getDateTimeUs(unixTs)
  1142. {
  1143. var dateIso = getDateIsoUs(unixTs);
  1144. return dateIso.substr(0, 10) + " " + dateIso.substr(11, 8);
  1145. }
  1146.  
  1147. function getTimeUs(unixTs)
  1148. {
  1149. return getDateIsoUs(unixTs).substr(11, 5);
  1150. }
  1151.  
  1152. function getDateIsoGmt(unixTs)
  1153. {
  1154. var date = unixTs ? new Date(unixTs * 1000) : new Date();
  1155. return date.toISOString();
  1156. }
  1157.  
  1158. function getDateGmt(unixTs)
  1159. {
  1160. return getDateIsoGmt(unixTs).substr(0, 10);
  1161. }
  1162.  
  1163. function getTimeMs(unixTs)
  1164. {
  1165. return unixTs ? new Date(unixTs * 1000).getTime() : new Date().getTime();
  1166. }
  1167.  
  1168. function getUnixTimestamp(date)
  1169. {
  1170. return parseInt((date ? new Date(date) : new Date()).getTime() / 1000);
  1171. }
  1172. var pattUrlTimestamp =
  1173. {
  1174. type1: /\?t=[0-9]{6,}\&/g,
  1175. type2: /\&t=[0-9]{6,}/g,
  1176. type3: /\?t=[0-9]{6,}/g,
  1177. type4: /\&[0-9]{6,}\&/g,
  1178. type5: /\&$/,
  1179. };
  1180.  
  1181. function cleanUrlTimestamp(eles)
  1182. {
  1183. if (!eles || !eles.length)
  1184. return;
  1185.  
  1186. for (var i = 0; i < eles.length; i++)
  1187. {
  1188. var val = "";
  1189. var attr = "";
  1190. if (eles[i].tagName === "A")
  1191. {
  1192. attr = "href";
  1193. }
  1194. else if (eles[i].tagName === "FORM")
  1195. {
  1196. attr = "action";
  1197. }
  1198. else if (eles[i].tagName === "DIV")
  1199. {
  1200. attr = "onclick";
  1201. }
  1202. else if (eles[i].tagName === "INPUT")
  1203. {
  1204. attr = "onclick";
  1205. if (eles[i].name === "t")
  1206. {
  1207. removeElement(eles[i]);
  1208. continue;
  1209. }
  1210. }
  1211. var isEdit = false;
  1212. val = eles[i].getAttribute(attr);
  1213. if (pattUrlTimestamp.type1.test(val))
  1214. {
  1215. eles[i].setAttribute(attr, val.replace(pattUrlTimestamp.type1, "?"));
  1216. isEdit = true;
  1217. }
  1218. else if (pattUrlTimestamp.type2.test(val))
  1219. {
  1220. eles[i].setAttribute(attr, val.replace(pattUrlTimestamp.type2, ""));
  1221. isEdit = true;
  1222. }
  1223. else if (pattUrlTimestamp.type3.test(val))
  1224. {
  1225. eles[i].setAttribute(attr, val.replace(pattUrlTimestamp.type3, ""));
  1226. isEdit = true;
  1227. }
  1228. if (isEdit)
  1229. {
  1230. val = eles[i].getAttribute(attr);
  1231. }
  1232. if (pattUrlTimestamp.type4.test(val))
  1233. {
  1234. eles[i].setAttribute(attr, val.replace(pattUrlTimestamp.type4, "&"));
  1235. }
  1236. if (pattUrlTimestamp.type5.test(val))
  1237. {
  1238. eles[i].setAttribute(attr, val.replace(pattUrlTimestamp.type5, ""));
  1239. }
  1240. }
  1241. }
  1242.  
  1243. var timeoutList = [];
  1244. var intervalList = [];
  1245.  
  1246. function setTimeoutCustom(func, tm, params)
  1247. {
  1248. var id = setTimeout(func, tm, params);
  1249. timeoutList.push(id);
  1250. return id;
  1251. }
  1252.  
  1253. function clearTimeoutAll()
  1254. {
  1255. for (var i = 0; i < timeoutList.length; i++)
  1256. {
  1257. clearTimeout(timeoutList[i]);
  1258. }
  1259. }
  1260.  
  1261. function setIntervalCustom(func, tm, params)
  1262. {
  1263. var id = setInterval(func, tm, params);
  1264. intervalList.push(id);
  1265. return id;
  1266. }
  1267.  
  1268. function clearIntervalAll()
  1269. {
  1270. for (var i = 0; i < intervalList.length; i++)
  1271. {
  1272. clearInterval(intervalList[i]);
  1273. }
  1274. }
  1275.  
  1276. function main()
  1277. {
  1278. var perfStart = 0;
  1279. if (performance && performance.now)
  1280. {
  1281. perfStart = performance.now();
  1282. }
  1283. var url = document.documentURI;
  1284. var lang = getCookie("Language");
  1285. var userId = "";
  1286. var userName = "";
  1287. var timingInit =
  1288. {
  1289. initNameSpace: 100,
  1290. refreshError: 60000,
  1291. cleanLinks: 100,
  1292. removeHorizonScroll: 100,
  1293. resizeTextNew: 100,
  1294. improveGlossary: 200,
  1295. bindLastText: 100,
  1296. insertAtCaret: 500,
  1297. pasteLastComment: 250,
  1298. autoApprove: 2000,
  1299. pasteLastSuggestion: 300,
  1300. hideCursor: 3000,
  1301. expandTextarea: 100,
  1302. focusModAction: 200,
  1303. autoReplaceText: 250,
  1304. findNextUnmatched: 500,
  1305. openFrame: 1000,
  1306. improveStatistics: 100,
  1307. autoLogin: 3000,
  1308. authSubmit: 3000,
  1309. bindObserverKeyList: 200,
  1310. pageUserActivity: 100,
  1311. };
  1312. if (document.body)
  1313. {
  1314. document.body.classList.add("stsh");
  1315. }
  1316. else
  1317. {
  1318. setTimeoutCustom(function()
  1319. {
  1320. if (document.body)
  1321. {
  1322. document.body.classList.add("stsh");
  1323. }
  1324. }, timingInit.initNameSpace);
  1325. }
  1326. // Auto refresh when error
  1327. {
  1328. var h1 = document.querySelector("#leftAreaContainer > h1, body > h1");
  1329. if (h1)
  1330. {
  1331. var text = h1.textContent.trim();
  1332. if (text === "Steam Translation Server - Maintenance Warning"
  1333. || text === "Forbidden")
  1334. {
  1335. console.log("stsh: refresh");
  1336. setTimeoutCustom(reload, timingInit.refreshError);
  1337. return;
  1338. }
  1339. }
  1340. }
  1341.  
  1342. // Clean links
  1343. {
  1344. setTimeoutCustom(function()
  1345. {
  1346. var eles = document.querySelectorAll("a, form[action], input");
  1347. cleanUrlTimestamp(eles);
  1348. }, timingInit.cleanLinks);
  1349. }
  1350. // Fix STS URL paths
  1351. {
  1352. var arrQuery = ["img"];
  1353. var arrAttr = ["src"];
  1354. for (var j = 0; j < arrQuery.length; j++)
  1355. {
  1356. var eles = document.querySelectorAll(arrQuery[j]);
  1357. for (var i = 0; i < eles.length; i++)
  1358. {
  1359. var attr = eles[i].getAttribute(arrAttr[j]);
  1360. if (attr)
  1361. {
  1362. var attrNew = attr.replace(/<\?=BASE_URL_CURRENT\?>/g, "/");
  1363. if (attrNew !== attr)
  1364. {
  1365. console.log("STS URL path is missing: " + eles[i].outerHTML);
  1366. eles[i].setAttribute(arrAttr[j], attrNew);
  1367. }
  1368. }
  1369. }
  1370. }
  1371. }
  1372. // Set current user
  1373. {
  1374. userId = GM_getValue("user", "");
  1375. userName = GM_getValue("name", "");
  1376. if (url.indexOf("/home.php") > -1)
  1377. {
  1378. var eleUser = document.querySelector("#leftAreaContainer > b > a[href^='user_activity.php?user=']");
  1379. if (eleUser)
  1380. {
  1381. var user = getQueryByName("user", eleUser.href);
  1382. if (user && userId !== user)
  1383. {
  1384. userId = user;
  1385. GM_setValue("user", userId);
  1386. }
  1387. var name = eleUser.textContent.trim();
  1388. if (name && userName !== name)
  1389. {
  1390. userName = name;
  1391. GM_setValue("name", userName);
  1392. }
  1393. }
  1394. }
  1395. }
  1396.  
  1397. var eleLogout = document.querySelector("#logout");
  1398. if (eleLogout)
  1399. {
  1400. var logoutHtml =
  1401. ' \
  1402. <a class="stsh_a_button stsh_btn_myProfile stsh_border_left" target="_blank" \
  1403. href="%PROFILE%" title="%NAME%">My Profile</a>\
  1404. <input name="login_button" class="stsh_border_right" value="Logout?" \
  1405. type="submit" onclick="return confirm(\'Logout?\');" /> \
  1406. ';
  1407. logoutHtml = logoutHtml
  1408. .replace("%PROFILE%", "/user_activity.php" + (userId ? "?user=" + userId : ""))
  1409. .replace("%NAME%", userName);
  1410. eleLogout.innerHTML = logoutHtml;
  1411. // Special event button
  1412. {
  1413. if (isRally())
  1414. {
  1415. var divSpecial = document.createElement("div");
  1416. divSpecial.id = "stsh_specialEvent";
  1417. divSpecial.innerHTML =
  1418. ' \
  1419. <a class="stsh_a_button" target="_blank" href="/rally.php">Year-End Rally</a> \
  1420. ';
  1421. eleLogout.parentElement.appendChild(divSpecial);
  1422. }
  1423. }
  1424. }
  1425. // Declare functions
  1426. var removeStsHtmlTags = null;
  1427. var displayHtmlTags = null;
  1428. {
  1429. removeStsHtmlTags = function(ele, isRemovedBrowserGenerated)
  1430. {
  1431. isRemovedBrowserGenerated = (typeof isRemovedBrowserGenerated === "undefined")
  1432. ? true : !!isRemovedBrowserGenerated;
  1433. var html = "";
  1434. if (ele)
  1435. {
  1436. html = (typeof ele.dataset.stshHtml === "undefined")
  1437. ? trimTab(ele.innerHTML) : ele.dataset.stshHtml;
  1438. if (ele.classList.contains("stsh_text_org"))
  1439. {
  1440. html = html.replace(/<span style="color:#ff0000;">(.*?)<\/span>/ig, "$1")
  1441. .replace(/<span style="color:#ffffff;">(.*?)<\/span>/ig, "$1")
  1442. .replace(/<font style="BACKGROUND-COLOR: blue">(.+?)<\/font>/ig, "$1")
  1443. .replace(/<font face="Times New Roman">(.+?)<\/font>/ig, "$1");
  1444. }
  1445. else if (ele.classList.contains("stsh_text_trn"))
  1446. {
  1447. html = html.replace(/<span style="color:#ff0000;">(.*?)<\/span>/ig, "$1")
  1448. .replace(/<span style="color:#ffffff;">(.*?)<\/span>/ig, "$1")
  1449. .replace(/<font face="Times New Roman">(.+?)<\/font>/ig, "$1");
  1450. }
  1451. else if (ele.classList.contains("suggestion_text"))
  1452. {
  1453. html = html.replace(/<span style="color:red;">(.*?)<\/span>/ig, "$1")
  1454. .replace(/<font face="Times New Roman">(.+?)<\/font>/ig, "$1");
  1455. }
  1456. if (isRemovedBrowserGenerated)
  1457. {
  1458. // Remove browser generated attributes and ending tags
  1459. // Regex .+? is "reluctant" that means "as few characters as it can"
  1460. html = html.replace(/="">/g, ">")
  1461. .replace(/([^\t])\t\t\t\t<\/[^\t ]+>$/, "$1")
  1462. .replace(/<script data-pagespeed-no-defer[\s\S]+?\/script>/ig, "")
  1463. .replace(/ data-pagespeed-url-hash=".+?"/ig, "")
  1464. .replace(/ onload="pagespeed.+?"/ig, "");
  1465. }
  1466. }
  1467. return html;
  1468. }
  1469. displayHtmlTags = function(ele)
  1470. {
  1471. if (ele)
  1472. {
  1473. ele.innerHTML = (typeof ele.dataset.stshHtml === "undefined")
  1474. ? trimTab(ele.innerHTML).replace(/\<span[^\>]+class=\"stsh_[\s\S]+?\/span\>/ig, "")
  1475. : ele.dataset.stshHtml;
  1476. var isSkip = false;
  1477. var isBb = (ele.textContent.indexOf("[/") > -1);
  1478. var isUsThem = false;
  1479. var isReplaceNewline = true;
  1480. var isReplaceScript = true;
  1481. var isDisplayBr = true;
  1482. ele.innerHTML = removeStsHtmlTags(ele, false);
  1483. if (ele.classList.contains("stsh_text_trn"))
  1484. {
  1485. if (ele.classList.contains("stsh_text_trn_empty"))
  1486. {
  1487. isSkip = true;
  1488. }
  1489. }
  1490. else if (ele.classList.contains("stsh_usThem_translation"))
  1491. {
  1492. isUsThem = true;
  1493. isReplaceNewline = false;
  1494. isReplaceScript = false;
  1495. isDisplayBr = false;
  1496. if (ele.innerHTML === "<i>--- Not Yet Translated ---</i>")
  1497. {
  1498. isSkip = true;
  1499. }
  1500. }
  1501. //isReplaceScript = false;
  1502. if (!isSkip)
  1503. {
  1504. ele.textContent = trimTab(ele.innerHTML);
  1505. var newHtml = ele.innerHTML;
  1506. if (!isBb)
  1507. {
  1508. if (isReplaceScript)
  1509. {
  1510. newHtml = newHtml
  1511. .replace(/&lt;script([^&]+)[\s\S]+?\/script&gt;/ig,
  1512. "<br>&lt;script$1&gt;...&lt;/script&gt;<br>")
  1513. .replace(/&lt;style([^&]+)[\s\S]+?\/style&gt;/ig,
  1514. "<br>&lt;style$1&gt;...&lt;/style&gt;<br>");
  1515. }
  1516. if (isReplaceNewline)
  1517. {
  1518. newHtml = newHtml
  1519. .replace(/\n/ig, "\n<br>");
  1520. }
  1521. newHtml = newHtml
  1522. // Remove browser generated attributes
  1523. .replace(/=""&gt;/ig, "&gt;")
  1524. // Remove browser generated ending tags
  1525. .replace(/([^\t])\t\t\t\t&lt;\/[^\t ]+&gt;$/i, "$1")
  1526. .replace(/&lt;/ig, '<span class="stsh_marker">&lt;')
  1527. .replace(/&gt;/ig, "&gt;</span>")
  1528. .replace(/&lt;li/ig, "<br>&lt;li")
  1529. .replace(/&amp;/ig, "&");
  1530. if (isDisplayBr)
  1531. {
  1532. newHtml = newHtml
  1533. .replace(/br([ \/]*)&gt;<\/span>/ig, "br$1&gt;</span><br>");
  1534. }
  1535. else
  1536. {
  1537. newHtml = newHtml
  1538. .replace(/<span class="stsh_marker">&lt;br([ \/]*)&gt;<\/span>/ig, "<br>");
  1539. }
  1540. }
  1541. else
  1542. {
  1543. if (isReplaceNewline)
  1544. {
  1545. newHtml = newHtml
  1546. .replace(/\n/ig, "\n<br>");
  1547. }
  1548. newHtml = newHtml
  1549. .replace(/\[/ig, '<span class="stsh_marker">[')
  1550. .replace(/\]/ig, "]</span>")
  1551. .replace(/&lt;font face="Times New Roman"&gt;-&lt;\/font&gt;/ig, "-")
  1552. .replace(/&amp;nbsp;/ig, " ");
  1553. }
  1554. if (isUsThem)
  1555. {
  1556. var status = newHtml.substr(67, 8);
  1557. //console.log(status);
  1558. if (status === "pending)")
  1559. {
  1560. newHtml = '<font style="color:CF8B37">(pending)</font>' + newHtml.substr(121);
  1561. }
  1562. else if (status === "approved")
  1563. {
  1564. newHtml = '<font style="color:A4B23C">(approved)</font>' + newHtml.substr(122);
  1565. }
  1566. else if (status === "outdated")
  1567. {
  1568. newHtml = '<font style="color:FF0000">(outdated)</font>' + newHtml.substr(122);
  1569. }
  1570. }
  1571. ele.innerHTML = newHtml;
  1572. }
  1573. }
  1574. }
  1575. }
  1576. // End Declare functions
  1577. if (url.indexOf("Us_And_Them.php") > -1)
  1578. {
  1579. document.body && document.body.classList.add("stsh_page_usAndThem");
  1580. var h1 = document.querySelector("#leftAreaContainer > h1:nth-child(2)");
  1581. if (h1)
  1582. {
  1583. var header = h1.textContent.trim();
  1584. var key = header.split(" ")[0];
  1585. h1.innerHTML = header.replace(key, "<a href='/translate.php?keyonly=1&search_input="
  1586. + encodeURIComponent(key) + "' >" + key + "</a>");
  1587. document.title = key + " - " + document.title;
  1588. }
  1589. // Hilight cur lang
  1590. {
  1591. var eleTable = document.querySelector("#leftAreaContainer > table");
  1592. if (eleTable)
  1593. {
  1594. eleTable.classList.add("stsh_usThem");
  1595. var eleLangCur = null;
  1596. var elesLang = eleTable.querySelectorAll("tr > td:nth-child(1) > a");
  1597. for (var i = 1; i < elesLang.length; i++)
  1598. {
  1599. if (lang === elesLang[i].textContent.trim().toLowerCase())
  1600. {
  1601. eleLangCur = elesLang[i].parentElement.parentElement;
  1602. break;
  1603. }
  1604. }
  1605. if (eleLangCur)
  1606. {
  1607. eleLangCur.classList.add("stsh_usThem_langCur");
  1608. }
  1609. if (elesLang.length > 1)
  1610. {
  1611. elesLang[0].parentElement.parentElement.classList.add("stsh_usThem_langEng")
  1612. }
  1613. }
  1614. }
  1615. // Normalize
  1616. // Add start/end marker to English text
  1617. {
  1618. var elesTranslation = document.querySelectorAll(
  1619. ".stsh_usThem > tbody:nth-child(1) > tr > td:nth-child(2)");
  1620. for (var i = 0; i < elesTranslation.length; i++)
  1621. {
  1622. elesTranslation[i].classList.add("stsh_usThem_translation");
  1623. var eleFirst = elesTranslation[i].firstElementChild;
  1624. if (eleFirst && eleFirst.textContent === "(outdated)")
  1625. {
  1626. // Fix STS inconsistent space
  1627. insertAfterElement(document.createTextNode(" "), eleFirst);
  1628. }
  1629. }
  1630. var container = "\"";
  1631. var tdEng = elesTranslation.length > 1 ? elesTranslation[0] : null;
  1632. if (tdEng)
  1633. {
  1634. //tdEng.innerHTML = container + tdEng.innerHTML + container;
  1635. }
  1636. }
  1637. // Add scroll to
  1638. // Add move up
  1639. {
  1640. var eleMenu = document.createElement("div");
  1641. document.body.appendChild(eleMenu);
  1642. eleMenu.innerHTML =
  1643. ' \
  1644. <div class="stsh_menu_group"> \
  1645. &nbsp; <span class="stsh_scroll_header">Scroll To</span>\
  1646. <br> &nbsp; <input value="English" \
  1647. class="stsh_btn_long" type="button" onclick="scrollToElement(\'.stsh_usThem_langEng\', -8); return false;" > \
  1648. <br> &nbsp; <input value="My lang" \
  1649. class="stsh_btn_long" type="button" onclick="scrollToElement(\'.stsh_usThem_langCur\', -30); return false;" > \
  1650. <div class="stsh_block_scrollToDiscussion stsh_inline"> \
  1651. <br> &nbsp; <input value="Discussion" \
  1652. class="stsh_btn_long" \
  1653. type="button" onclick="scrollToElement(\'a[name=\\\'tokendiscussion\\\']\'); return false;" > \
  1654. </div> \
  1655. <br> \
  1656. <br> &nbsp; <input value="Move up my lang" \
  1657. class="stsh_btn_long stsh_btn_moveLang" type="button" onclick="return false;" > \
  1658. <br> \
  1659. <div class="stsh_block_displayHtml stsh_inline"> \
  1660. <br> &nbsp; <input value="Display HTML tags" \
  1661. class="stsh_btn_long stsh_btn_displayHtmlTags" type="button" onclick="return false;" > \
  1662. <br> \
  1663. </div> \
  1664. <br> &nbsp; <input value="Refresh" \
  1665. class="stsh_btn_long" type="button" onclick="window.location = window.location.href; return false;" /> \
  1666. <br> \
  1667. </div> \
  1668. ';
  1669. if (!document.querySelector("a[name='tokendiscussion']"))
  1670. {
  1671. var eleBlock = document.querySelector(".stsh_block_scrollToDiscussion");
  1672. if (eleBlock)
  1673. {
  1674. eleBlock.classList.add("stsh_hidden");
  1675. }
  1676. }
  1677.  
  1678. var eleMove = eleMenu.querySelector(".stsh_btn_moveLang");
  1679. if (eleMove)
  1680. {
  1681. eleMove.addEventListener("click", function(ev)
  1682. {
  1683. var ele = ev.target;
  1684. ele.disabled = true;
  1685. var eleLangEng = document.querySelector(".stsh_usThem_langEng");
  1686. var eleLangCur = document.querySelector(".stsh_usThem_langCur");
  1687. if (eleLangEng && eleLangCur)
  1688. {
  1689. insertAfterElement(eleLangCur, eleLangEng);
  1690. }
  1691. });
  1692. }
  1693. // Sample: https://translation.steampowered.com/Us_And_Them.php?token_key_ID=21476726000412883
  1694. var eleHtml = eleMenu.querySelector(".stsh_btn_displayHtmlTags");
  1695. if (eleHtml)
  1696. {
  1697. var eleEng = document.querySelector(".stsh_usThem_langEng > .stsh_usThem_translation");
  1698. if (eleEng.firstElementChild)
  1699. {
  1700. eleHtml.addEventListener("click", function(ev)
  1701. {
  1702. var ele = ev.target;
  1703. ele.disabled = true;
  1704. var elesTranslation = document.querySelectorAll(".stsh_usThem_translation");
  1705. for (var i = 0; i < elesTranslation.length; i++)
  1706. {
  1707. displayHtmlTags(elesTranslation[i]);
  1708. }
  1709. });
  1710. }
  1711. else
  1712. {
  1713. var eleBlock = document.querySelector(".stsh_block_displayHtml");
  1714. if (eleBlock)
  1715. {
  1716. eleBlock.classList.add("stsh_hidden");
  1717. }
  1718. }
  1719. }
  1720. }
  1721. } // End Us_And_Them.php
  1722.  
  1723. if (url.indexOf("suggestions.php") > -1)
  1724. {
  1725. document.body && document.body.classList.add("stsh_page_suggestions");
  1726. var eleTextOrg = null;
  1727. var eleTextTrn = null;
  1728. var eleTextNew = null;
  1729. var elesTextSug = null;
  1730. var eleTextSubmit = null;
  1731. var eleTextSubmitNext = null;
  1732. var elesTextRemoveComment = null;
  1733. var eleHeaderOrg = null;
  1734. var eleHeaderTrn = null;
  1735. // Normalize
  1736. {
  1737. eleTextOrg = document.querySelector(".progress > tbody > tr:last-child > td:nth-child(1)");
  1738. if (eleTextOrg)
  1739. {
  1740. eleTextOrg.classList.add("stsh_text_org");
  1741. trimElement(eleTextOrg);
  1742. eleTextOrg.dataset.stshHtml = eleTextOrg.innerHTML;
  1743. }
  1744. eleTextTrn = document.querySelector(".progress > tbody > tr:last-child > td:nth-child(3)");
  1745. if (eleTextTrn)
  1746. {
  1747. eleTextTrn.classList.add("stsh_text_trn");
  1748. trimElement(eleTextTrn);
  1749. if (eleTextTrn.textContent === "")
  1750. {
  1751. eleTextTrn.classList.add("stsh_text_trn_empty");
  1752. }
  1753. eleTextTrn.dataset.stshHtml = eleTextTrn.innerHTML;
  1754. }
  1755. eleTextNew = document.querySelector("#suggestion_value_new");
  1756. elesTextSug = document.querySelectorAll(".suggestion_text");
  1757. for (var i = 0; i < elesTextSug.length; i++)
  1758. {
  1759. elesTextSug[i].classList.add("stsh_text_sug");
  1760. elesTextSug[i].dataset.stshHtml = elesTextSug[i].innerHTML;
  1761. }
  1762. eleTextSubmit = document.querySelector(".lbAction[name='suggestion_temp'] input[accesskey='s']");
  1763. if (eleTextSubmit)
  1764. {
  1765. eleTextSubmit.classList.add("stsh_text_submit");
  1766. if (eleTextSubmit.value.indexOf("RESUBMIT") > -1)
  1767. {
  1768. eleTextSubmit.classList.add("stsh_text_resubmit");
  1769. }
  1770. }
  1771. eleTextSubmitNext = document.querySelector(".lbAction input[type='submit'][accesskey='a']");
  1772. if (eleTextSubmitNext)
  1773. {
  1774. eleTextSubmitNext.value = "Next";
  1775. eleTextSubmitNext.classList.add("stsh_text_submit_right");
  1776. }
  1777. elesTextRemoveComment = document.querySelectorAll(".suggestion_signature .lbAction[name^='mymodcomment'] a");
  1778. for (var i = 0; i < elesTextRemoveComment.length; i++)
  1779. {
  1780. elesTextRemoveComment[i].removeAttribute("href");
  1781. elesTextRemoveComment[i].classList.add("stsh_text_removeComment");
  1782. }
  1783. var elesTextComment = document.querySelectorAll("textarea[name='suggestion_comment']");
  1784. for (var i = 0; i < elesTextComment.length; i++)
  1785. {
  1786. elesTextComment[i].nextElementSibling.classList.add("stsh_submit_comment");
  1787. elesTextComment[i].classList.add("stsh_text_addComment");
  1788. }
  1789. var eleInputPrev = document.querySelector("#suggestions_nav > input[value^='Prev']");
  1790. if (eleInputPrev)
  1791. {
  1792. eleInputPrev.classList.add("stsh_nav_prev");
  1793. }
  1794. var eleInputNext = document.querySelector("#suggestions_nav > input[value~='Next']");
  1795. if (eleInputNext)
  1796. {
  1797. eleInputNext.classList.add("stsh_nav_next");
  1798. }
  1799. var elesApprove = document.querySelectorAll(".suggestion_signature input[value~='APPROVE']");
  1800. for (var i = 0; i < elesApprove.length; i++)
  1801. {
  1802. elesApprove[i].classList.add("stsh_action_approve");
  1803. }
  1804. var elesDecline = document.querySelectorAll(".suggestion_signature input[value~='DECLINE']");
  1805. for (var i = 0; i < elesDecline.length; i++)
  1806. {
  1807. elesDecline[i].classList.add("stsh_action_decline");
  1808. }
  1809. var elesNext = document.querySelectorAll(".suggestion_signature input[value~='Next']");
  1810. for (var i = 0; i < elesNext.length; i++)
  1811. {
  1812. elesNext[i].value = "Next";
  1813. var elePrev = elesNext[i].previousElementSibling;
  1814. if (elePrev)
  1815. {
  1816. if (elePrev.classList.contains("stsh_action_approve"))
  1817. {
  1818. elesNext[i].classList.add("stsh_action_approve_next");
  1819. }
  1820. else if (elePrev.classList.contains("stsh_action_decline"))
  1821. {
  1822. elesNext[i].classList.add("stsh_action_decline_next");
  1823. }
  1824. }
  1825. }
  1826. var elesRemove = document.querySelectorAll(".suggestion_signature input[value='REMOVE']");
  1827. for (var i = 0; i < elesRemove.length; i++)
  1828. {
  1829. elesRemove[i].classList.add("stsh_action_remove");
  1830. elesRemove[i].classList.add("stsh_yellow_light");
  1831. }
  1832. var elesEdit = document.querySelectorAll("input[value='Edit']");
  1833. for (var i = 0; i < elesEdit.length; i++)
  1834. {
  1835. elesEdit[i].classList.add("stsh_action_edit");
  1836. elesEdit[i].classList.add("stsh_blue_light");
  1837. }
  1838. var elesRemoveMyComment = document.querySelectorAll(
  1839. ".suggestion_signature .lbAction[name^='myFrm'] a[onclick*='.submit()']");
  1840. for (var i = 0; i < elesRemoveMyComment.length; i++)
  1841. {
  1842. elesRemoveMyComment[i].removeAttribute("href");
  1843. elesRemoveMyComment[i].classList.add("stsh_text_removeMyComment");
  1844. }
  1845. var elesFriendDiscuss = document.querySelectorAll(".friend_block_discussions");
  1846. for (var i = 0; i < elesFriendDiscuss.length; i++)
  1847. {
  1848. var eleDiscuss = elesFriendDiscuss[i].parentElement.nextElementSibling;
  1849. if (eleDiscuss)
  1850. {
  1851. eleDiscuss.classList.add("stsh_discussion");
  1852. }
  1853. }
  1854. var eleSugList = document.querySelector(".suggestions_list:nth-child(2)");
  1855. if (eleSugList)
  1856. {
  1857. if (eleSugList.childElementCount === 0)
  1858. {
  1859. eleSugList.classList.add("stsh_suggestion_list_empty");
  1860. }
  1861. else
  1862. {
  1863. for (var i = 0; i < eleSugList.children.length; i++)
  1864. {
  1865. if (eleSugList.children[i].querySelector(".suggestion_status_approved"))
  1866. {
  1867. eleSugList.children[i].classList.add("stsh_suggestion_border_approved");
  1868. }
  1869. else if (eleSugList.children[i].querySelector(".suggestion_status_declined"))
  1870. {
  1871. eleSugList.children[i].classList.add("stsh_suggestion_border_declined");
  1872. }
  1873. else
  1874. {
  1875. eleSugList.children[i].classList.add("stsh_suggestion_border_pending");
  1876. }
  1877. }
  1878. }
  1879. }
  1880. var eleSugHistory = document.querySelector(".suggestions_list:nth-child(5)");
  1881. if (eleSugHistory)
  1882. {
  1883. eleSugHistory.classList.add("stsh_suggestion_list_history");
  1884. }
  1885. var elesH1 = document.querySelectorAll(".progress > tbody:nth-child(2) > tr:nth-child(1) > td > h1:nth-child(1)");
  1886. if (elesH1.length >= 2)
  1887. {
  1888. eleHeaderOrg = elesH1[0].parentElement;
  1889. eleHeaderOrg.classList.add("stsh_header_org");
  1890. eleHeaderTrn = elesH1[1].parentElement;
  1891. eleHeaderTrn.classList.add("stsh_header_trn");
  1892. }
  1893. var eleSugListHeader = document.querySelector("#suggestionmain > div > h2");
  1894. if (eleSugListHeader)
  1895. {
  1896. eleSugListHeader.classList.add("stsh_suggestion_list_header");
  1897. }
  1898. }
  1899. // Remove horizon scroll
  1900. {
  1901. setTimeoutCustom(function()
  1902. {
  1903. var eleMain = document.querySelector("#suggestionmain");
  1904. if (eleMain)
  1905. {
  1906. if (eleMain.scrollWidth < 1000)
  1907. {
  1908. eleMain.classList.add("stsh_body_crop");
  1909. }
  1910. }
  1911. }, timingInit.removeHorizonScroll);
  1912. }
  1913. // Move region
  1914. {
  1915. if (eleTextTrn && eleTextTrn.classList.contains("stsh_text_trn_empty"))
  1916. {
  1917. var moveSuggestionBox = function()
  1918. {
  1919. var eleTextTrn = document.querySelector(".stsh_text_trn.stsh_text_trn_empty");
  1920. if (eleTextTrn)
  1921. {
  1922. eleTextTrn.innerHTML = "";
  1923. var eleTarget = document.querySelector("#suggestionmain > div:nth-child(4) > .lbAction");
  1924. if (eleTarget)
  1925. {
  1926. eleTextTrn.appendChild(eleTarget);
  1927. eleTextTrn.style.padding = "0px";
  1928. var textarea = document.querySelector("#suggestion_value_new");
  1929. if (textarea)
  1930. {
  1931. textarea.style.width = "98%";
  1932. textarea.style.marginLeft = "0px";
  1933. if (textarea.scrollHeight < 500)
  1934. {
  1935. textarea.style.height = (textarea.scrollHeight + 20) + "px";
  1936. }
  1937. else
  1938. {
  1939. textarea.style.height = "500px";
  1940. }
  1941. textarea.focus();
  1942. }
  1943. var eleTextOrg = document.querySelector(".stsh_text_org");
  1944. if (eleTextOrg)
  1945. {
  1946. eleTextOrg.style.display = "table-cell";
  1947. eleTextOrg.style.paddingTop = "6px";
  1948. }
  1949. }
  1950. }
  1951. }
  1952. var moveSuggestionList = function()
  1953. {
  1954. var eleTextTrn = document.querySelector(".stsh_text_trn.stsh_text_trn_empty");
  1955. if (eleTextTrn && eleTextTrn.textContent.trim() === "")
  1956. {
  1957. eleTextTrn.innerHTML = "";
  1958. var eleTarget = document.querySelector(".suggestion");
  1959. if (eleTarget)
  1960. {
  1961. eleTextTrn.appendChild(eleTarget);
  1962. eleTextTrn.style.padding = "0px";
  1963. }
  1964. }
  1965. }
  1966. var eleDiv = document.createElement("div");
  1967. eleDiv.classList.add("stsh_moveSuggestionContainer");
  1968. eleTextTrn.appendChild(eleDiv);
  1969. var eleMoveBox = document.createElement("input");
  1970. eleMoveBox.id = "stsh_moveSuggestionBox";
  1971. eleMoveBox.setAttribute("value", "Move Box Here");
  1972. eleMoveBox.setAttribute("type", "button");
  1973. eleDiv.appendChild(eleMoveBox);
  1974. eleMoveBox.addEventListener("click", function(e)
  1975. {
  1976. moveSuggestionBox();
  1977. });
  1978. if (document.querySelector(".suggestion"))
  1979. {
  1980. var eleMoveList = document.createElement("input");
  1981. eleMoveList.id = "stsh_moveSuggestionList";
  1982. eleMoveList.setAttribute("value", "Move Suggestion Here");
  1983. eleMoveList.setAttribute("type", "button");
  1984. eleDiv.appendChild(eleMoveList);
  1985. eleMoveList.addEventListener("click", function(e)
  1986. {
  1987. moveSuggestionList();
  1988. });
  1989. }
  1990. }
  1991. }
  1992. // Resize suggestion textarea
  1993. if (eleTextNew)
  1994. {
  1995. eleTextNew.style.width = "960px";
  1996. eleTextNew.style.height = "64px";
  1997. eleTextNew.style.marginLeft = "3px";
  1998. var resizeTextNew = function(eleTextNew)
  1999. {
  2000. eleTextNew.focus();
  2001. if (eleTextNew.scrollHeight < 500)
  2002. {
  2003. eleTextNew.style.height = (eleTextNew.scrollHeight + 20) + "px";
  2004. }
  2005. else
  2006. {
  2007. eleTextNew.style.height = "500px";
  2008. }
  2009. if (eleTextNew.scrollHeight > 200 && document.querySelector(".suggestion"))
  2010. {
  2011. eleTextNew.scrollIntoView();
  2012. }
  2013. };
  2014. if (isVisible())
  2015. {
  2016. resizeTextNew(eleTextNew);
  2017. }
  2018. else
  2019. {
  2020. // Fix size error when inactive
  2021. setTimeoutCustom(resizeTextNew, timingInit.resizeTextNew, eleTextNew);
  2022. }
  2023. }
  2024. // Add nav menu
  2025. {
  2026. /* // Unknown reason
  2027. var br = document.querySelector("form.lbAction:nth-child(2) > div:nth-child(2) > br:nth-child(1)");
  2028. if (br)
  2029. {
  2030. removeElement(br);
  2031. }
  2032. */
  2033. var key = "";
  2034. var eleNav = document.querySelector("div#suggestions_nav");
  2035. if (!eleNav)
  2036. {
  2037. // Add when error occured
  2038. eleNav = document.createElement("div");
  2039. eleNav.id = "suggestions_nav";
  2040. document.body && document.body.appendChild(eleNav);
  2041. }
  2042. if (eleNav)
  2043. {
  2044. var insert = "";
  2045. var insertSearch = "";
  2046. var insertView = "";
  2047. var spliter = "_";
  2048. var regApp = /[0-9]{4,}/;
  2049. var aKey = document.querySelector(".smallcopy > font:nth-child(2) > a:nth-child(1)");
  2050. if (aKey)
  2051. {
  2052. key = encodeURIComponent(aKey.textContent.trim());
  2053. if (key === "token-key")
  2054. {
  2055. aKey = document.querySelector(".smallcopy > a:nth-child(3)");
  2056. if (aKey)
  2057. {
  2058. key = encodeURIComponent(aKey.textContent.trim());
  2059. }
  2060. }
  2061. if (key !== "")
  2062. {
  2063. document.title = key + " - " + document.title;
  2064. if (key.split(spliter).length > 1)
  2065. {
  2066. if (key.indexOf("%23") === 0)
  2067. {
  2068. var firstSpliter = key.indexOf(spliter);
  2069. var keySharp = key.substring(0, firstSpliter);
  2070. insertSearch += '<a class="stsh_a_button" target="_blank" '
  2071. + ' href="/translate.php?keyonly=1&paginationrows=1000&search_input='
  2072. + keySharp + '">Hashtag</a>';
  2073. }
  2074. var lastSpliter = key.lastIndexOf(spliter);
  2075. var keyGroup = key.substring(0, lastSpliter);
  2076. insertSearch += '<a class="stsh_a_button" target="_blank" '
  2077. + ' href="/translate.php?keyonly=1&paginationrows=1000&search_input='
  2078. + keyGroup + '">Group</a>';
  2079. }
  2080. insertSearch += '<a class="stsh_a_button" target="_blank" '
  2081. + ' href="/translate.php?keyonly=1&search_input='
  2082. + key + '">Key</a>';
  2083. }
  2084. }
  2085. if (eleTextOrg)
  2086. {
  2087. var text = encodeURIComponent(eleTextOrg.textContent.trim())
  2088. .replace(/(%20|%09)/g,"+")
  2089. .replace(/'/g,"\\'")
  2090. .replace("%0A", "+")
  2091. .replace(/\++/g, "+")
  2092. .substr(0, 80);
  2093. if (text.length >= 80)
  2094. {
  2095. // Find last space
  2096. var last = text.lastIndexOf("+");
  2097. last = last < 0 ? 80 : last;
  2098. text = text.substr(0, last);
  2099. }
  2100. if (text.indexOf(". ") > 20)
  2101. {
  2102. // Find first .
  2103. text = text.substr(0, text.indexOf(". ") + 1);
  2104. }
  2105. if (text.indexOf("%5C") > 10)
  2106. {
  2107. // Find first \
  2108. text = text.substr(0, text.indexOf("%5C"));
  2109. }
  2110. /* // Unknown reason
  2111. if (eleTextSubmit)
  2112. {
  2113. var elePrev = eleTextSubmit.previousElementSibling;
  2114. if (!elePrev || elePrev.tagName !== "BR")
  2115. {
  2116. var eleNew = document.createElement("br");
  2117. insertBeforeElement(eleNew, eleTextSubmit);
  2118. }
  2119. }
  2120. */
  2121. if (text !== "")
  2122. {
  2123. insertSearch += '<a class="stsh_a_button" target="_blank" '
  2124. + ' href="/translate.php?keyonly=2&paginationrows=1000&search_input='
  2125. + text + '">String</a>';
  2126. if (eleTextSubmitNext)
  2127. {
  2128. var eleForm = eleTextSubmitNext.parentElement.parentElement;
  2129. if (eleForm.tagName === "FORM")
  2130. {
  2131. addKeyCtrlShiftEnter(eleForm, eleTextSubmitNext);
  2132. }
  2133. }
  2134. else
  2135. {
  2136. if (eleTextSubmit)
  2137. {
  2138. eleTextSubmitNext = document.createElement("input");
  2139. eleTextSubmitNext.id = "stsh_text_submit_next";
  2140. eleTextSubmitNext.classList.add("stsh_text_submit_right");
  2141. eleTextSubmitNext.setAttribute("type", "submit");
  2142. eleTextSubmitNext.setAttribute("value", "Next");
  2143. eleTextSubmitNext.setAttribute("name", "submitandnext");
  2144. insertAfterElement(eleTextSubmitNext, eleTextSubmit);
  2145. eleTextSubmitNext.addEventListener("click", function(ev)
  2146. {
  2147. var textOrg = "";
  2148. var textTrn = "";
  2149. var textCur = "";
  2150. var eleTextOrg = document.querySelector(".stsh_text_org");
  2151. if (eleTextOrg)
  2152. {
  2153. textOrg = trimSpace(eleTextOrg.textContent);
  2154. }
  2155. var eleTextTrn = document.querySelector(".stsh_text_trn:not(.stsh_text_trn_empty)");
  2156. if (eleTextTrn)
  2157. {
  2158. textTrn = trimSpace(eleTextTrn.textContent);
  2159. }
  2160. var eleTextCur = document.querySelector("#suggestion_value_new");
  2161. if (eleTextCur)
  2162. {
  2163. textCur = trimSpace(eleTextCur.value);
  2164. }
  2165. if (textCur === "" || textOrg === textCur || textTrn === textCur)
  2166. {
  2167. ev.preventDefault();
  2168. var eleTextSubmit = document.querySelector(".stsh_text_submit");
  2169. if (eleTextSubmit)
  2170. {
  2171. eleTextSubmit.click();
  2172. }
  2173. }
  2174. });
  2175. var eleForm = eleTextSubmit.parentElement.parentElement;
  2176. if (eleForm.tagName === "FORM")
  2177. {
  2178. addKeyCtrlShiftEnter(eleForm, eleTextSubmitNext);
  2179. }
  2180. }
  2181. }
  2182. if (eleTextSubmitNext)
  2183. {
  2184. var canNext = !!(document.querySelector(".stsh_nav_next:not(:disabled)"));
  2185. if (!canNext)
  2186. {
  2187. // Display as disabled
  2188. eleTextSubmitNext.classList.add("stsh_grey");
  2189. eleTextSubmitNext.classList.add("stsh_cursor_default");
  2190. }
  2191. }
  2192. }
  2193. else
  2194. {
  2195. // (text === "")
  2196. if (eleTextNew && eleTextSubmit && !eleTextSubmit.classList.contains("stsh_text_resubmit"))
  2197. {
  2198. var eleNew = document.createElement("input");
  2199. eleNew.id = "stsh_text_submit_space";
  2200. eleNew.classList.add("stsh_text_submit_right");
  2201. eleNew.setAttribute("type", "button");
  2202. //eleNew.setAttribute("value", "Submit Space (Alt+0160)");
  2203. eleNew.setAttribute("value", "Submit Empty (2 Newlines)");
  2204. insertAfterElement(eleNew, eleTextSubmit);
  2205. eleNew.addEventListener("click", function(ev)
  2206. {
  2207. var eleTextNew = document.querySelector("#suggestion_value_new");
  2208. if (eleTextNew)
  2209. {
  2210. // Space char
  2211. //eleTextNew.value = String.fromCharCode(160);
  2212. // Two newlines result in one newline when export
  2213. eleTextNew.value = "\n\n";
  2214. eleTextNew.focus();
  2215. ev.preventDefault();
  2216. var eleTextSubmit = document.querySelector(".stsh_text_submit");
  2217. if (eleTextSubmit)
  2218. {
  2219. eleTextSubmit.click();
  2220. }
  2221. }
  2222. });
  2223. }
  2224. }
  2225. }
  2226. var qBranch = getQueryByName("branch");
  2227. if (qBranch.indexOf("games") !== 0)
  2228. {
  2229. var app = regApp.exec(key.replace("%23", ""));
  2230. if (app && key.indexOf("faq") < 0 && key.indexOf("glossary") < 0)
  2231. {
  2232. if (key.indexOf("SharedFiles_App_") === 0)
  2233. {
  2234. insertView += '<a class="stsh_a_button" target="_blank" '
  2235. + ' href="https://steamcommunity.com/workshop/browse?appid='
  2236. + app + '">Workshop</a>';
  2237. }
  2238. insertView += '<a class="stsh_a_button" target="_blank" '
  2239. + ' href="https://steamcommunity.com/app/'
  2240. + app + '">Community</a>'
  2241. insertView += '<a class="stsh_a_button" target="_blank" '
  2242. + ' href="https://store.steampowered.com/app/'
  2243. + app + '">App</a>';
  2244. }
  2245. }
  2246. if (insertSearch)
  2247. {
  2248. insert += ' <br> &nbsp; Search: <div class="stsh_nav_group"> ' + insertSearch + " </div>";
  2249. }
  2250. if (insertView)
  2251. {
  2252. insert += ' <br> &nbsp; View: <div class="stsh_nav_group"> ' + insertView + " </div>";
  2253. }
  2254. var insertBefore =
  2255. ' \
  2256. <input id="stsh_refresh" value="Refresh" onclick="return false;" type="button"> \
  2257. <a class="stsh_a_button" target="_blank" href="' + url + '">Frame</a> \
  2258. ';
  2259.  
  2260. var innerNew = eleNav.innerHTML
  2261. .replace('<input value="Previous', '&nbsp;&nbsp;<input value="Prev')
  2262. .replace('<input value="Close X', '&nbsp;&nbsp;<input value="Close (ESC)');
  2263. eleNav.innerHTML = insertBefore + innerNew + insert + " <br> ";
  2264. var eleRefresh = document.querySelector("#stsh_refresh");
  2265. if (eleRefresh)
  2266. {
  2267. eleRefresh.addEventListener("click", function()
  2268. {
  2269. reload();
  2270. });
  2271. }
  2272. }
  2273. }
  2274. // Regroup glossary
  2275. // Auto replace matched string
  2276. {
  2277. setTimeoutCustom(function()
  2278. {
  2279. var br = "<br>";
  2280. var brSpace = " <br> ";
  2281. var tag = "<a";
  2282. var colon = ">: ";
  2283. var comma = ",";
  2284. var bracket = " (";
  2285. var isEdit = false;
  2286. var p = null;
  2287. var aGls = document.querySelectorAll("a[href='glossary.php']");
  2288. for (var i = 0; i < aGls.length; i++)
  2289. {
  2290. if (aGls[i].textContent.trim() === "GLOSSARY FEATURE")
  2291. {
  2292. p = aGls[i].parentElement;
  2293. break;
  2294. }
  2295. }
  2296. if (p)
  2297. {
  2298. var glosOuters = [];
  2299. var glosInnerStart = 0;
  2300. var countGl = 0;
  2301. var glossaries = p.innerHTML.split(br);
  2302. if (glossaries.length > 2)
  2303. {
  2304. glosOuters = [p];
  2305. glosInnerStart = 2;
  2306. }
  2307. else
  2308. {
  2309. glosOuters = p.nextSibling.querySelectorAll("td");
  2310. glosInnerStart = 0;
  2311. }
  2312. var rgxKey = />[^><]+</;
  2313. var rgxKeyClean = /[><]+/g;
  2314. var rgxKeyPunct = /[\(\)\[\]\:\!]/g;
  2315. var rgxContentClean = /<[^<]*>/g;
  2316. var textNew = "";
  2317. var textEng = "";
  2318. var textNewFull = "";
  2319. var textEngFull = "";
  2320. var isTextReplaced = false;
  2321. var isOutdated = false;
  2322.  
  2323. var eleBtnResummit = document.querySelector(".stsh_text_submit[value^='RESUBMIT']");
  2324. if (eleBtnResummit)
  2325. {
  2326. isTextReplaced = true;
  2327. }
  2328. else
  2329. {
  2330. if (eleTextNew)
  2331. {
  2332. textNewFull = trimTab(eleTextNew.value.toLowerCase());
  2333. textNew = textNewFull.trim();
  2334. }
  2335. if (textNew === "" || textNew.length > 300)
  2336. {
  2337. // Not replace on empty and long strings
  2338. isTextReplaced = true;
  2339. }
  2340. }
  2341. if (!isTextReplaced)
  2342. {
  2343. var eleTrs = document.querySelectorAll(".progress tr");
  2344. isOutdated = (eleTrs.length >= 3);
  2345. if (isOutdated)
  2346. {
  2347. textEngFull = trimTab(eleTrs[eleTrs.length - 1].firstElementChild.textContent.toLowerCase());
  2348. textEng = textEngFull.trim();
  2349. }
  2350. }
  2351. for (var i = 0; i < glosOuters.length; i++)
  2352. {
  2353. var glosOuter = glosOuters[i];
  2354. var glosInners = glosOuter.innerHTML.split(br);
  2355. isEdit = false;
  2356. for (var j = glosInnerStart; j < glosInners.length; j++)
  2357. {
  2358. var glossary = glosInners[j].trim();
  2359. if (glossary.length > 0 && glossary.indexOf(tag) === 0)
  2360. {
  2361. var colonIndex = glossary.indexOf(colon);
  2362. var contentHead = glossary.substr(0, colonIndex + 3);
  2363. var contentAll = glossary.substr(colonIndex + 3);
  2364. var contentWords = contentAll.split(comma);
  2365. var contentFirst = contentWords[0].trim();
  2366. for (var k = 0; k < contentWords.length; k++)
  2367. {
  2368. var contentNew = contentWords[k].trim();
  2369. var contentSub = null;
  2370. var bracketPos = contentNew.indexOf(" (");
  2371. if (bracketPos > -1)
  2372. {
  2373. contentSub = contentNew.substr(bracketPos);
  2374. contentNew = contentNew.substr(0, bracketPos);
  2375. }
  2376. contentNew = " <span id='stsh_gls_" + countGl
  2377. + "' onclick='clickToSelect(this)'>"
  2378. + contentNew + "</span>";
  2379. //+ "<span style='color: white; cursor: pointer;'>^</span>";
  2380. if (contentSub)
  2381. {
  2382. contentNew += "<span "
  2383. + "onclick='clickToSelect(this.previousElementSibling)'>"
  2384. + contentSub + "</span>";
  2385. }
  2386. contentWords[k] = contentNew;
  2387. countGl++;
  2388. }
  2389. if (!isTextReplaced)
  2390. {
  2391. var keys = contentHead.match(rgxKey);
  2392. if (keys && keys.length > 0)
  2393. {
  2394. var key = keys[0].replace(rgxKeyClean, "").trim().toLowerCase();
  2395. var contentClean = contentFirst.replace(rgxContentClean, "");
  2396. var contentLower = contentClean.toLowerCase();
  2397. var textCur = "";
  2398. if (key === textNew.replace(rgxKeyPunct, ""))
  2399. {
  2400. textCur = textNewFull;
  2401. }
  2402. else if (key === textEng.replace(rgxKeyPunct, ""))
  2403. {
  2404. textCur = textEngFull;
  2405. }
  2406. if (textCur !== "" && key !== contentLower)
  2407. {
  2408. if (eleTextNew)
  2409. {
  2410. var rgxReplace = new RegExp(key, "i");
  2411. eleTextNew.value = textCur.replace(rgxReplace, contentClean);
  2412. isTextReplaced = true;
  2413. }
  2414. }
  2415. }
  2416. }
  2417. glosInners[j] = contentHead + contentWords.join(comma);
  2418. isEdit = true;
  2419. }
  2420. }
  2421. if (isEdit && false)
  2422. {
  2423. // old feature
  2424. glosOuter.innerHTML = glosInners.join(brSpace);
  2425. }
  2426. }
  2427. }
  2428. }, timingInit.improveGlossary);
  2429. }
  2430. // Insert clicked word in last textarea
  2431. {
  2432. var eleTextLast = null;
  2433. setTimeoutCustom(function()
  2434. {
  2435. if (document.activeElement && document.activeElement.tagName === "TEXTAREA")
  2436. {
  2437. eleTextLast = document.activeElement;
  2438. }
  2439. var elesText = document.querySelectorAll
  2440. (" \
  2441. #suggestion_value_new \
  2442. , .stsh_text_addComment \
  2443. , #add_to_discussion \
  2444. , textarea[name^='autoreplace'] \
  2445. , .stsh_autoReplace_text \
  2446. ");
  2447. for (var i = 0; i < elesText.length; i++)
  2448. {
  2449. elesText[i].addEventListener('focus', function(ev)
  2450. {
  2451. eleTextLast = ev.target;
  2452. });
  2453. }
  2454. }, timingInit.bindLastText);
  2455. setTimeoutCustom(function()
  2456. {
  2457. var elesInsert = document.querySelectorAll(".insertword");
  2458. for (var i = 0; i < elesInsert.length; i++)
  2459. {
  2460. removeAllEventListeners(elesInsert[i]);
  2461. }
  2462. var insertAtCaret = function(txtarea, text)
  2463. {
  2464. // Edit from STS
  2465. var scrollPos = txtarea.scrollTop;
  2466. var strPos = 0;
  2467. var strLength = 0;
  2468. var br = ((txtarea.selectionStart || txtarea.selectionStart === 0) ? "ff" : (document.selection ? "ie" : false));
  2469. if (br === "ie")
  2470. {
  2471. txtarea.focus();
  2472. var range = document.selection.createRange();
  2473. range.moveStart('character', -txtarea.value.length);
  2474. strPos = range.text.length;
  2475. }
  2476. else if (br === "ff")
  2477. {
  2478. strPos = txtarea.selectionStart;
  2479. strLength = txtarea.selectionEnd - txtarea.selectionStart;
  2480. }
  2481. var front = (txtarea.value).substring(0, strPos);
  2482. var back = (txtarea.value).substring(strPos + strLength, txtarea.value.length);
  2483. txtarea.value = front + text + back;
  2484. strPos = strPos + text.length;
  2485. if (br === "ie")
  2486. {
  2487. txtarea.focus();
  2488. var range = document.selection.createRange();
  2489. range.moveStart('character', -txtarea.value.length);
  2490. range.moveStart('character', strPos);
  2491. range.moveEnd('character', 0);
  2492. range.select();
  2493. }
  2494. else if (br === "ff")
  2495. {
  2496. txtarea.selectionStart = strPos;
  2497. txtarea.selectionEnd = strPos;
  2498. txtarea.focus();
  2499. }
  2500. txtarea.scrollTop = scrollPos;
  2501. }
  2502. elesInsert = document.querySelectorAll(".insertword");
  2503. for (var i = 0; i < elesInsert.length; i++)
  2504. {
  2505. //elesInsert[i].classList.add("stsh_unselectable");
  2506. elesInsert[i].addEventListener("click", function(ev)
  2507. {
  2508. if (eleTextLast)
  2509. {
  2510. insertAtCaret(eleTextLast , ev.target.textContent.trim());
  2511. }
  2512. });
  2513. }
  2514. }, timingInit.insertAtCaret);
  2515. }
  2516. // Restyle glossary
  2517. {
  2518. var eleP = null;
  2519. var elesA = document.querySelectorAll("a[href='glossary.php']");
  2520. for (var i = 0; i < elesA.length; i++)
  2521. {
  2522. if (elesA[i].textContent.trim() === "GLOSSARY FEATURE")
  2523. {
  2524. eleP = elesA[i].parentElement;
  2525. break;
  2526. }
  2527. }
  2528. if (eleP)
  2529. {
  2530. var nodeText = eleP.firstElementChild.nextSibling;
  2531. if (nodeText.nodeType === document.TEXT_NODE)
  2532. {
  2533. var ele = document.createElement("span");
  2534. ele.textContent = nodeText.textContent;
  2535. removeElement(nodeText);
  2536. insertAfterElement(ele, eleP.firstElementChild);
  2537. }
  2538. var eleHead;
  2539. if (eleP.nextElementSibling.tagName === "TABLE")
  2540. {
  2541. eleHead = eleP.nextElementSibling;
  2542. }
  2543. else
  2544. {
  2545. eleHead = eleP;
  2546. }
  2547. eleHead.classList.add("stsh_glossary_header");
  2548. var elesTerm = eleHead.querySelectorAll(
  2549. "a[href*='//translation.steampowered.com/translate.php?search_input=']");
  2550. for (var i = 0; i < elesTerm.length; i++)
  2551. {
  2552. elesTerm[i].classList.add("stsh_glossary_term");
  2553. // Clean glossary links
  2554. {
  2555. var href = elesTerm[i].href;
  2556. var hrefNew = href.replace("http://", "//")
  2557. .replace(/\?search_input=([^"])([^&]+)&keyonly=0&listfilter=0&listsort=0&liststatus=0&paginationrows=50/i
  2558. , '\?keyonly=2&paginationrows=1000&search_input="$1$2"');
  2559. elesTerm[i].href = hrefNew;
  2560. }
  2561. }
  2562. {
  2563. var eleSpan = null;
  2564. if (eleHead.tagName === "TABLE")
  2565. {
  2566. eleSpan = eleHead.previousElementSibling.querySelector("span");
  2567. }
  2568. else
  2569. {
  2570. eleSpan = eleHead.querySelector("span");
  2571. }
  2572. eleSpan.textContent = eleSpan.textContent
  2573. .replace(" (click to copy to top)", "");
  2574. eleSpan.title = "Click to copy to suggestion or comment";
  2575. eleSpan.classList.add("stsh_cursor_help");
  2576. eleSpan.classList.add("stsh_glossary_help");
  2577. }
  2578. }
  2579. var eleTd = document.querySelector(".stsh_glossary_header \
  2580. > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(4)");
  2581. if (eleTd)
  2582. {
  2583. if (eleTd.childElementCount === 0)
  2584. {
  2585. removeElement(eleTd);
  2586. }
  2587. }
  2588. }
  2589. // Restyle same token
  2590. {
  2591. /* // Unknown reason
  2592. var p = document.querySelector("#suggestionmain > div:nth-child(5) > p:nth-child(4)");
  2593. if (p)
  2594. {
  2595. for (var i = 0; i < p.childNodes.length; i++)
  2596. {
  2597. var child = p.childNodes[i];
  2598. if (child.nodeName === "#text")
  2599. {
  2600. child.nodeValue = child.nodeValue.trim();
  2601. }
  2602. }
  2603. }
  2604. */
  2605. var widthMax = 0;
  2606. var elesFile = document.querySelectorAll(
  2607. "#suggestionmain > div > p > a[href*='/translate.php?keyonly=1&search_input=']");
  2608. for (var i = 0; i < elesFile.length; i++)
  2609. {
  2610. elesFile[i].classList.add("stsh_sametoken_file");
  2611. var width = elesFile[i].offsetWidth;
  2612. if (width > widthMax)
  2613. {
  2614. widthMax = width;
  2615. }
  2616. }
  2617. for (var i = 0; i < elesFile.length; i++)
  2618. {
  2619. elesFile[i].style.minWidth = (widthMax + 4) + "px";
  2620. }
  2621. var eleHeader = null;
  2622. if (elesFile.length > 0)
  2623. {
  2624. eleHeader = elesFile[0].parentElement;
  2625. }
  2626. if (eleHeader)
  2627. {
  2628. eleHeader.classList.add("stsh_sametoken_header");
  2629. eleHeader.innerHTML = eleHeader.innerHTML.replace(
  2630. "&lt;--- currently in view above",
  2631. '<span class="stsh_blue_light stsh_sametoken_current">&lt;--- currently in view above</span>');
  2632. }
  2633. }
  2634. // Auto link http
  2635. // Format comment
  2636. // Show images
  2637. {
  2638. var countSugStatus = document.querySelectorAll(
  2639. ".suggestions_list span[class^='suggestion_status_']").length;
  2640. var rgxUrl = /https?:[^ "]+/ig;
  2641. var rgxHostUrl = /^https?:\/\/translation\.steampowered\.com\//i;
  2642. var hostReplace = "/";
  2643. var eleComments = document.querySelectorAll
  2644. (" \
  2645. .suggestion_signature > i:nth-child(3) \
  2646. , .suggestion_signature div:nth-child(1) > i:nth-child(4) \
  2647. , .suggestion_signature div:nth-child(1) > i:nth-child(6) \
  2648. , *[class^='row'] > td:nth-child(2) \
  2649. ");
  2650. for (var i = 0; i < eleComments.length; i++)
  2651. {
  2652. var comment = eleComments[i].innerHTML + " ";
  2653. if (comment.indexOf("<a") === -1)
  2654. {
  2655. var commentUrls = comment.match(rgxUrl) || [];
  2656. for (var j = 0; j < commentUrls.length; j++)
  2657. {
  2658. var urlDecode = commentUrls[j];
  2659. try
  2660. {
  2661. urlDecode = decodeURIComponent(commentUrls[j])
  2662. .replace(/#/g, "%23").replace(/&amp;/g, "&");
  2663. //console.log(urlDecode);
  2664. if (countSugStatus === 0 && rgxHostUrl.test(urlDecode))
  2665. {
  2666. var query = getQueryByName("search_input", urlDecode);
  2667. if (query !== "")
  2668. {
  2669. urlDecode = query;
  2670. }
  2671. else
  2672. {
  2673. urlDecode = urlDecode.replace(rgxHostUrl, hostReplace);
  2674. }
  2675. }
  2676. }
  2677. catch (ex)
  2678. {
  2679. console.error("FormatComment", ex.message);
  2680. }
  2681. var commentUrl = commentUrls[j] + " ";
  2682. comment = comment.replace(commentUrl, "<a target='_blank' href='"
  2683. + commentUrls[j] + "' >" + urlDecode + "</a> ");
  2684. }
  2685. }
  2686. comment = comment.trim();
  2687. var commentHead = "";
  2688. var commentFoot = "";
  2689. if (comment.indexOf("Comment:") === 0)
  2690. {
  2691. eleComments[i].classList.add("stsh_text_comment_header");
  2692. comment = comment.substr(9);
  2693. commentHead = "Comment: <span class='stsh_text_comment'>";
  2694. commentFoot = "</span>";
  2695. }
  2696. else
  2697. {
  2698. var indexHead = comment.indexOf(":</font>");
  2699. if (indexHead > -1)
  2700. {
  2701. commentHead = comment.substr(0, indexHead + 8);
  2702. comment = comment.substr(indexHead + 8);
  2703. }
  2704. }
  2705. comment = comment
  2706. .replace(/([ \n])([\/~]{1,})([ \n])/g, "$1<span class='stsh_white stsh_pad'>$2</span>$3")
  2707. //.replace(/\/ /g, "<span class='stsh_white stsh_pad'>/</span> ")
  2708. //.replace(/ \//g, " <span class='stsh_white stsh_pad'>/</span>")
  2709. .replace(/(\-+)\&gt\;/g, "<span class='stsh_white stsh_pad'>$1&gt;</span>")
  2710. .replace(/ &gt; /g, " <span class='stsh_white stsh_pad'>&gt;</span> ")
  2711. .replace(/(\-{2,})([^\&])/g, "<span class='stsh_white stsh_pad'>$1</span>$2")
  2712. //.replace(/([^<>,]+)(\, +)([^<>,]+)/g, "$1<span class='stsh_white stsh_pad'>$2</span>$3")
  2713. //.replace(/([^<>,]+)(\, +)([^<>,]+)/g, "$1<span class='stsh_white stsh_pad'>$2</span>$3")
  2714. .replace(/\| /g, "<span class='stsh_white stsh_pad'>| </span>")
  2715. .replace(/ \* /g, " <span class='stsh_white stsh_pad'>*</span> ")
  2716. .replace(/ \.\.\.([ \n])/g, " <span class='stsh_white stsh_pad'>...</span>$1")
  2717. .replace(/\n/g, "<br>")
  2718. .replace(/Past application on (.{20})/g,
  2719. "<span class='stsh_white stsh_pad'><br>Past application on $1</span>");
  2720. eleComments[i].innerHTML = commentHead + comment + commentFoot;
  2721. var eleAs = eleComments[i].querySelectorAll("a");
  2722. for (var j = 0; j < eleAs.length; j++)
  2723. {
  2724. var href = eleAs[j].getAttribute("href");
  2725. if (href.indexOf("#") > -1)
  2726. {
  2727. eleAs[j].setAttribute("href", href.replace(/\#/g,"%23"));
  2728. }
  2729. }
  2730. //if (comment.indexOf("Comment:") !== 0)
  2731. {
  2732. // Discussion comment
  2733. var rgxImg = /(\.(jpg|png|gif)|\/ugc\/)/i;
  2734. var rgxImgur = /^https?:\/\/imgur\.com\/([a-z0-9]+)\/?$/i;
  2735. var rgxLongUrl = /^https?\:\/\/translation\.steampowered\.com\/translate\.php\?search_input\=/i;
  2736. var elesA = eleComments[i].querySelectorAll("a");
  2737. for (var j = 0; j < elesA.length; j++)
  2738. {
  2739. var href = elesA[j].getAttribute("href");
  2740. if (rgxImgur.test(href))
  2741. {
  2742. href = href.replace(rgxImgur, "https://i.imgur.com/$1.png");
  2743. }
  2744. if (rgxImg.test(href))
  2745. {
  2746. if (elesA[j].querySelectorAll("img").length === 0)
  2747. {
  2748. var ele = document.createElement("img");
  2749. ele.classList.add("stsh_comment_img");
  2750. ele.setAttribute("src", href);
  2751. ele.setAttribute("title", href);
  2752. ele.dataset.modeNext = "unmin";
  2753. insertAfterElement(ele, elesA[j]);
  2754. if (ele.naturalWidth === 0 || ele.naturalWidth > 400 || ele.naturalHeight > 225)
  2755. {
  2756. ele.classList.add("stsh_comment_img_zoom");
  2757. ele.addEventListener("click", function(ev)
  2758. {
  2759. var eleTarget = ev.target;
  2760. var mode = "min";
  2761. if (eleTarget.dataset.modeNext === "min")
  2762. {
  2763. mode = "min";
  2764. eleTarget.dataset.modeNext = "unmin";
  2765. }
  2766. else
  2767. {
  2768. mode = "unmin";
  2769. eleTarget.dataset.modeNext = "min";
  2770. }
  2771. if (eleTarget.naturalWidth < 400 && eleTarget.naturalHeight < 225)
  2772. {
  2773. eleTarget.classList.remove("stsh_comment_img_zoom");
  2774. }
  2775. var isHorizontal = eleTarget.naturalWidth > eleTarget.naturalHeight;
  2776. if (isHorizontal)
  2777. {
  2778. eleTarget.style.maxHeight = "none";
  2779. if (mode === "unmin")
  2780. {
  2781. eleTarget.style.minWidth = eleTarget.naturalWidth < 850
  2782. ? eleTarget.naturalWidth + "px" : "850px";
  2783. }
  2784. else
  2785. {
  2786. eleTarget.style.minWidth = eleTarget.naturalWidth < 400
  2787. ? eleTarget.naturalWidth + "px" : "400px";
  2788. }
  2789. }
  2790. else
  2791. {
  2792. eleTarget.style.maxWidth = "none";
  2793. if (mode === "unmin")
  2794. {
  2795. eleTarget.style.minHeight = eleTarget.naturalHeight < 850
  2796. ? eleTarget.naturalHeight + "px" : "850px";
  2797. }
  2798. else
  2799. {
  2800. eleTarget.style.minHeight = eleTarget.naturalHeight < 225
  2801. ? eleTarget.naturalHeight + "px" : "225px";
  2802. }
  2803. }
  2804. });
  2805. }
  2806. }
  2807. }
  2808. else
  2809. {
  2810. var content = elesA[j].textContent;
  2811. if (rgxLongUrl.test(content))
  2812. {
  2813. //console.log(elesA[j]);
  2814. if (!elesA[j].parentElement.parentElement.parentElement
  2815. .querySelector(".suggestion_signature .lbAction[name^='mymodcomment']"))
  2816. {
  2817. elesA[j].textContent = content.replace(rgxLongUrl, "").replace(/\+/g, " ");
  2818. }
  2819. }
  2820. }
  2821. }
  2822. }
  2823. }
  2824. }
  2825. // Add space between comment and button
  2826. {
  2827. var elesAction = document.querySelectorAll(".stsh_action_remove, .stsh_action_edit");
  2828. for (var i = 0; i < elesAction.length; i++)
  2829. {
  2830. if (elesAction[i].previousElementSibling
  2831. && elesAction[i].previousElementSibling.previousElementSibling
  2832. && elesAction[i].previousElementSibling.previousElementSibling
  2833. .classList.contains("stsh_text_comment_header"))
  2834. {
  2835. insertBeforeElement(document.createElement("br"), elesAction[i]);
  2836. }
  2837. }
  2838. }
  2839. // Restyle token info
  2840. {
  2841. var divIntro = document.querySelector("#suggestionmain > div.smallcopy");
  2842. if (divIntro)
  2843. {
  2844. var qBranch = getQueryByName("branch");
  2845. var htmlEdit = "You are editing";
  2846. var htmlEditReplace = "";
  2847. var htmlToken = "Token <";
  2848. var htmlTokenReplace = "Token: <";
  2849. var htmlToken2 = "token-key";
  2850. var htmlToken2Replace = "Token";
  2851. var htmlLiveLinkMoved =
  2852. '\
  2853. <font style="color:red;">This FAQ likely does not exist anymore!</font>\
  2854. The generated <a href="https://support.steampowered.com/kb_article.php?ref="\
  2855. target="_blank">live link</a> seems dead or is redirecting.\
  2856. ';
  2857. var htmlLiveLinkMovedReplace =
  2858. '\
  2859. <font class="stsh_red stsh_cursor_help"\
  2860. title="The generated live link seems dead or is redirecting.">\
  2861. This FAQ likely does not exist anymore!</font>\
  2862. ';
  2863. var htmlLiveLinkMovedWithLiveLink =
  2864. '\
  2865. <font style="color:red;">This FAQ likely does not exist anymore!</font> The generated \
  2866. <a href="https://support.steampowered.com/kb_article.php?ref=\
  2867. ';
  2868. var htmlLiveLinkMovedWithLiveLinkReplace =
  2869. '<a href="https://support.steampowered.com/kb_article.php?ref=';
  2870. var htmlLiveLinkMovedWithLiveLink2 =
  2871. '" target="_blank">live link</a> seems dead or is redirecting.';
  2872. var htmlLiveLinkMovedWithLiveLink2Replace =
  2873. '\
  2874. " target="_blank">Live link</a> - \
  2875. <font class="stsh_red stsh_cursor_help"\
  2876. title="The generated live link seems dead or is redirecting.">\
  2877. This FAQ likely does not exist anymore!</font>';
  2878. var htmlLiveLink = 'target="_blank">Live link';
  2879. var htmlLiveLinkReplace = 'target="_blank">Live link'; // Change in condition
  2880. var htmlFile = " of <";
  2881. var htmlFileReplace =
  2882. ' <br>File: <font class="stsh_info_file stsh_blue" onclick="clickToSelect(this)">' + qBranch + '</font> >> <';
  2883. var htmlFrom = "<br>Added on <";
  2884. var htmlFromReplace = " &nbsp;&nbsp;Added: <";
  2885. var htmlUpdated = ">. Updated on <";
  2886. var htmlUpdatedReplace = "> &nbsp;&nbsp;Updated: <";
  2887. var htmlUpdated2 = "<br> Updated on <";
  2888. var htmlUpdated2Replace = " &nbsp;&nbsp;Updated: <";
  2889. var htmlSugg = 'You have <font style="';
  2890. var htmlSuggReplace =
  2891. 'You have <font title="Enter and submit new suggestions below. Do not alter HTML tags or variables." class="stsh_cursor_help" style="';
  2892. var htmlIntro =
  2893. "Enter and submit new suggestions below. Do not alter HTML tags or variables.";
  2894. var htmlIntroReplace =
  2895. ' \
  2896. &nbsp;&nbsp;\
  2897. <a href="mailto:translationserver@valvesoftware.com" \
  2898. title="Please report token issues by posting a TOKEN DISCUSSION \r\nor email to translationserver@valvesoftware.com" \
  2899. class="stsh_cursor_help">\
  2900. <font class="stsh_white">Report Tokens</font></a>\
  2901. ';
  2902. var htmlContact =
  2903. '\
  2904. <br>Please report token issues by posting a <font style="color:#a4b23c;">TOKEN DISCUSSION</font> tagged\
  2905. <input style="border:none; color:#FFFFFF; background-color:#111111; cursor:pointer;"\
  2906. onclick="tosts(\'truncated\')" value="[sts_admin][truncated]" type="button">or\
  2907. <input style="border:none; color:#FFFFFF; background-color:#111111; cursor:pointer;"\
  2908. onclick="tosts(\'typo\');" value="[sts_admin][typo]" type="button">or\
  2909. <input style="border:none; color:#FFFFFF; background-color:#111111; cursor:pointer;"\
  2910. onclick="tosts(\'unlockpls\')" value="[sts_admin][unlockpls]" type="button">or by \
  2911. <a href="mailto:translationserver@valvesoftware.com">email</a>.\
  2912. ';
  2913. var htmlContactReplace = '';
  2914. var htmlContact2 =
  2915. '\
  2916. <br>Please report token issues by posting a <font style="color:#a4b23c;">TOKEN DISCUSSION</font> tagged\
  2917. <input style="border:none; color:#FFFFFF; background-color:#111111; cursor:pointer;" type="button"\
  2918. onclick="tosts(\'truncated\')" value="[sts_admin][truncated]">or\
  2919. <input style="border:none; color:#FFFFFF; background-color:#111111; cursor:pointer;" type="button"\
  2920. onclick="tosts(\'typo\');" value="[sts_admin][typo]">or\
  2921. <input style="border:none; color:#FFFFFF; background-color:#111111; cursor:pointer;" type="button"\
  2922. onclick="tosts(\'unlockpls\')" value="[sts_admin][unlockpls]">or by \
  2923. <a href="mailto:translationserver@valvesoftware.com">email</a>.\
  2924. ';
  2925. var htmlContact2Replace = '';
  2926. var rgxTestEmail =
  2927. /<br><font style="color:#a4b23c;">This is part of email message .+ - you can test it by following this link:<\/font> /i;
  2928. var htmlTestEmailReplace = '';
  2929. var rgxTestEmail2 =
  2930. /<a href="test_email\.php\?filename=.+\&amp;lang=[a-z]+" target="_blank">Test<\/a>/i;
  2931. var htmlTestEmail2Replace = '';
  2932. var htmlsTestEmail = rgxTestEmail.exec(divIntro.innerHTML);
  2933. if (htmlsTestEmail)
  2934. {
  2935. var htmlTestEmail = htmlsTestEmail[0]
  2936. .replace('<br><font style="color:#a4b23c;">This is part of email message ', "")
  2937. .replace(' - you can test it by following this link:</font> ', "");
  2938. var htmlTestEmail2 = "";
  2939. var htmlsTestEmail2 = rgxTestEmail2.exec(divIntro.innerHTML);
  2940. if (htmlsTestEmail2)
  2941. {
  2942. htmlTestEmail2 = htmlsTestEmail2[0].replace('<a href="', "")
  2943. .replace('" target="_blank">Test</a>', "");
  2944. }
  2945. htmlIntroReplace += ' &nbsp;&nbsp;Test: <a href="' + htmlTestEmail2
  2946. + '" title="You can test email by following this link." target="_blank">'
  2947. + htmlTestEmail + '</a>';
  2948. }
  2949. if (key !== "")
  2950. {
  2951. htmlIntroReplace +=
  2952. ' \
  2953. <br>Share: \
  2954. <font class="stsh_token_share stsh_green stsh_truncate" onclick="clickToSelect(this)">\
  2955. https://translation.steampowered.com/translate.php?search_input=' + key + '\
  2956. </font> <br>\
  2957. ';
  2958. }
  2959. var urlLiveLink = "https://support.steampowered.com/kb_article.php?ref=";
  2960. var eleLiveLink = divIntro.querySelector("a[href^='" + urlLiveLink + "']");
  2961. if (eleLiveLink)
  2962. {
  2963. htmlLiveLinkReplace = 'target="_blank" title="Live link">'
  2964. + eleLiveLink.getAttribute("href").replace(urlLiveLink, "");
  2965. }
  2966. var isComplete = (divIntro.innerHTML.indexOf(htmlContact) > -1);
  2967. divIntro.innerHTML = divIntro.innerHTML
  2968. .replace(htmlEdit, htmlEditReplace)
  2969. .replace(htmlToken, htmlTokenReplace)
  2970. .replace(htmlToken2, htmlToken2Replace)
  2971. .replace(htmlLiveLinkMoved, htmlLiveLinkMovedReplace)
  2972. .replace(htmlLiveLinkMovedWithLiveLink, htmlLiveLinkMovedWithLiveLinkReplace)
  2973. .replace(htmlLiveLinkMovedWithLiveLink2, htmlLiveLinkMovedWithLiveLink2Replace)
  2974. .replace(htmlLiveLink, htmlLiveLinkReplace)
  2975. .replace(htmlFile, htmlFileReplace)
  2976. .replace(htmlFrom, htmlFromReplace)
  2977. .replace(htmlUpdated, htmlUpdatedReplace)
  2978. .replace(htmlUpdated2, htmlUpdated2Replace)
  2979. .replace(htmlSugg, htmlSuggReplace)
  2980. .replace(htmlIntro, htmlIntroReplace)
  2981. .replace(htmlContact, htmlContactReplace)
  2982. .replace(htmlContact2, htmlContact2Replace)
  2983. .replace(rgxTestEmail, htmlTestEmailReplace)
  2984. .replace(rgxTestEmail2, htmlTestEmail2Replace)
  2985. .trim();
  2986. var eleToken = document.querySelector("a[href^='Us_And_Them.php?']");
  2987. if (eleToken)
  2988. {
  2989. if (eleToken.textContent !== "Token")
  2990. {
  2991. eleToken.classList.add("stsh_token_name");
  2992. eleToken.classList.add("stsh_truncate");
  2993. }
  2994. }
  2995. if (!isComplete)
  2996. {
  2997. var stsh_introReplace_start = getTimeMs();
  2998. var stsh_introReplace_itv = setIntervalCustom(function(params)
  2999. {
  3000. var divIntro = params[0];
  3001. var htmlContact = params[1];
  3002. var htmlContactReplace = params[2];
  3003. var stsh_introReplace_isEnd = false;
  3004. var stsh_introReplace_cur = getTimeMs();
  3005. if (divIntro.innerHTML.indexOf(htmlContact) > -1)
  3006. {
  3007. divIntro.innerHTML = divIntro.innerHTML
  3008. .replace(htmlContact, htmlContactReplace);
  3009. stsh_introReplace_isEnd = true;
  3010. }
  3011. if (stsh_introReplace_isEnd || stsh_introReplace_cur - stsh_introReplace_start > 10000)
  3012. {
  3013. clearInterval(stsh_introReplace_itv);
  3014. }
  3015. }, 100, [divIntro, htmlContact, htmlContactReplace]);
  3016. }
  3017. }
  3018. }
  3019. // Restyle token discussion
  3020. {
  3021. var eleDiscuss = document.querySelector("a[name='tokendiscussion']");
  3022. if (eleDiscuss)
  3023. {
  3024. var htmlHeader = "TOKEN DISCUSSION (keep global comments English please!):";
  3025. var htmlHeaderReplace = "TOKEN DISCUSSION:";
  3026. var eleHeader = eleDiscuss.nextElementSibling;
  3027. if (eleHeader)
  3028. {
  3029. eleHeader.setAttribute("title", "Keep global comments English please!");
  3030. eleHeader.classList.add("stsh_cursor_help");
  3031. eleHeader.textContent = eleHeader.textContent.replace(htmlHeader, htmlHeaderReplace);
  3032. }
  3033. var eleParent = eleDiscuss.parentElement;
  3034. eleParent.classList.add("stsh_discussion_header");
  3035. if (eleParent.nextElementSibling)
  3036. {
  3037. eleParent.nextElementSibling.classList.add("stsh_discussion_section");
  3038. }
  3039. var elesInput = document.querySelectorAll("input[value='[stsadmin]']");
  3040. if (elesInput.length === 2)
  3041. {
  3042. removeElement(elesInput[1]);
  3043. }
  3044. var eleSpan = document.createElement("span");
  3045. eleSpan.innerHTML =
  3046. '\
  3047. <input style="border:none; color:#888888; background-color:#111111; cursor:pointer;"\
  3048. onclick="tosts(\'truncated\')" value="[sts_admin][truncated]" type="button">\
  3049. <input style="border:none; color:#888888; background-color:#111111; cursor:pointer;"\
  3050. onclick="tosts(\'typo\');" value="[sts_admin][typo]" type="button">\
  3051. <input style="border:none; color:#888888; background-color:#111111; cursor:pointer;"\
  3052. onclick="tosts(\'unlockpls\')" value="[sts_admin][unlockpls]" type="button">\
  3053. ';
  3054. eleParent.appendChild(eleSpan);
  3055. }
  3056. var eleAutoCopy = document.querySelector("#autocopy");
  3057. if (eleAutoCopy)
  3058. {
  3059. var eleAutoCopyHeader = eleAutoCopy.previousElementSibling;
  3060. eleAutoCopyHeader.classList.add("stsh_autoCopy_header");
  3061. eleAutoCopyHeader.firstElementChild.firstElementChild.textContent = "AUTO-REPLACEMENT";
  3062. eleAutoCopy.appendChild(document.createElement("br"));
  3063. }
  3064. var eleTableDiscuss = null;
  3065. var eleFriendDiscuss = document.querySelector(".friend_block_discussions");
  3066. if (eleFriendDiscuss)
  3067. {
  3068. if (eleAutoCopy)
  3069. {
  3070. insertBeforeElement(document.createElement("br"), eleAutoCopy.previousElementSibling);
  3071. }
  3072. eleTableDiscuss = eleFriendDiscuss.parentElement.parentElement.parentElement.parentElement;
  3073. if (eleTableDiscuss.tagName === "TABLE")
  3074. {
  3075. eleTableDiscuss.classList.add("stsh_discussion_table");
  3076. }
  3077. }
  3078. var elesDiscuss = document.querySelectorAll(".stsh_discussion");
  3079. for (var i = 0; i < elesDiscuss.length; i++)
  3080. {
  3081. var nodesChild = elesDiscuss[i].childNodes;
  3082. if (nodesChild.length > 2)
  3083. {
  3084. var arrNode = [];
  3085. for (var j = 3; j < nodesChild.length; j++)
  3086. {
  3087. arrNode.push(nodesChild[j]);
  3088. }
  3089. var eleDiv = document.createElement("div");
  3090. eleDiv.classList.add("stsh_discussion_text");
  3091. for (var j = 0; j < arrNode.length; j++)
  3092. {
  3093. eleDiv.appendChild(arrNode[j]);
  3094. }
  3095. elesDiscuss[i].appendChild(eleDiv);
  3096. eleDiv.classList.add("stsh_discussion_text_long");
  3097. }
  3098. }
  3099. }
  3100. // Move up glossary
  3101. {
  3102. var moveUpGlossary = function()
  3103. {
  3104. var eleDiscuss = document.querySelector(".stsh_discussion_header");
  3105. if (eleDiscuss)
  3106. {
  3107. var eleGlosGroup = document.createElement("div");
  3108. eleGlosGroup.classList.add("stsh_glossary_group");
  3109. insertBeforeElement(eleGlosGroup, eleDiscuss);
  3110. var eleHead = document.querySelector(".stsh_glossary_header");
  3111. if (eleHead)
  3112. {
  3113. if (!(eleHead.childNodes.length === 5
  3114. && eleHead.childNodes[4].nodeType === document.TEXT_NODE
  3115. && eleHead.childNodes[4].nodeValue === "No results"))
  3116. {
  3117. eleGlosGroup.appendChild(document.createElement("br"));
  3118. if (eleHead.tagName === "TABLE")
  3119. {
  3120. eleGlosGroup.appendChild(eleHead.previousElementSibling);
  3121. }
  3122. eleGlosGroup.appendChild(eleHead);
  3123. }
  3124. }
  3125. }
  3126. }
  3127. var eleAutoCopy = document.querySelector(".stsh_autoCopy_header");
  3128. if (eleAutoCopy)
  3129. {
  3130. var eleHead = document.querySelector(".stsh_glossary_header");
  3131. if (eleHead)
  3132. {
  3133. insertAfterElement(eleAutoCopy.nextElementSibling, eleHead);
  3134. insertAfterElement(eleAutoCopy, eleHead);
  3135. insertAfterElement(document.createElement("br"), eleHead);
  3136. insertAfterElement(document.createElement("br"), eleAutoCopy.nextElementSibling);
  3137. }
  3138. }
  3139. var eleFriendDiscuss = document.querySelector(".friend_block_discussions");
  3140. if (!eleFriendDiscuss)
  3141. {
  3142. moveUpGlossary();
  3143. }
  3144. else
  3145. {
  3146. var eleHelp = document.querySelector(".stsh_glossary_help");
  3147. if (eleHelp)
  3148. {
  3149. var eleBtn = document.createElement("input");
  3150. eleBtn.classList.add("stsh_glossary_move");
  3151. eleBtn.setAttribute("type", "button");
  3152. eleBtn.setAttribute("onclick", "return false;");
  3153. eleBtn.value = "Move up";
  3154. eleBtn.title = "Glossary is displayed below when discussion is active. "
  3155. + "\nClick here to move glossary up.";
  3156. insertAfterElement(eleBtn, eleHelp);
  3157. eleBtn.addEventListener("click", function(ev)
  3158. {
  3159. var eleTarget = ev.target;
  3160. eleTarget.classList.add("stsh_hidden");
  3161. moveUpGlossary();
  3162. });
  3163. }
  3164. }
  3165. }
  3166. // Add shortcut keys
  3167. {
  3168. var elesForm = document.querySelectorAll(".lbAction");
  3169. for (var i = 0; i < elesForm.length; i++)
  3170. {
  3171. var eleForm = elesForm[i];
  3172. var eleSubmit = eleForm.querySelector("input[type=submit]");
  3173. if (eleSubmit)
  3174. {
  3175. addKeyCtrlEnter(eleForm, eleSubmit);
  3176. }
  3177. }
  3178. var elesInputApprove = document.querySelectorAll(".stsh_action_approve");
  3179. if (elesInputApprove.length > 0)
  3180. {
  3181. var eleBind = elesInputApprove[0];
  3182. addKeyAlt(document, eleBind, ["BracketLeft", 219, "KeyO", 79, "KeyA", 65]); // [ O A
  3183. disableAfterClick(eleBind);
  3184. }
  3185. var eleInputApproveNext = document.querySelector(".stsh_action_approve_next");
  3186. if (eleInputApproveNext)
  3187. {
  3188. var eleBind = null;
  3189. if (!eleInputApproveNext.disabled)
  3190. {
  3191. // Can go next
  3192. if (elesInputApprove.length === 1)
  3193. {
  3194. // Go next if only 1 suggestion
  3195. if (document.querySelector(".suggestion_status_approved"))
  3196. {
  3197. // Don't go next if 1 or more approved suggestion
  3198. eleBind = elesInputApprove[0];
  3199. }
  3200. else
  3201. {
  3202. eleBind = eleInputApproveNext;
  3203. }
  3204. }
  3205. else if (elesInputApprove.length > 1)
  3206. {
  3207. // Only approve if more than 1 suggestion
  3208. eleBind = elesInputApprove[0];
  3209. }
  3210. }
  3211. else
  3212. {
  3213. // Can't go next
  3214. if (elesInputApprove.length > 0)
  3215. {
  3216. var eleBind = elesInputApprove[0];
  3217. }
  3218. }
  3219. if (eleBind)
  3220. {
  3221. addKeyAlt(document, eleBind, ["BracketRight", 221, 171, "KeyP", 80, "KeyS", 83]); // ] P S
  3222. addKeyCtrl(document, eleBind, ["Backslash", 220, "Insert", 45], "Ins", 1|2); // Backslash, INS
  3223. disableAfterClick(eleBind);
  3224. }
  3225. }
  3226. var eleInputDecline = document.querySelector(".stsh_action_decline");
  3227. if (eleInputDecline)
  3228. {
  3229. var eleBind = eleInputDecline;
  3230. addKeyCtrl(document, eleBind, ["Delete", 46], "Del", 1|2); // DEL
  3231. disableAfterClick(eleBind);
  3232. var eleInpueDeclineNext = eleInputDecline.nextElementSibling;
  3233. if (eleInpueDeclineNext && eleInpueDeclineNext.value.indexOf("Next") > -1
  3234. && !eleInpueDeclineNext.disabled)
  3235. {
  3236. var eleBind = eleInpueDeclineNext;
  3237. addKeyCtrlShift(document, eleBind, ["Delete", 46], "Del", 2); // DEL
  3238. disableAfterClick(eleBind);
  3239. }
  3240. }
  3241. else
  3242. {
  3243. var eleReconsider = document.querySelector(".suggestion_status_approved > a, .suggestion_status_declined > a");
  3244. if (eleReconsider)
  3245. {
  3246. if (eleReconsider.parentElement.classList.contains("suggestion_status_approved"))
  3247. {
  3248. var elesReconsiderApprove = document.querySelectorAll(".suggestion_status_approved > a");
  3249. if (elesReconsiderApprove.length > 0)
  3250. {
  3251. // Bind to last approve
  3252. var eleBind = elesReconsiderApprove[elesReconsiderApprove.length - 1];
  3253. addKeyCtrl(document, eleBind, ["Delete", 46], "Del", 2|16); // DEL
  3254. }
  3255. }
  3256. else
  3257. {
  3258. if (!eleReconsider.parentElement.parentElement
  3259. .querySelector(".suggestion_signature .lbAction[name^='mymodcomment']"))
  3260. {
  3261. var eleBind = eleReconsider;
  3262. addKeyAlt(document, eleBind, ["BracketRight", 221, 171, "KeyP", 80, "KeyS", 83]); // ] P S
  3263. addKeyCtrl(document, eleBind, ["Backslash", 220, "Insert", 45], "Ins", 2|16); // Backslash INS
  3264. }
  3265. }
  3266. }
  3267. }
  3268. if (elesTextRemoveComment.length > 0)
  3269. {
  3270. // Remove last comment
  3271. var i = elesTextRemoveComment.length - 1;
  3272.  
  3273. var eleBind = elesTextRemoveComment[i];
  3274. addKeyCtrl(document, eleBind, ["Backspace", 8], "Bksp", 2|16); // Backspace
  3275. }
  3276. var eleInputPrev = document.querySelector(".stsh_nav_prev");
  3277. if (eleInputPrev)
  3278. {
  3279. var eleBind = eleInputPrev;
  3280. addKeyCtrl(document, eleBind, ["BracketLeft", 219], "[", 1|2); // [
  3281. disableAfterClick(eleBind);
  3282. // Remove space
  3283. removeElement(eleBind.nextSibling);
  3284. }
  3285. var eleInputNext = document.querySelector(".stsh_nav_next");
  3286. if (eleInputNext)
  3287. {
  3288. var eleBind = eleInputNext;
  3289. addKeyCtrl(document, eleBind, ["BracketRight", 221, 171], "]", 1|2); // ]
  3290. disableAfterClick(eleBind);
  3291. }
  3292. }
  3293. // Check special chars
  3294. // Check combining diacritical marks
  3295. // Check HTML elements count
  3296. {
  3297. if (eleHeaderOrg && eleHeaderTrn)
  3298. {
  3299. if (eleTextOrg && eleTextTrn)
  3300. {
  3301. var strOrg = trimTab(eleTextOrg.textContent);
  3302. var strTrn = "";
  3303. if (!eleTextTrn.classList.contains("stsh_text_trn_empty"))
  3304. {
  3305. strTrn = trimTab(eleTextTrn.textContent);
  3306. }
  3307. var elesSug = elesTextSug;
  3308. // Check special chars
  3309. {
  3310. var statusTrnArr = checkSpecialCharMatched(strOrg, strTrn);
  3311. var statusTrnMatched = statusTrnArr[0];
  3312. var spOrg = statusTrnArr[1];
  3313. var spTrn = statusTrnArr[2];
  3314. if (spOrg > 0 || spTrn > 0)
  3315. {
  3316. var spTitle = "Please check special chars by pressing Display special chars button.";
  3317. var spanSpOrg = document.createElement("span");
  3318. spanSpOrg.id = "stsh_spanSpOrg";
  3319. spanSpOrg.classList.add("stsh_spanStatusOrg");
  3320. spanSpOrg.classList.add("stsh_blue");
  3321. spanSpOrg.classList.add("stsh_cursor_help");
  3322. spanSpOrg.title = spTitle;
  3323. spanSpOrg.innerHTML = " SpecialChar: " + spOrg;
  3324. eleHeaderOrg.appendChild(spanSpOrg);
  3325. // Translated
  3326. if (strTrn !== "")
  3327. {
  3328. var spanSpTrn = document.createElement("span");
  3329. spanSpTrn.id = "stsh_spanSpTrn";
  3330. spanSpTrn.classList.add("stsh_spanStatusTrn");
  3331. spanSpTrn.classList.add("stsh_cursor_help");
  3332. spanSpTrn.title = spTitle;
  3333. if (statusTrnMatched === 0)
  3334. {
  3335. spanSpTrn.classList.add("stsh_green");
  3336. }
  3337. else
  3338. {
  3339. spanSpTrn.classList.add("stsh_red");
  3340. spanSpTrn.classList.add("stsh_status_unmatched");
  3341. }
  3342. var outputTrn = " SpecialChar: " + spTrn;
  3343. if (statusTrnMatched === 0)
  3344. {
  3345. outputTrn += " (Matched)";
  3346. }
  3347. else if (statusTrnMatched === 1)
  3348. {
  3349. outputTrn += " (Order not matched)";
  3350. }
  3351. else
  3352. {
  3353. outputTrn += " (Not matched)";
  3354. }
  3355. spanSpTrn.innerHTML = outputTrn;
  3356. eleHeaderTrn.appendChild(spanSpTrn);
  3357. }
  3358. // Suggested
  3359. for (var i = 0; i < elesSug.length; i++)
  3360. {
  3361. var eleSug = elesSug[i];
  3362. var strSug = trimSpace(eleSug.textContent);
  3363. var statusSugArr = checkSpecialCharMatched(strOrg, strSug);
  3364. var statusSugMatched = statusSugArr[0];
  3365. var spSug = statusSugArr[2];
  3366. var spanSpSug = document.createElement("span");
  3367. spanSpSug.classList.add("stsh_spanSpSug");
  3368. spanSpSug.classList.add("stsh_spanStatusSug");
  3369. spanSpSug.classList.add("stsh_cursor_help");
  3370. spanSpSug.title = spTitle;
  3371. if (statusSugMatched === 0)
  3372. {
  3373. spanSpSug.classList.add("stsh_green");
  3374. spanSpSug.classList.add("stsh_status_matched");
  3375. }
  3376. else
  3377. {
  3378. spanSpSug.classList.add("stsh_red");
  3379. spanSpSug.classList.add("stsh_status_unmatched");
  3380. }
  3381. var outputSug = " SpecialChar: " + spSug;
  3382. if (statusSugMatched === 0)
  3383. {
  3384. outputSug += " (Matched)";
  3385. }
  3386. else if (statusSugMatched === 1)
  3387. {
  3388. outputSug += " (Order not matched)";
  3389. }
  3390. else
  3391. {
  3392. outputSug += " (Not matched)";
  3393. }
  3394. spanSpSug.innerHTML = outputSug;
  3395. insertBeforeElement(spanSpSug, eleSug);
  3396. }
  3397. }
  3398. }
  3399. // Check diacritical marks
  3400. {
  3401. var hasDct = false;
  3402. // Translated
  3403. var dctTrn = countDiacriticalMark(strTrn);
  3404. if (dctTrn > 0)
  3405. {
  3406. hasDct = true;
  3407. }
  3408. var countsSug = [];
  3409. // Suggested
  3410. for (var i = 0; i < elesSug.length; i++)
  3411. {
  3412. var eleSug = elesSug[i];
  3413. var strSug = trimSpace(eleSug.textContent);
  3414. var dctSug = countDiacriticalMark(strSug);
  3415. if (dctSug > 0)
  3416. {
  3417. hasDct = true;
  3418. }
  3419. countsSug.push(dctSug);
  3420. }
  3421. if (hasDct)
  3422. {
  3423. var dctTitleGood = "Combining Diacritical Marks not found. \nThis is good typing method.";
  3424. var dctTitleBad = "Combining Diacritical Marks found. \nPlease change typing method.";
  3425. var spanDctTrn = document.createElement("span");
  3426. spanDctTrn.id = "stsh_spanDctTrn";
  3427. spanDctTrn.classList.add("stsh_spanStatusTrn");
  3428. spanDctTrn.classList.add("stsh_cursor_help");
  3429. if (dctTrn > 0)
  3430. {
  3431. spanDctTrn.classList.add("stsh_red");
  3432. spanDctTrn.classList.add("stsh_status_unmatched");
  3433. spanDctTrn.title = dctTitleBad;
  3434. }
  3435. else
  3436. {
  3437. spanDctTrn.classList.add("stsh_green");
  3438. spanDctTrn.title = dctTitleGood;
  3439. }
  3440. var outputDctTrn = " DiacriticalMark: " + dctTrn;
  3441. spanDctTrn.innerHTML = outputDctTrn;
  3442. eleHeaderTrn.appendChild(spanDctTrn);
  3443. for (var i = 0; i < elesSug.length; i++)
  3444. {
  3445. var eleSug = elesSug[i];
  3446. var dctSug = countsSug[i];
  3447. var spanDctSug = document.createElement("span");
  3448. spanDctSug.classList.add("stsh_spanDctSug");
  3449. spanDctSug.classList.add("stsh_spanStatusSug");
  3450. spanDctSug.classList.add("stsh_cursor_help");
  3451. if (dctSug > 0)
  3452. {
  3453. spanDctSug.classList.add("stsh_red");
  3454. spanDctSug.classList.add("stsh_status_unmatched");
  3455. spanDctSug.title = dctTitleBad;
  3456. }
  3457. else
  3458. {
  3459. spanDctSug.classList.add("stsh_green");
  3460. spanDctSug.title = dctTitleGood;
  3461. }
  3462. var outputDctSug = " DiacriticalMark: " + dctSug;
  3463. spanDctSug.innerHTML = outputDctSug;
  3464. insertBeforeElement(spanDctSug, eleSug);
  3465. }
  3466. }
  3467. }
  3468. // Check HTML elements count
  3469. // Sample: https://translation.steampowered.com/translate.php?search_input=%23Email_Partner_KeyRequest_Doc_Instructions
  3470. // Sample: https://translation.steampowered.com/translate.php?search_input=turret.sp_sabotage_factory_defect
  3471. {
  3472. var hasElement = false;
  3473. var queryCount = ':not([style="color:red;"])'
  3474. + ':not([style="color:#ff0000;"])'
  3475. + ':not([style="color:#ffffff;"])'
  3476. + ':not([style="BACKGROUND-COLOR: blue"])'
  3477. + ':not([face="Times New Roman"])'
  3478. + ':not([data-pagespeed-no-defer])';
  3479. var countEleOrg = eleTextOrg.querySelectorAll(queryCount).length;
  3480. var countEleTrn = -1; // -1 means Not Translated
  3481. if (!eleTextTrn.classList.contains("stsh_text_trn_empty"))
  3482. {
  3483. countEleTrn = eleTextTrn.querySelectorAll(queryCount).length;
  3484. }
  3485. var countsSug = [];
  3486. // Suggested
  3487. var elesSug = elesTextSug;
  3488. for (var i = 0; i < elesSug.length; i++)
  3489. {
  3490. var eleSug = elesSug[i];
  3491. var countEle = eleSug.querySelectorAll(queryCount).length;;
  3492. if (countEle > 0)
  3493. {
  3494. hasElement = true;
  3495. }
  3496. countsSug.push(countEle);
  3497. }
  3498. hasElement = hasElement || countEleOrg > 0 || countEleTrn > 0;
  3499. if (hasElement)
  3500. {
  3501. var countTitleGood = "You can check HTML elements by pressing Display HTML tags button. "
  3502. + "\nSome tags and attributes were generated or removed by STS "
  3503. + "\n(such as <script>, <br> and <img> tags). "
  3504. + "\nIf you can submit, then it's OK.";
  3505. var countTitleBad = "HTML elements count not matched. \n" + countTitleGood;
  3506. var spanCountOrg = document.createElement("span");
  3507. spanCountOrg.id = "stsh_spanCountEleOrg";
  3508. spanCountOrg.classList.add("stsh_spanStatusOrg");
  3509. spanCountOrg.classList.add("stsh_blue");
  3510. spanCountOrg.classList.add("stsh_cursor_help");
  3511. spanCountOrg.title = countTitleGood;
  3512. spanCountOrg.innerHTML = " HtmlElementCount: " + countEleOrg;
  3513. eleHeaderOrg.appendChild(spanCountOrg);
  3514. // Translated
  3515. if (countEleTrn > -1)
  3516. {
  3517. var spanCountTrn = document.createElement("span");
  3518. spanCountTrn.id = "stsh_spanCountEleTrn";
  3519. spanCountTrn.classList.add("stsh_spanStatusTrn");
  3520. spanCountTrn.classList.add("stsh_cursor_help");
  3521. var outputTrn = " HtmlElementCount: " + countEleTrn;
  3522. if (countEleOrg === countEleTrn)
  3523. {
  3524. spanCountTrn.classList.add("stsh_green");
  3525. spanCountTrn.title = countTitleGood;
  3526. outputTrn += (countEleOrg > 0) ? " (Matched)" : "";
  3527. }
  3528. else
  3529. {
  3530. spanCountTrn.classList.add("stsh_blue");
  3531. spanCountTrn.classList.add("stsh_status_unmatched");
  3532. spanCountTrn.title = countTitleBad;
  3533. outputTrn += (countEleOrg > 0) ? " (Not matched)" : "";
  3534. }
  3535. spanCountTrn.innerHTML = outputTrn;
  3536. eleHeaderTrn.appendChild(spanCountTrn);
  3537. }
  3538. // Suggested
  3539. for (var i = 0; i < elesSug.length; i++)
  3540. {
  3541. var eleSug = elesSug[i];
  3542. var countEleSug = countsSug[i];
  3543. var spanCountSug = document.createElement("span");
  3544. spanCountSug.classList.add("stsh_spanCountEleSug");
  3545. spanCountSug.classList.add("stsh_spanStatusSug");
  3546. spanCountSug.classList.add("stsh_cursor_help");
  3547. var outputSug = " HtmlElementCount: " + countEleSug;
  3548. if (countEleOrg === countEleSug)
  3549. {
  3550. spanCountSug.classList.add("stsh_green");
  3551. spanCountSug.title = countTitleGood;
  3552. outputSug += (countEleOrg > 0) ? " (Matched)" : "";
  3553. }
  3554. else
  3555. {
  3556. spanCountSug.classList.add("stsh_blue");
  3557. spanCountSug.classList.add("stsh_status_unmatched");
  3558. spanCountSug.title = countTitleBad;
  3559. outputSug += (countEleOrg > 0) ? "/" + countEleOrg + " (Not matched)" : "";
  3560. }
  3561. spanCountSug.innerHTML = outputSug;
  3562. insertBeforeElement(spanCountSug, eleSug);
  3563. }
  3564. }
  3565. }
  3566. }
  3567. }
  3568. }
  3569. // Display newlines
  3570. // Display spaces
  3571. // Display specialChars
  3572. // Display HTML tags
  3573. // Display hidden contents
  3574. // Minimize images
  3575. {
  3576. var eleSugListHeader = document.querySelector(".stsh_suggestion_list_header");
  3577. if (eleSugListHeader && eleTextOrg && eleTextTrn)
  3578. {
  3579. var htmlOrg = eleTextOrg.dataset.stshHtml;
  3580. var htmlTrn = eleTextTrn.classList.contains("stsh_text_trn_empty") ? "" : eleTextTrn.dataset.stshHtml;
  3581. var elesSug = elesTextSug;
  3582. var eleGroup = null;
  3583. var elesBtn = [null, null, null, null, null, null, null, null]
  3584. var enableDisplay = false;
  3585. var enableNewline = false;
  3586. var enableSpace = false;
  3587. var enableSpecialChar = false;
  3588. var enableHtmlTag = false;
  3589. var enableHidden = false;
  3590. var enableMinImg = false;
  3591. var rgxSpaceTagOpen = /(<[^\/][^>]+>)( +)([^< \r\n])/g;
  3592. var rgxSpaceTagClose = /([^> \r\n])( +)(<\/[^>]+>)/g;
  3593. var hasNewline = function(html)
  3594. {
  3595. return html.indexOf("\n") > -1 || html.indexOf("\\n") > -1;
  3596. }
  3597. var hasSpace = function(html)
  3598. {
  3599. return html.indexOf(" ") === 0 || isLastIndex(html, " ")
  3600. || rgxSpaceTagOpen.test(html) || rgxSpaceTagClose.test(html);
  3601. }
  3602. var hasHtmlTag = function(html)
  3603. {
  3604. return html.indexOf("<") > -1 || html.indexOf("[/") > -1;
  3605. }
  3606. var hasHidden = function(eleTextOrg, eleTextTrn, elesSug)
  3607. {
  3608. var returnValue = false;
  3609. returnValue = !!(eleTextOrg.querySelector("*[style='display: none;']")
  3610. || eleTextTrn.querySelector("*[style='display: none;']"));
  3611. if (!returnValue)
  3612. {
  3613. if (elesSug.length > 0)
  3614. {
  3615. returnValue = !!(elesSug[0].querySelector("*[style='display: none;']"));
  3616. }
  3617. }
  3618. if (returnValue)
  3619. {
  3620. var countHidden = 0;
  3621. var elesHidden = eleTextOrg.querySelectorAll("*[style='display: none;']");
  3622. for (var i = 0; i < elesHidden.length; i++)
  3623. {
  3624. if (elesHidden[i].childElementCount > 1
  3625. || (elesHidden[i].firstElementChild
  3626. && elesHidden[i].firstElementChild.tagName !== "STYLE"))
  3627. {
  3628. countHidden++;
  3629. break;
  3630. }
  3631. }
  3632. returnValue = countHidden > 0;
  3633. }
  3634. if (!returnValue)
  3635. {
  3636. returnValue = !!(eleTextOrg.querySelector(".collapse, .dropdown-before")
  3637. || eleTextTrn.querySelector(".collapse, .dropdown-before"));
  3638. }
  3639. return returnValue;
  3640. }
  3641. var hasImage = function(eleTextOrg, eleTextTrn)
  3642. {
  3643. return !!(eleTextOrg.querySelector("img") || eleTextTrn.querySelector("img"));
  3644. }
  3645. enableNewline = hasNewline(htmlOrg) || hasNewline(htmlTrn);
  3646. enableSpace = hasSpace(htmlOrg) || hasSpace(htmlTrn);
  3647. enableSpecialChar = hasSpecialChar(htmlOrg) || hasSpecialChar(htmlTrn);
  3648. enableHtmlTag = hasHtmlTag(htmlOrg) || hasHtmlTag(htmlTrn);
  3649. enableHidden = hasHidden(eleTextOrg, eleTextTrn, elesSug);
  3650. enableMinImg = hasImage(eleTextOrg, eleTextTrn);
  3651. for (var i = 0; i < elesSug.length; i++)
  3652. {
  3653. var htmlSug = elesSug[i].dataset.stshHtml;
  3654. enableNewline = enableNewline || hasNewline(htmlSug);
  3655. enableSpace = enableSpace || hasSpace(htmlSug);
  3656. enableSpecialChar = enableSpecialChar || hasSpecialChar(htmlSug);
  3657. }
  3658. enableDisplay = enableNewline || enableSpace || enableSpecialChar
  3659. || enableHtmlTag || enableHidden || enableMinImg;
  3660. if (enableDisplay)
  3661. {
  3662. elesBtn[0] = document.createElement("input");
  3663. elesBtn[0].id = "stsh_btn_restoreContents";
  3664. elesBtn[0].classList.add("stsh_btn_right");
  3665. elesBtn[0].classList.add("stsh_margin_left");
  3666. elesBtn[0].setAttribute("type", "button");
  3667. elesBtn[0].setAttribute("value", "Restore contents");
  3668. elesBtn[0].setAttribute("title", "Restore original contents");
  3669. elesBtn[0].disabled = true;
  3670. eleSugListHeader.appendChild(elesBtn[0]);
  3671. var restoreContents = function(ele)
  3672. {
  3673. if (ele)
  3674. {
  3675. ele.innerHTML = ele.dataset.stshHtml;
  3676. }
  3677. };
  3678. elesBtn[0].addEventListener("click", function(ev)
  3679. {
  3680. var eleTarget = ev.target;
  3681. eleTarget.disabled = true;
  3682. for (var i = 1; i < elesBtn.length; i++)
  3683. {
  3684. if (elesBtn[i])
  3685. {
  3686. elesBtn[i].disabled = false;
  3687. elesBtn[i].focus();
  3688. }
  3689. }
  3690. var topOld = Math.floor(eleTarget.getBoundingClientRect().top) || 0;
  3691. var eleTextOrg = document.querySelector(".stsh_text_org");
  3692. var eleTextTrn = document.querySelector(".stsh_text_trn:not(.stsh_text_trn_empty)");
  3693. restoreContents(eleTextOrg);
  3694. restoreContents(eleTextTrn);
  3695. var elesSug = document.querySelectorAll(".suggestion_text");
  3696. for (var i = 0; i < elesSug.length; i++)
  3697. {
  3698. var eleSug = elesSug[i];
  3699. restoreContents(eleSug);
  3700. }
  3701. var topNew = Math.floor(eleTarget.getBoundingClientRect().top) || 0;
  3702. if (topOld !== topNew)
  3703. {
  3704. window.scrollBy(0, topNew - topOld);
  3705. }
  3706. });
  3707. eleGroup = document.createElement("div");
  3708. eleGroup.classList.add("stsh_group_display");
  3709. eleGroup.classList.add("stsh_btn_right");
  3710. eleSugListHeader.appendChild(eleGroup);
  3711. }
  3712. // Display newlines
  3713. if (enableNewline)
  3714. {
  3715. elesBtn[1] = document.createElement("input");
  3716. elesBtn[1].id = "stsh_btn_displayNewlines";
  3717. elesBtn[1].classList.add("stsh_btn_right");
  3718. elesBtn[1].classList.add("stsh_btn_display");
  3719. elesBtn[1].setAttribute("type", "button");
  3720. elesBtn[1].setAttribute("value", "Newlines");
  3721. elesBtn[1].setAttribute("title", "Display newlines (\\n and <br>)");
  3722. eleGroup.appendChild(elesBtn[1]);
  3723. var displayNewlines = function(ele)
  3724. {
  3725. if (ele)
  3726. {
  3727. ele.innerHTML = ele.dataset.stshHtml
  3728. .replace(/\<span[^\>]+class=\"stsh_[\s\S]+?\/span\>/ig, "")
  3729. .replace(/\n/g, "\n<br>")
  3730. .replace(/(\\r)? *\\n/g, ' <span class="stsh_marker">$&</span><br>')
  3731. .replace(/\<br\>[\s]+/g, "<br>&nbsp;");
  3732. }
  3733. };
  3734. elesBtn[1].addEventListener("click", function(ev)
  3735. {
  3736. var eleTarget = ev.target;
  3737. eleTarget.disabled = true;
  3738. for (var i = 0; i < elesBtn.length; i++)
  3739. {
  3740. if (elesBtn[i] && elesBtn[i] !== eleTarget)
  3741. {
  3742. elesBtn[i].disabled = false;
  3743. }
  3744. }
  3745. elesBtn[0].focus();
  3746. var topOld = Math.floor(eleTarget.getBoundingClientRect().top) || 0;
  3747. var eleTextOrg = document.querySelector(".stsh_text_org");
  3748. var eleTextTrn = document.querySelector(".stsh_text_trn:not(.stsh_text_trn_empty)");
  3749. displayNewlines(eleTextOrg);
  3750. displayNewlines(eleTextTrn);
  3751. var elesSug = document.querySelectorAll(".suggestion_text");
  3752. for (var i = 0; i < elesSug.length; i++)
  3753. {
  3754. var eleSug = elesSug[i];
  3755. displayNewlines(eleSug);
  3756. }
  3757. var topNew = Math.floor(eleTarget.getBoundingClientRect().top) || 0;
  3758. if (topOld !== topNew)
  3759. {
  3760. window.scrollBy(0, topNew - topOld);
  3761. }
  3762. });
  3763. }
  3764. // Display spaces
  3765. // Sample: Use regexp ^[ ]+[^/W]|[^/W][ ]+$ to search
  3766. // Sample: https://translation.steampowered.com/translate.php?search_input=portal_lyrics_17
  3767. // Sample: https://translation.steampowered.com/translate.php?search_input=portal_lyrics_23
  3768. if (enableSpace)
  3769. {
  3770. elesBtn[2] = document.createElement("input");
  3771. elesBtn[2].id = "stsh_btn_displaySpaces";
  3772. elesBtn[2].classList.add("stsh_btn_right");
  3773. elesBtn[2].classList.add("stsh_btn_display");
  3774. elesBtn[2].setAttribute("type", "button");
  3775. elesBtn[2].setAttribute("value", "Spaces");
  3776. elesBtn[2].setAttribute("title", "Strings may have leading or trailing spaces.");
  3777. eleGroup.appendChild(elesBtn[2]);
  3778. var displaySpaces = function(ele)
  3779. {
  3780. if (ele)
  3781. {
  3782. ele.innerHTML = ele.dataset.stshHtml
  3783. .replace(/(^ +| +$)/g, function(match, p1)
  3784. {
  3785. return '<span class="stsh_marker">' + p1.replace(/ /g,"_") + '</span>';
  3786. })
  3787. .replace(rgxSpaceTagOpen, function(match, p1, p2, p3)
  3788. {
  3789. return p1 + '<span class="stsh_marker">' + p2.replace(/ /g,"_") + '</span>' + p3;
  3790. })
  3791. .replace(rgxSpaceTagClose, function(match, p1, p2, p3)
  3792. {
  3793. return p1 + '<span class="stsh_marker">' + p2.replace(/ /g,"_") + '</span>' + p3;
  3794. });
  3795. }
  3796. }
  3797. elesBtn[2].addEventListener("click", function(ev)
  3798. {
  3799. var eleTarget = ev.target;
  3800. eleTarget.disabled = true;
  3801. for (var i = 0; i < elesBtn.length; i++)
  3802. {
  3803. if (elesBtn[i] && elesBtn[i] !== eleTarget)
  3804. {
  3805. elesBtn[i].disabled = false;
  3806. }
  3807. }
  3808. elesBtn[0].focus();
  3809. var topOld = Math.floor(eleTarget.getBoundingClientRect().top) || 0;
  3810. var eleTextOrg = document.querySelector(".stsh_text_org");
  3811. var eleTextTrn = document.querySelector(".stsh_text_trn:not(.stsh_text_trn_empty)");
  3812. displaySpaces(eleTextOrg);
  3813. displaySpaces(eleTextTrn);
  3814. var elesSug = document.querySelectorAll(".suggestion_text");
  3815. for (var i = 0; i < elesSug.length; i++)
  3816. {
  3817. var eleSug = elesSug[i];
  3818. displaySpaces(eleSug);
  3819. }
  3820. var topNew = Math.floor(eleTarget.getBoundingClientRect().top) || 0;
  3821. if (topOld !== topNew)
  3822. {
  3823. window.scrollBy(0, topNew - topOld);
  3824. }
  3825. });
  3826. }
  3827. // Display specialChars
  3828. // Sample: https://translation.steampowered.com/translate.php?search_input=Item_Traded
  3829. if (enableSpecialChar)
  3830. {
  3831. elesBtn[3] = document.createElement("input");
  3832. elesBtn[3].id = "stsh_btn_displaySpecialChars";
  3833. elesBtn[3].classList.add("stsh_btn_right");
  3834. elesBtn[3].classList.add("stsh_btn_display");
  3835. elesBtn[3].setAttribute("type", "button");
  3836. elesBtn[3].setAttribute("value", "Special chars");
  3837. elesBtn[3].setAttribute("title", "Special chars usually use in Valve games as color symbols.");
  3838. eleGroup.appendChild(elesBtn[3]);
  3839. var replaceSpecialChars = function(str, unicodeNumber)
  3840. {
  3841. var rgx = new RegExp("\\u" + padZeroHex(unicodeNumber, 4), "g");
  3842. return str.replace(rgx, '<span class="stsh_marker">[' + padZeroHex(unicodeNumber, 2) + ']</span>');
  3843. }
  3844. var displaySpecialChars = function(ele)
  3845. {
  3846. if (ele)
  3847. {
  3848. var strInner = (typeof ele.dataset.stshHtml === "undefined")
  3849. ? trimTab(ele.innerHTML) : ele.dataset.stshHtml;
  3850. for (var i = 0; i < 32; i++)
  3851. {
  3852. if (hasSpecialChar(strInner))
  3853. {
  3854. if (isSpecialChar(i))
  3855. {
  3856. strInner = replaceSpecialChars(strInner, i);
  3857. }
  3858. }
  3859. else
  3860. {
  3861. break;
  3862. }
  3863. }
  3864. ele.innerHTML = strInner;
  3865. }
  3866. }
  3867. elesBtn[3].addEventListener("click", function(ev)
  3868. {
  3869. var eleTarget = ev.target;
  3870. eleTarget.disabled = true;
  3871. for (var i = 0; i < elesBtn.length; i++)
  3872. {
  3873. if (elesBtn[i] && elesBtn[i] !== eleTarget)
  3874. {
  3875. elesBtn[i].disabled = false;
  3876. }
  3877. }
  3878. elesBtn[0].focus();
  3879. var topOld = Math.floor(eleTarget.getBoundingClientRect().top) || 0;
  3880. var eleTextOrg = document.querySelector(".stsh_text_org");
  3881. var eleTextTrn = document.querySelector(".stsh_text_trn:not(.stsh_text_trn_empty)");
  3882. displaySpecialChars(eleTextOrg);
  3883. displaySpecialChars(eleTextTrn);
  3884. var elesSug = document.querySelectorAll(
  3885. ".suggestion_text, .stsh_sametoken_header .insertword, .stsh_text_comment");
  3886. for (var i = 0; i < elesSug.length; i++)
  3887. {
  3888. var eleSug = elesSug[i];
  3889. displaySpecialChars(eleSug);
  3890. }
  3891. var topNew = Math.floor(eleTarget.getBoundingClientRect().top) || 0;
  3892. if (topOld !== topNew)
  3893. {
  3894. window.scrollBy(0, topNew - topOld);
  3895. }
  3896. });
  3897. }
  3898. // Display HTML tags
  3899. if (enableHtmlTag)
  3900. {
  3901. elesBtn[4] = document.createElement("input");
  3902. elesBtn[4].id = "stsh_btn_displayHtmlTags";
  3903. elesBtn[4].classList.add("stsh_btn_right");
  3904. elesBtn[4].classList.add("stsh_btn_display");
  3905. elesBtn[4].setAttribute("type", "button");
  3906. elesBtn[4].setAttribute("value", "HTML tags");
  3907. elesBtn[4].setAttribute("title"
  3908. , "Some closing tags and attributes were autogenerated by web browser.");
  3909. eleGroup.appendChild(elesBtn[4]);
  3910. elesBtn[4].addEventListener("click", function(ev)
  3911. {
  3912. var eleTarget = ev.target;
  3913. eleTarget.disabled = true;
  3914. for (var i = 0; i < elesBtn.length; i++)
  3915. {
  3916. if (elesBtn[i] && elesBtn[i] !== eleTarget)
  3917. {
  3918. elesBtn[i].disabled = false;
  3919. }
  3920. }
  3921. elesBtn[0].focus();
  3922. var topOld = Math.floor(eleTarget.getBoundingClientRect().top) || 0;
  3923. var eleTextOrg = document.querySelector(".stsh_text_org");
  3924. var eleTextTrn = document.querySelector(".stsh_text_trn:not(.stsh_text_trn_empty)");
  3925. displayHtmlTags(eleTextOrg);
  3926. displayHtmlTags(eleTextTrn);
  3927. var elesSug = document.querySelectorAll(".suggestion_text");
  3928. for (var i = 0; i < elesSug.length; i++)
  3929. {
  3930. var eleSug = elesSug[i];
  3931. displayHtmlTags(eleSug);
  3932. }
  3933. var topNew = Math.floor(eleTarget.getBoundingClientRect().top) || 0;
  3934. if (topOld !== topNew)
  3935. {
  3936. window.scrollBy(0, topNew - topOld);
  3937. }
  3938. });
  3939. }
  3940. // Display hidden contents
  3941. // Sample: https://translation.steampowered.com/translate.php?search_input=faq_4181_answer
  3942. if (enableHidden)
  3943. {
  3944. elesBtn[5] = document.createElement("input");
  3945. elesBtn[5].id = "stsh_btn_displayHidden";
  3946. elesBtn[5].classList.add("stsh_btn_right");
  3947. elesBtn[5].classList.add("stsh_btn_display");
  3948. elesBtn[5].setAttribute("type", "button");
  3949. elesBtn[5].setAttribute("value", "Hidden contents");
  3950. elesBtn[5].setAttribute("title", "Toggle show/hide contents that hidden by CSS."
  3951. + " \nHidden contents shown in gray boxes.");
  3952. elesBtn[5].dataset.modeNext = "show";
  3953. eleGroup.appendChild(elesBtn[5]);
  3954. var showHidden = function(ele, mode)
  3955. {
  3956. if (ele)
  3957. {
  3958. if (mode === "show")
  3959. {
  3960. var elesHidden = ele.querySelectorAll(
  3961. "*[style='display: none;'], .collapse, .dropdown-before");
  3962. for (var i = 0; i < elesHidden.length; i++)
  3963. {
  3964. elesHidden[i].classList.add("stsh_showHidden");
  3965. }
  3966. }
  3967. else
  3968. {
  3969. var elesHidden = ele.querySelectorAll(".stsh_showHidden");
  3970. for (var i = 0; i < elesHidden.length; i++)
  3971. {
  3972. elesHidden[i].classList.remove("stsh_showHidden");
  3973. }
  3974. }
  3975. }
  3976. }
  3977. elesBtn[5].addEventListener("click", function(ev)
  3978. {
  3979. var eleTarget = ev.target;
  3980. var mode = "show";
  3981. if (eleTarget.dataset.modeNext === "show")
  3982. {
  3983. mode = "show";
  3984. eleTarget.dataset.modeNext = "hide";
  3985. }
  3986. else
  3987. {
  3988. mode = "hide";
  3989. eleTarget.dataset.modeNext = "show";
  3990. }
  3991. var topOld = Math.floor(eleTarget.getBoundingClientRect().top) || 0;
  3992. var eleTextOrg = document.querySelector(".stsh_text_org");
  3993. var eleTextTrn = document.querySelector(".stsh_text_trn:not(.stsh_text_trn_empty)");
  3994. showHidden(eleTextOrg, mode);
  3995. showHidden(eleTextTrn, mode);
  3996. var elesSug = document.querySelectorAll(".suggestion_text");
  3997. for (var i = 0; i < elesSug.length; i++)
  3998. {
  3999. var eleSug = elesSug[i];
  4000. showHidden(eleSug, mode);
  4001. }
  4002. var topNew = Math.floor(eleTarget.getBoundingClientRect().top) || 0;
  4003. if (topOld !== topNew)
  4004. {
  4005. window.scrollBy(0, topNew - topOld);
  4006. }
  4007. });
  4008. }
  4009. // Minimize images
  4010. // Sample: https://translation.steampowered.com/translate.php?search_input=faq_4192_answer
  4011. if (enableMinImg)
  4012. {
  4013. elesBtn[6] = document.createElement("input");
  4014. elesBtn[6].id = "stsh_btn_minimizeImages";
  4015. elesBtn[6].classList.add("stsh_btn_right");
  4016. elesBtn[6].classList.add("stsh_btn_display");
  4017. elesBtn[6].setAttribute("type", "button");
  4018. elesBtn[6].setAttribute("value", "Minimize images");
  4019. elesBtn[6].setAttribute("title", "Toggle reduced/normal image sizes");
  4020. elesBtn[6].dataset.modeNext = "min";
  4021. eleGroup.appendChild(elesBtn[6]);
  4022. var minimizeImages = function(ele, mode)
  4023. {
  4024. if (ele)
  4025. {
  4026. if (mode === "min")
  4027. {
  4028. var elesImg = ele.querySelectorAll("img:not(.stsh_img_min)");
  4029. for (var i = 0; i < elesImg.length; i++)
  4030. {
  4031. elesImg[i].classList.add("stsh_img_min");
  4032. }
  4033. }
  4034. else
  4035. {
  4036. var elesImg = ele.querySelectorAll("img.stsh_img_min");
  4037. for (var i = 0; i < elesImg.length; i++)
  4038. {
  4039. elesImg[i].classList.remove("stsh_img_min");
  4040. }
  4041. }
  4042. }
  4043. }
  4044. elesBtn[6].addEventListener("click", function(ev)
  4045. {
  4046. var eleTarget = ev.target;
  4047. var mode = "min";
  4048. if (eleTarget.dataset.modeNext === "min")
  4049. {
  4050. mode = "min";
  4051. eleTarget.dataset.modeNext = "unmin";
  4052. }
  4053. else
  4054. {
  4055. mode = "unmin";
  4056. eleTarget.dataset.modeNext = "min";
  4057. }
  4058. var topOld = Math.floor(eleTarget.getBoundingClientRect().top) || 0;
  4059. var eleTextOrg = document.querySelector(".stsh_text_org");
  4060. var eleTextTrn = document.querySelector(".stsh_text_trn:not(.stsh_text_trn_empty)");
  4061. minimizeImages(eleTextOrg, mode);
  4062. minimizeImages(eleTextTrn, mode);
  4063. var elesSug = document.querySelectorAll(".suggestion_text");
  4064. for (var i = 0; i < elesSug.length; i++)
  4065. {
  4066. var eleSug = elesSug[i];
  4067. minimizeImages(eleSug, mode);
  4068. }
  4069. var topNew = Math.floor(eleTarget.getBoundingClientRect().top) || 0;
  4070. if (topOld !== topNew)
  4071. {
  4072. window.scrollBy(0, topNew - topOld);
  4073. }
  4074. });
  4075. }
  4076. if (enableDisplay)
  4077. {
  4078. var eleDiv = document.createElement("div");
  4079. eleDiv.classList.add("stsh_text_right");
  4080. eleDiv.classList.add("stsh_margin_right");
  4081. eleDiv.textContent = "Display:";
  4082. eleSugListHeader.appendChild(eleDiv);
  4083. }
  4084. }
  4085. }
  4086. // Open comment when decline
  4087. // Paste last comment
  4088. {
  4089. var countComment = 0;
  4090. var elesComment = [];
  4091. var countSug = document.querySelectorAll(".suggestions_list .suggestion").length;
  4092. if (countSug > 0)
  4093. {
  4094. var textOrg = "";
  4095. if (eleTextOrg)
  4096. {
  4097. textOrg = eleTextOrg.dataset.stshHtml.substr(0, 3000).toLowerCase();
  4098. }
  4099. var isSameTextOrg = textOrg === GM_getValue("textLastOrg_Comment", "");
  4100. var textLastCur = GM_getValue("textLastCur_Comment", "");
  4101. var isSetComment = false;
  4102. var countSugDeclined = document.querySelectorAll(
  4103. ".suggestions_list span[class='suggestion_status_declined']").length;
  4104. if (countSug !== countSugDeclined)
  4105. {
  4106. var elesSugCheck = document.querySelectorAll(".suggestions_list span[class^='suggestion_status_']");
  4107. if (countSug === elesSugCheck.length)
  4108. {
  4109. var eleSugDeclined = document.querySelector(".suggestions_list span[class='suggestion_status_declined']");
  4110. if (eleSugDeclined && eleSugDeclined === elesSugCheck[0] && eleSugDeclined.querySelector("a"))
  4111. {
  4112. countSugDeclined = countSug;
  4113. }
  4114. }
  4115. }
  4116. if (countSug === countSugDeclined)
  4117. {
  4118. var elesSugA = document.querySelectorAll(".suggestions_list span[class^='suggestion_status_'] a");
  4119. for (var i = 0; i < elesSugA.length; i++)
  4120. {
  4121. var eleComment = elesSugA[i].parentElement.parentElement.nextSibling;
  4122. if (eleComment.nodeName === "DIV" && eleComment.classList.contains("copy"))
  4123. {
  4124. if (elesSugA[i].parentElement.classList.contains("suggestion_status_declined"))
  4125. {
  4126. countComment++;
  4127. elesComment.push(eleComment);
  4128. }
  4129. }
  4130. }
  4131. if (countComment === elesSugA.length)
  4132. {
  4133. var isFocus = false;
  4134. for (var i = 0; i < elesComment.length; i++)
  4135. {
  4136. elesComment[i].style.display = "block";
  4137. if (!isFocus)
  4138. {
  4139. var eleTxt = elesComment[i].querySelector(".stsh_text_addComment");
  4140. if (eleTxt)
  4141. {
  4142. eleTxt.focus();
  4143. // Auto paste last comment
  4144. {
  4145. if (isSameTextOrg)
  4146. {
  4147. if (textLastCur !== "")
  4148. {
  4149. eleTxt.value = textLastCur;
  4150. isSetComment = true;
  4151. }
  4152. setTimeoutCustom(function(ele)
  4153. {
  4154. // paste again after script ran
  4155. if (ele)
  4156. {
  4157. var textLastCur = GM_getValue("textLastCur_Comment", "");
  4158. if (textLastCur !== "")
  4159. {
  4160. ele.value = textLastCur;
  4161. //ele.selectionStart = 0;
  4162. //ele.selectionEnd = ele.value.length;
  4163. }
  4164. }
  4165. }, timingInit.pasteLastComment, eleTxt);
  4166. }
  4167. }
  4168. /*
  4169. // Typonion
  4170. var eleSugOuter = elesComment[i].parentElement.parentElement.parentElement.parentElement;
  4171. if (eleSugOuter.classList.contains("suggestion"))
  4172. {
  4173. var eleOnion = eleSugOuter.querySelector(".suggestion_text font[style='color:#01ec00;']");
  4174. if (eleOnion)
  4175. {
  4176. eleTxt.value = "onion";
  4177. }
  4178. }
  4179. */
  4180. var eleSugComment = elesComment[i].parentElement
  4181. .parentElement.parentElement.querySelector(".stsh_text_comment font");
  4182. if (eleSugComment && eleSugComment.textContent.trim() ==
  4183. "ATTENTION - English string was updated. This suggestion might be outdated.")
  4184. {
  4185. eleTxt.value = "outdated";
  4186. isSetComment = true;
  4187. }
  4188. isFocus = true;
  4189. }
  4190. }
  4191. }
  4192. }
  4193. }
  4194. if (isSameTextOrg && !isSetComment && textLastCur !== "")
  4195. {
  4196. // paste last comment to all hidden comment inputs
  4197. var elesTxt = document.querySelectorAll(".stsh_text_addComment");
  4198. for (var i = 0; i < elesTxt.length; i++)
  4199. {
  4200. elesTxt[i].value = textLastCur;
  4201. isSetComment = true;
  4202. }
  4203. }
  4204. }
  4205. }
  4206. // Convert time
  4207. {
  4208. var rgxTime = /\d{2}-\d{2}-\d{4}, \d{2}:\d{2} [AP]M/;
  4209. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
  4210. var eleFriends = document.querySelectorAll(".friend_block_avatar, .stsh_discussion, .suggestions_list");
  4211. for (var i = 0; i < eleFriends.length; i++)
  4212. {
  4213. var nodes = [];
  4214. if (eleFriends[i].classList.contains("friend_block_avatar"))
  4215. {
  4216. nodes = eleFriends[i].childNodes;
  4217. if (nodes.length === 1)
  4218. {
  4219. // Correct HTML tags that auto generated
  4220. nodes = eleFriends[i].childNodes[0].childNodes;
  4221. }
  4222. }
  4223. else if (eleFriends[i].classList.contains("stsh_discussion"))
  4224. {
  4225. nodes = eleFriends[i].childNodes[2].childNodes;
  4226. }
  4227. else if (eleFriends[i].classList.contains("suggestions_list"))
  4228. {
  4229. if (!eleFriends[i].querySelector(".suggestion"))
  4230. {
  4231. nodes = eleFriends[i].childNodes;
  4232. }
  4233. }
  4234. for (var j = 0; j < nodes.length; j++)
  4235. {
  4236. var nodeVal = nodes[j].nodeValue;
  4237. if (nodeVal)
  4238. {
  4239. var dateTimes = rgxTime.exec(nodeVal);
  4240. if (dateTimes)
  4241. {
  4242. var dateTime = dateTimes[0];
  4243. var month = dateTime.substr(0, 2);
  4244. var day = dateTime.substr(3, 2);
  4245. var year = dateTime.substr(6, 4);
  4246. var hour = dateTime.substr(12, 2);
  4247. var minute = dateTime.substr(15, 2);
  4248. var period = dateTime.substr(18, 2);
  4249. if (period === "AM")
  4250. {
  4251. if (hour === "12")
  4252. {
  4253. hour = "00"
  4254. }
  4255. }
  4256. else if (period === "PM")
  4257. {
  4258. hour = parseInt(hour) + 12;
  4259. if (hour === 24)
  4260. {
  4261. hour = 12;
  4262. }
  4263. }
  4264. var dateTimeStd = year + "-" + month + "-" + day;
  4265. if (isDstUs(year, month, day, hour))
  4266. {
  4267. dateTimeStd += "T" + hour + ":" + minute + ":00-0700";
  4268. }
  4269. else
  4270. {
  4271. dateTimeStd += "T" + hour + ":" + minute + ":00-0800";
  4272. }
  4273. var dateStd = new Date(dateTimeStd);
  4274. if (dateStd.toLocaleString() !== "Invalid Date")
  4275. {
  4276. var gmt = dateStd.getTimezoneOffset() / 60 * -1;
  4277. var gmtStr = " GMT";
  4278. if (gmt > 0)
  4279. {
  4280. gmtStr += "+" + gmt;
  4281. }
  4282. else if (gmt < 0)
  4283. {
  4284. gmtStr += "-" + gmt;
  4285. }
  4286. var dateNew = dateStd.getDate()
  4287. + " " + months[dateStd.getMonth()]
  4288. + " " + dateStd.getFullYear()
  4289. + ", " + padZero(dateStd.getHours(), 2)
  4290. + ":" + padZero(dateStd.getMinutes(), 2)
  4291. + gmtStr;
  4292. //console.log("Time: " + dateTimeStd);
  4293. //console.log("Time: " + dateTime + " -> " + dateNew);
  4294. //var dateNew2 = dateStd.toLocaleString() + gmtStr;
  4295. //console.log("Time: " + dateTime + " -> " + dateNew2);
  4296. var nodeValBegin = nodeVal.substr(0, nodeVal.indexOf(dateTime));
  4297. var nodeValEnd = nodeVal.substr(nodeVal.indexOf(dateTime) + dateTime.length);
  4298. nodes[j].nodeValue = nodeValBegin;
  4299. var ele = document.createElement("span");
  4300. ele.classList.add("stsh_time_convert");
  4301. ele.classList.add("stsh_cursor_help");
  4302. ele.setAttribute("title", dateTime);
  4303. ele.textContent = dateNew;
  4304. insertAfterElement(ele, nodes[j]);
  4305. if (nodeValEnd !== "")
  4306. {
  4307. insertAfterElement(document.createTextNode(nodeValEnd), ele);
  4308. }
  4309. }
  4310. else
  4311. {
  4312. console.log("Invalid Date: " + dateTimeStd);
  4313. }
  4314. }
  4315. }
  4316. }
  4317. }
  4318. }
  4319. // Fix STS PM functions
  4320. {
  4321. var elesSpan = document.querySelectorAll(".friend_block_avatar > span[onclick^='totranslator']");
  4322. for (var i = 0; i < elesSpan.length; i++)
  4323. {
  4324. var eleUser = elesSpan[i].parentElement.firstElementChild;
  4325. if (eleUser.tagName === "A")
  4326. {
  4327. var execUser = /user=([0-9]+)/i.exec(eleUser.getAttribute("href"));
  4328. if (execUser && execUser.length === 2)
  4329. {
  4330. var attrClick = elesSpan[i].getAttribute("onclick");
  4331. var execTranslator = /totranslator\('([0-9]+)'\)/i.exec(attrClick);
  4332. if (execTranslator && execTranslator.length === 2)
  4333. {
  4334. if (execUser[1] !== execTranslator[1])
  4335. {
  4336. elesSpan[i].setAttribute("onclick", "totranslator('" + execUser[1] + "')");
  4337. }
  4338. }
  4339. }
  4340. }
  4341. }
  4342. }
  4343. // Add Steam profile links
  4344. {
  4345. var elesSpan = document.querySelectorAll("span[title='Send this user a private message']");
  4346. for (var i = 0; i < elesSpan.length; i++)
  4347. {
  4348. var attrClick = elesSpan[i].getAttribute("onclick");
  4349. var execTranslator = /totranslator\('([0-9]+)'\)/i.exec(attrClick);
  4350. if (execTranslator && execTranslator.length === 2)
  4351. {
  4352. var ele = document.createElement("a");
  4353. ele.classList.add("stsh_steamProfile");
  4354. ele.setAttribute("target", "_blank");
  4355. ele.setAttribute("title", "View Steam profile");
  4356. ele.setAttribute("href", "https://steamcommunity.com/profiles/" + execTranslator[1]);
  4357. var name = "Steam";
  4358. var eleParent = elesSpan[i].parentElement;
  4359. if (eleParent.classList.contains("friend_block_avatar"))
  4360. {
  4361. var eleImg = eleParent.querySelector("a[href^='user_activity.php'] > img");
  4362. if (eleImg && eleImg.title && eleImg.title.trim())
  4363. {
  4364. name = eleImg.title.trim();
  4365. }
  4366. }
  4367. else if (eleParent.tagName === "TD")
  4368. {
  4369. var eleImg = eleParent.parentElement.querySelector(
  4370. "td > .friend_block_discussions > a[href^='user_activity.php'] > img");
  4371. if (eleImg && eleImg.title && eleImg.title.trim())
  4372. {
  4373. name = eleImg.title.trim();
  4374. }
  4375. }
  4376. ele.textContent = " " + name + " ";
  4377. var eleNext = elesSpan[i].nextSibling;
  4378. if (eleNext && eleNext.textContent.trim() === "")
  4379. {
  4380. eleNext.textContent = " | ";
  4381. }
  4382. insertAfterElement(ele, elesSpan[i]);
  4383. }
  4384. }
  4385. }
  4386. // Add auto approve
  4387. {
  4388. if (elesInputApprove.length > 0)
  4389. {
  4390. var eleInput = document.createElement("input");
  4391. eleInput.id = "stsh_autoApprove";
  4392. eleInput.setAttribute("type", "checkbox");
  4393. eleInput.setAttribute("value", "auto");
  4394. var eleLabel = document.createElement("label");
  4395. eleLabel.classList.add("stsh_autoApprove_label");
  4396. eleLabel.classList.add("stsh_unselectable");
  4397. eleLabel.setAttribute("for", "stsh_autoApprove");
  4398. eleLabel.setAttribute("title", "Please use with care!");
  4399. eleLabel.textContent = " Auto Approve Next ";
  4400. elesInputApprove[0].parentElement.appendChild(eleInput);
  4401. elesInputApprove[0].parentElement.appendChild(eleLabel);
  4402. var autoApprove = function()
  4403. {
  4404. console.log("AutoApprove: Next in " + timingInit.autoApprove + "ms");
  4405. setTimeoutCustom(function ()
  4406. {
  4407. var eleCheck = document.querySelector("#stsh_autoApprove");
  4408. if (eleCheck && eleCheck.checked)
  4409. {
  4410. var isClicked = false;
  4411. var ele = document.querySelector(".stsh_action_approve_next");
  4412. if (ele && !ele.disabled && isVisible())
  4413. {
  4414. var isSkip = false;
  4415. var eleSugComment = ele.parentElement
  4416. .parentElement.parentElement.querySelector(".stsh_text_comment font");
  4417. if (eleSugComment && eleSugComment.textContent.trim() ==
  4418. "ATTENTION - English string was updated. This suggestion might be outdated.")
  4419. {
  4420. isSkip = true;
  4421. }
  4422. if (!isSkip)
  4423. {
  4424. var eleStatusUnmatched = document.querySelector(".stsh_spanSpSug.stsh_status_unmatched");
  4425. if (eleStatusUnmatched)
  4426. {
  4427. isSkip = true;
  4428. }
  4429. }
  4430. if (!isSkip)
  4431. {
  4432. isClicked = true;
  4433. GM_setValue("timeAutoApproveLast", getUnixTimestamp());
  4434. ele.click();
  4435. }
  4436. }
  4437. if (!isClicked)
  4438. {
  4439. eleCheck.checked = false;
  4440. GM_setValue("isAutoApprove", "false");
  4441. }
  4442. }
  4443. }, timingInit.autoApprove);
  4444. }
  4445. var tmDiff = getUnixTimestamp() - GM_getValue("timeAutoApproveLast", 0);
  4446. if (tmDiff > 10)
  4447. {
  4448. // > 10s
  4449. eleInput.checked = false;
  4450. GM_setValue("isAutoApprove", "false");
  4451. }
  4452. if (window !== window.parent)
  4453. {
  4454. var eleOuter = window.parent.document.querySelector("#suggestions_box_outer");
  4455. if (eleOuter)
  4456. {
  4457. if (eleOuter.style.display === "none")
  4458. {
  4459. // Closed iFrame
  4460. eleInput.checked = false;
  4461. GM_setValue("isAutoApprove", "false");
  4462. }
  4463. }
  4464. }
  4465. if (GM_getValue("isAutoApprove", 0) === "true")
  4466. {
  4467. eleInput.checked = true;
  4468. autoApprove();
  4469. var uncheckAutoApprove = function (ev)
  4470. {
  4471. var eleTarget = ev.target;
  4472. if (eleTarget.id !== "stsh_autoApprove"
  4473. && !eleTarget.classList.contains("stsh_autoApprove_label")
  4474. && !eleTarget.classList.contains("stsh_action_approve_next"))
  4475. {
  4476. // Skip auto click
  4477. var eleAuto = document.querySelector("#stsh_autoApprove");
  4478. if (eleAuto)
  4479. {
  4480. console.log("AutoApprove: Stop");
  4481. eleAuto.checked = false;
  4482. GM_setValue("isAutoApprove", "false");
  4483. document.removeEventListener("click", uncheckAutoApprove);
  4484. }
  4485. }
  4486. };
  4487. // Stop with any clicked
  4488. document.addEventListener("click", uncheckAutoApprove);
  4489. }
  4490.  
  4491. eleInput.addEventListener("click", function (e)
  4492. {
  4493. var ele = e.target;
  4494. if (ele.checked)
  4495. {
  4496. GM_setValue("isAutoApprove", "true");
  4497. autoApprove();
  4498. }
  4499. else
  4500. {
  4501. GM_setValue("isAutoApprove", "false");
  4502. }
  4503. });
  4504. }
  4505. }
  4506. // Warn when remove
  4507. // Suggest to remove
  4508. // Add remove & next
  4509. {
  4510. var canNext = !!(document.querySelector(".stsh_nav_next:not(:disabled)"));
  4511. var elesRemove = document.querySelectorAll(".stsh_action_remove");
  4512. for (var i = 0; i < elesRemove.length; i++)
  4513. {
  4514. var isDisabled = false;
  4515. var oldClick = elesRemove[i].getAttribute("onclick");
  4516. if (oldClick && oldClick.indexOf("location.href") === 0)
  4517. {
  4518. var eleSug = elesRemove[i].parentElement.parentElement.parentElement.parentElement;
  4519. if (eleSug.classList.contains("suggestion"))
  4520. {
  4521. /*
  4522. // Typonion
  4523. var eleOnion = eleSug.querySelector(".suggestion_text font[style='color:#01ec00;']");
  4524. if (eleOnion)
  4525. {
  4526. var newClick = "if (!confirm(\"Warning: You will delete your onion. Press Cancel to go back.\")) return false; "
  4527. + oldClick;
  4528. elesRemove[i].setAttribute("onclick", newClick);
  4529. elesRemove[i].setAttribute("title", "Do not remove your onion!");
  4530. elesRemove[i].classList.add("stsh_grey");
  4531. elesRemove[i].classList.add("stsh_cursor_notallowed");
  4532. }
  4533. else
  4534. */
  4535. {
  4536. var eleModComment = elesRemove[i].parentElement.querySelector(".stsh_text_comment_header");
  4537. if (eleModComment)
  4538. {
  4539. // Mod commented, suggest to do not remove
  4540. var newClick = "if (!confirm(\"Warning: You should not remove this suggestion."
  4541. + " Press OK if you really want.\")) return false; "
  4542. + oldClick;
  4543. elesRemove[i].setAttribute("onclick", newClick);
  4544. elesRemove[i].setAttribute("title",
  4545. "Your suggestion has a mod's comment! \nShould not remove this suggestion.");
  4546. elesRemove[i].classList.add("stsh_grey");
  4547. elesRemove[i].classList.add("stsh_cursor_notallowed");
  4548. isDisabled = true;
  4549. }
  4550. else
  4551. {
  4552. var eleUserComment = elesRemove[i].parentElement.parentElement.parentElement
  4553. .querySelector(".stsh_text_comment_header");
  4554. if (eleUserComment)
  4555. {
  4556. // User commented
  4557. var comment = eleUserComment.textContent.trim();
  4558. if (comment.indexOf("ATTENTION - English string was updated.") > -1)
  4559. {
  4560. // Outdated, suggest to edit and remove
  4561. elesRemove[i].setAttribute("title",
  4562. "Please edit and remove this outdated suggestion.");
  4563. elesRemove[i].classList.add("stsh_green");
  4564. elesRemove[i].classList.add("stsh_border_green");
  4565. isDisabled = true;
  4566. }
  4567. }
  4568. }
  4569. if (!isDisabled)
  4570. {
  4571. var eleDeclined = elesRemove[i].parentElement.querySelector(".suggestion_status_declined");
  4572. if (eleDeclined)
  4573. {
  4574. // Declined without comment, suggest to remove
  4575. elesRemove[i].setAttribute("title",
  4576. "Please remove this suggestion to save admin time.");
  4577. elesRemove[i].classList.add("stsh_green");
  4578. elesRemove[i].classList.add("stsh_border_green");
  4579. }
  4580. }
  4581. }
  4582. }
  4583. }
  4584. // Add remove & next
  4585. {
  4586. elesRemove[i].classList.add("stsh_border_left");
  4587. var eleNext = document.createElement("input");
  4588. eleNext.value = "Next";
  4589. eleNext.classList.add("stsh_action_remove_next");
  4590. eleNext.classList.add("stsh_border_right");
  4591. eleNext.setAttribute("type", "button");
  4592. if (canNext && !isDisabled)
  4593. {
  4594. eleNext.title = "Remove & Next";
  4595. var onclick = elesRemove[i].getAttribute("onclick")
  4596. .replace("';", "&ynext=true';");
  4597. eleNext.setAttribute("onclick", onclick);
  4598. eleNext.classList.add("stsh_yellow_light");
  4599. }
  4600. else
  4601. {
  4602. eleNext.disabled = true;
  4603. }
  4604. insertAfterElement(eleNext, elesRemove[i]);
  4605. }
  4606. }
  4607. }
  4608. // Suggest to decline outdated
  4609. {
  4610. if (document.querySelector(".stsh_action_approve"))
  4611. {
  4612. var elesAttention = document.querySelectorAll(".stsh_text_comment > font > i > b");
  4613. for (var i = 0; i < elesAttention.length; i++)
  4614. {
  4615. if (elesAttention[i].textContent.trim()
  4616. === "ATTENTION - English string was updated. This suggestion might be outdated.")
  4617. {
  4618. var eleAction = elesAttention[i]
  4619. .parentElement.parentElement
  4620. .parentElement.parentElement
  4621. .nextElementSibling;
  4622. var eleApprove = eleAction.querySelector(".stsh_action_approve");
  4623. var eleApproveNext = null;
  4624. var eleDecline = null;
  4625. if (eleApprove)
  4626. {
  4627. eleApproveNext = eleApprove.nextElementSibling;
  4628. var oldClick = eleApprove.getAttribute("onclick");
  4629. if (oldClick && oldClick.indexOf("location.href") === 0)
  4630. {
  4631. var newClick = "if (!confirm(\"Warning: Please decline outdated suggestion."
  4632. + " Press OK if you really want to approve.\")) return false; "
  4633. + oldClick;
  4634. eleApprove.setAttribute("onclick", newClick);
  4635. eleApprove.setAttribute("title", "Please decline outdated suggestion.");
  4636. eleApprove.classList.add("stsh_grey");
  4637. eleApprove.classList.add("stsh_cursor_notallowed");
  4638. }
  4639. }
  4640. if (eleApproveNext)
  4641. {
  4642. eleDecline = eleApproveNext.nextElementSibling;
  4643. if (!eleApproveNext.disabled)
  4644. {
  4645. var oldClick = eleApproveNext.getAttribute("onclick");
  4646. if (oldClick && oldClick.indexOf("location.href") === 0)
  4647. {
  4648. var newClick = "if (!confirm(\"Warning: Please decline outdated suggestion."
  4649. + " Press OK if you really want to approve.\")) return false; "
  4650. + oldClick;
  4651. eleApproveNext.setAttribute("onclick", newClick);
  4652. eleApproveNext.setAttribute("title", "Please decline outdated suggestion.");
  4653. eleApproveNext.classList.add("stsh_grey");
  4654. eleApproveNext.classList.add("stsh_cursor_notallowed");
  4655. }
  4656. }
  4657. }
  4658. if (eleDecline)
  4659. {
  4660. eleDecline.setAttribute("title", "Please decline outdated suggestion.");
  4661. eleDecline.classList.add("stsh_green");
  4662. eleDecline.classList.add("stsh_border_green_left");
  4663. }
  4664. }
  4665. }
  4666. }
  4667. }
  4668. // Clean language markers that link to Steam
  4669. {
  4670. var rgxLang = /[\?&]l=[a-z]+$/i;
  4671. var elesDiscussText = document.querySelectorAll(".stsh_discussion_text");
  4672. for (var i = 0; i < elesDiscussText.length; i++)
  4673. {
  4674. var elesA = elesDiscussText[i].querySelectorAll("a[href*='steam']");
  4675. for (var j = 0; j < elesA.length; j++)
  4676. {
  4677. var href = elesA[j].getAttribute("href");
  4678. if (rgxLang.test(href))
  4679. {
  4680. elesA[j].setAttribute("href", href.replace(rgxLang, ""));
  4681. }
  4682. }
  4683. }
  4684. }
  4685. // Auto paste last suggestion
  4686. {
  4687. if (!/edit/i.test(getQueryByName("action")))
  4688. {
  4689. if (eleTextOrg)
  4690. {
  4691. var textOrg = eleTextOrg.dataset.stshHtml.toLowerCase();
  4692. if (textOrg === GM_getValue("textLastOrg", ""))
  4693. {
  4694. var eleTextCur = document.querySelector("#suggestion_value_new");
  4695. if (eleTextCur)
  4696. {
  4697. var textLastCur = GM_getValue("textLastCur", "");
  4698. if (textLastCur !== "")
  4699. {
  4700. eleTextCur.value = textLastCur;
  4701. }
  4702. }
  4703. setTimeoutCustom(function()
  4704. {
  4705. var eleTextCur = document.querySelector("#suggestion_value_new");
  4706. if (eleTextCur)
  4707. {
  4708. var textLastCur = GM_getValue("textLastCur", "");
  4709. if (textLastCur !== "")
  4710. {
  4711. eleTextCur.value = textLastCur;
  4712. }
  4713. }
  4714. }, timingInit.pasteLastSuggestion);
  4715. }
  4716. }
  4717. }
  4718. var elesTextSubmit = document.querySelectorAll(".stsh_text_submit, #stsh_text_submit_next");
  4719. for (var i = 0; i < elesTextSubmit.length; i++)
  4720. {
  4721. elesTextSubmit[i].addEventListener("click", function()
  4722. {
  4723. var eleTextOrg = document.querySelector(".stsh_text_org");
  4724. if (eleTextOrg)
  4725. {
  4726. var textOrg = eleTextOrg.dataset.stshHtml;
  4727. if (textOrg.length < 3000)
  4728. {
  4729. var eleTextCur = document.querySelector("#suggestion_value_new");
  4730. if (eleTextCur)
  4731. {
  4732. var textCur = eleTextCur.value;
  4733. GM_setValue("textLastOrg", textOrg.toLowerCase());
  4734. GM_setValue("textLastCur", textCur);
  4735. //console.log("Store suggestion: " + textOrg.length);
  4736. }
  4737. }
  4738. }
  4739. });
  4740. }
  4741. }
  4742. // Auto store last comment
  4743. {
  4744. //console.log("textLastOrg_Comment: " + GM_getValue("textLastOrg_Comment", ""));
  4745. //console.log("textLastCur_Comment: " + GM_getValue("textLastCur_Comment", ""));
  4746. var storeLastComment = function(eleTextComment, isRemoved)
  4747. {
  4748. if (eleTextComment)
  4749. {
  4750. var eleTextOrg = document.querySelector(".stsh_text_org");
  4751. if (eleTextOrg)
  4752. {
  4753. var textOrg = eleTextOrg.dataset.stshHtml.substr(0, 3000).toLowerCase();
  4754. if (isRemoved)
  4755. {
  4756. if (textOrg === GM_getValue("textLastOrg_Comment", ""))
  4757. {
  4758. // When remove comment, don't store if original text is the same
  4759. return;
  4760. }
  4761. }
  4762. var textCur = trimSpace(eleTextComment.value || eleTextComment.textContent);
  4763. if (textCur !== "outdated")
  4764. {
  4765. GM_setValue("textLastOrg_Comment", textOrg);
  4766. GM_setValue("textLastCur_Comment", textCur);
  4767. }
  4768. }
  4769. }
  4770. }
  4771. for (var i = 0; i < elesTextRemoveComment.length; i++)
  4772. {
  4773. elesTextRemoveComment[i].addEventListener("click", function(ev)
  4774. {
  4775. var target = null;
  4776. if (ev.target.tagName === "FONT")
  4777. {
  4778. target = ev.target.parentElement;
  4779. }
  4780. else
  4781. {
  4782. target = ev.target;
  4783. }
  4784. var eleTextComment = target
  4785. .parentElement.parentElement.parentElement.parentElement
  4786. .querySelector(".stsh_text_comment");
  4787. storeLastComment(eleTextComment, true);
  4788. });
  4789. }
  4790. var elesSubmitComment = document.querySelectorAll(".stsh_submit_comment");
  4791. for (var i = 0; i < elesSubmitComment.length; i++)
  4792. {
  4793. elesSubmitComment[i].addEventListener("click", function(ev)
  4794. {
  4795. var eleTextComment = ev.target.previousElementSibling;
  4796. if (eleTextComment.tagName !== "TEXTAREA")
  4797. {
  4798. eleTextComment = eleTextComment.previousElementSibling;
  4799. }
  4800. storeLastComment(eleTextComment, false);
  4801. });
  4802. }
  4803. }
  4804. // Mark showing
  4805. {
  4806. var eleStatus = window.parent.document.querySelector("#stsh_showing_random");
  4807. if (eleStatus)
  4808. {
  4809. eleStatus.dataset.random = getTimeMs();
  4810. }
  4811. }
  4812. // Delta
  4813. {
  4814. var eleFile = document.querySelector(".stsh_info_file");
  4815. if (eleFile)
  4816. {
  4817. if (eleFile.textContent.trim() === "STEAM/DELTA")
  4818. {
  4819. document.body && document.body.classList.add("stsh_delta");
  4820. }
  4821. }
  4822. }
  4823. // Hide cursor when typing
  4824. // Expand textarea when typing
  4825. {
  4826. var tmTextChange = 0;
  4827. var autoHideCursor = function(ele)
  4828. {
  4829. if (ele)
  4830. {
  4831. ele.addEventListener("input", function(ev)
  4832. {
  4833. var ele = ev.target;
  4834. ele.style.setProperty("cursor", "none", "important");
  4835. clearTimeout(tmTextChange);
  4836. tmTextChange = setTimeoutCustom(function(ele)
  4837. {
  4838. ele.style.setProperty("cursor", "auto", "important");
  4839. }, timingInit.hideCursor, ele);
  4840. });
  4841. ele.addEventListener("mousemove", function(ev)
  4842. {
  4843. var ele = ev.target;
  4844. clearTimeout(tmTextChange);
  4845. ele.style.setProperty("cursor", "auto", "important");
  4846. });
  4847. }
  4848. }
  4849. var autoExpandEvent = function(ev)
  4850. {
  4851. var ele = ev.target;
  4852. var maxHeight = ele.param_MaxHeight;
  4853. var styleHeight = parseInt(ele.style.height)
  4854. || parseInt(window.getComputedStyle(ele).height)
  4855. || maxHeight;
  4856. var heightDiff = ele.scrollHeight - styleHeight;
  4857. //console.log("ele.scrollHeight:"+ele.scrollHeight+", styleHeight:"+styleHeight+", heightDiff:"+heightDiff);
  4858. // When press a button
  4859. // Chrome: heightDiff === 4
  4860. // Firefox: heightDiff === 0
  4861. if ((heightDiff > 0 && heightDiff !== 4) && ele.scrollHeight < maxHeight)
  4862. {
  4863. ele.style.height = (ele.scrollHeight + 2) + "px";
  4864. }
  4865. else if (ele.scrollHeight > maxHeight && ele.scrollHeight - maxHeight < 100)
  4866. {
  4867. ele.style.height = maxHeight + "px";
  4868. }
  4869. }
  4870. var autoExpandEventTextarea = function(ele, maxHeight)
  4871. {
  4872. if (ele)
  4873. {
  4874. ele.param_MaxHeight = maxHeight;
  4875. ele.addEventListener("input", autoExpandEvent);
  4876. ele.addEventListener("keyup", autoExpandEvent);
  4877. }
  4878. }
  4879. setTimeoutCustom(function()
  4880. {
  4881. var elesTextarea = document.querySelectorAll("textarea");
  4882. for (var i = 0; i < elesTextarea.length; i++)
  4883. {
  4884. autoExpandEventTextarea(elesTextarea[i], 500);
  4885. autoHideCursor(elesTextarea[i]);
  4886. }
  4887. }, timingInit.expandTextarea);
  4888. }
  4889. // Focus on mod action
  4890. {
  4891. var elesFormRemoveComment = document.querySelectorAll(".suggestion_signature .lbAction[name^='mymodcomment']");
  4892. for (var i = 0; i < elesFormRemoveComment.length; i++)
  4893. {
  4894. var action = elesFormRemoveComment[i].getAttribute("action");
  4895. if (action.indexOf("#stsh_modcomment") < 0)
  4896. {
  4897. elesFormRemoveComment[i].setAttribute("action", action + "#stsh_modcomment");
  4898. }
  4899. }
  4900. var elesSubmitComment = document.querySelectorAll(
  4901. ".suggestion_signature > div > div > .copy > form > div > .stsh_submit_comment");
  4902. for (var i = 0; i < elesSubmitComment.length; i++)
  4903. {
  4904. var eleForm = elesSubmitComment[i].parentElement.parentElement;
  4905. if (eleForm.tagName === "FORM")
  4906. {
  4907. var action = eleForm.getAttribute("action");
  4908. if (action.indexOf("#stsh_modcomment") < 0)
  4909. {
  4910. eleForm.setAttribute("action", action + "#stsh_modcomment");
  4911. }
  4912. }
  4913. }
  4914. if (/reconsider|approve|decline/i.test(getQueryByName("action")) || url.indexOf("#stsh_modcomment") > -1)
  4915. {
  4916. setTimeoutCustom(function()
  4917. {
  4918. if (eleTextNew && eleTextOrg)
  4919. {
  4920. if (eleTextNew.scrollHeight > 480 || eleTextOrg.scrollHeight > 480)
  4921. {
  4922. scrollToElement(".suggestions_list", -40);
  4923. }
  4924. else if (eleTextNew.scrollHeight > 110 || eleTextOrg.scrollHeight > 200)
  4925. {
  4926. var elesEdit = document.querySelectorAll(".stsh_action_edit");
  4927. if (elesEdit.length > 1)
  4928. {
  4929. scrollToElement(".suggestions_list", -40);
  4930. }
  4931. }
  4932. }
  4933. }, timingInit.focusModAction);
  4934. }
  4935. }
  4936. // Add char, word and byte count
  4937. {
  4938. var countCharWordByte = function(ele)
  4939. {
  4940. var countChar = 0;
  4941. var countWord = 0;
  4942. var countByte = 0;
  4943. if (ele)
  4944. {
  4945. var text = ele.value || (ele.value === "" ? "" : ele.textContent);
  4946. countChar = text.length;
  4947. var arrWord = trimSpace(text).split(/\s+/);
  4948. if (arrWord.length === 1)
  4949. {
  4950. if (trimSpace(arrWord[0]).length > 0)
  4951. {
  4952. countWord = 1;
  4953. }
  4954. }
  4955. else
  4956. {
  4957. countWord = arrWord.length;
  4958. }
  4959. countByte = getByteCount(text);
  4960. }
  4961. return "Char: " + countChar + " :: Word: " + countWord + " :: Byte: " + countByte;
  4962. }
  4963. var elesText = document.querySelectorAll("#suggestion_value_new, .stsh_text_addComment, #add_to_discussion");
  4964. for (var i = 0; i < elesText.length; i++)
  4965. {
  4966. var eleCounter = document.createElement("div");
  4967. eleCounter.classList.add("stsh_counter");
  4968. eleCounter.classList.add("stsh_blue_light");
  4969. eleCounter.classList.add("stsh_cursor_help");
  4970. eleCounter.dataset.counter = countCharWordByte(elesText[i]);
  4971. eleCounter.title = "Chars and words are approximate values. "
  4972. + "\nYou should add a comment or a discussion using less than 1020 bytes.";
  4973. insertAfterElement(eleCounter, elesText[i]);
  4974. elesText[i].addEventListener("input", function(ev)
  4975. {
  4976. var eleTarget = ev.target;
  4977. var eleCounter = eleTarget.nextElementSibling;
  4978. if (eleCounter && eleCounter.classList.contains("stsh_counter"))
  4979. {
  4980. eleCounter.dataset.counter = countCharWordByte(eleTarget);
  4981. }
  4982. });
  4983. }
  4984. /*elesText = document.querySelectorAll(".stsh_text_org, .stsh_text_trn:not(.stsh_text_trn_empty), .suggestion_text");
  4985. for (var i = 0; i < elesText.length; i++)
  4986. {
  4987. ////
  4988. }*/
  4989. }
  4990. // Warn before closing frame
  4991. {
  4992. if (window !== window.parent)
  4993. {
  4994. var eleOuter = window.parent.document.querySelector("#suggestions_box_outer");
  4995. if (eleOuter)
  4996. {
  4997. eleOuter.dataset.stshTextEdited = "false";
  4998. eleOuter.title = "";
  4999. var markEdited = function(ev)
  5000. {
  5001. if (!ev.ctrlKey && !ev.altKey)
  5002. {
  5003. if (eleOuter && eleOuter.dataset)
  5004. {
  5005. eleOuter.dataset.stshTextEdited = "true";
  5006. eleOuter.title = "When some texts were edited. \nYou must double click to close suggestion box.";
  5007. removeEventsMarkEdited();
  5008. }
  5009. }
  5010. };
  5011. var removeEventsMarkEdited = function()
  5012. {
  5013. var elesText = document.querySelectorAll("#suggestion_value_new, .stsh_text_addComment, #add_to_discussion");
  5014. for (var i = 0; i < elesText.length; i++)
  5015. {
  5016. elesText[i].removeEventListener("keydown", markEdited);
  5017. }
  5018. };
  5019. var elesText = document.querySelectorAll("#suggestion_value_new, .stsh_text_addComment, #add_to_discussion");
  5020. for (var i = 0; i < elesText.length; i++)
  5021. {
  5022. elesText[i].addEventListener("keydown", markEdited);
  5023. }
  5024. }
  5025. }
  5026. }
  5027. // Open auto replace form when applied
  5028. {
  5029. var eleStatus = document.querySelector("#replacementstatus");
  5030. if (eleStatus)
  5031. {
  5032. var eleAutoCopy = document.querySelector("#autocopy");
  5033. if (eleAutoCopy)
  5034. {
  5035. eleAutoCopy.style.display = "";
  5036. }
  5037. }
  5038. }
  5039. // Add auto-replacement for suggestion box
  5040. {
  5041. var eleAutoCopy = document.querySelector("#autocopy");
  5042. if (eleAutoCopy)
  5043. {
  5044. var eleBlock = null;
  5045. var eleHeader = null;
  5046. var eleForm = null;
  5047. var eleInstruction = null;
  5048. var eleMarker = null;
  5049. var eleDefine = null;
  5050. var eleMore = null;
  5051. var eleEnabled = null;
  5052. var eleEnabledLabel = null;
  5053. var eleEnabledContent = null;
  5054. var eleCase = null;
  5055. var eleCaseLabel = null;
  5056. var eleCaseContent = null;
  5057. var eleRgx = null;
  5058. var eleRgxLabel = null;
  5059. var eleRgxContent = null;
  5060. var addAutoReplaceText = function(eleMarker, textOrg, textDef)
  5061. {
  5062. textOrg = (typeof textOrg !== "undefined") ? textOrg : "";
  5063. textDef = (typeof textDef !== "undefined") ? textDef : "";
  5064. if (eleMarker)
  5065. {
  5066. var eleTextOrg = document.createElement("textarea");
  5067. eleTextOrg.classList.add("stsh_autoReplace_text");
  5068. eleTextOrg.classList.add("stsh_autoReplace_text_org");
  5069. eleTextOrg.setAttribute("rows", "1");
  5070. eleTextOrg.setAttribute("placeholder", "Your language or english text to be autoreplaced");
  5071. eleTextOrg.value = textOrg;
  5072. var eleTextDef = document.createElement("textarea");
  5073. eleTextDef.classList.add("stsh_autoReplace_text");
  5074. eleTextDef.classList.add("stsh_autoReplace_text_def");
  5075. eleTextDef.setAttribute("rows", "1");
  5076. eleTextDef.setAttribute("placeholder", "Translation");
  5077. eleTextDef.value = textDef;
  5078. insertBeforeElement(eleTextOrg, eleMarker);
  5079. insertBeforeElement(document.createTextNode(" "), eleMarker);
  5080. insertBeforeElement(eleTextDef, eleMarker);
  5081. insertBeforeElement(document.createElement("br"), eleMarker);
  5082. }
  5083. }
  5084. // Add elements
  5085. {
  5086. eleBlock = document.createElement("div");
  5087. eleBlock.classList.add("stsh_autoReplace_block");
  5088. insertAfterElement(eleBlock, eleAutoCopy);
  5089. eleHeader = document.createElement("div");
  5090. eleHeader.classList.add("stsh_autoReplace_header");
  5091. eleHeader.classList.add("stsh_green");
  5092. eleHeader.classList.add("stsh_cursor_pointer");
  5093. eleHeader.textContent = "AUTO-REPLACEMENT FOR SUGGESTION BOX";
  5094. eleHeader.setAttribute("onclick", "$('.stsh_autoReplace_form').toggle('blind', 300);");
  5095. eleBlock.appendChild(document.createElement("br"));
  5096. eleBlock.appendChild(eleHeader);
  5097. eleForm = document.createElement("form");
  5098. eleForm.classList.add("stsh_form");
  5099. eleForm.classList.add("stsh_autoReplace_form");
  5100. eleForm.style.display = "none";
  5101. eleBlock.appendChild(eleForm);
  5102. eleInstruction = document.createElement("div");
  5103. eleInstruction.classList.add("stsh_autoReplace_instruction");
  5104. eleInstruction.innerHTML =
  5105. " \
  5106. Auto-replacements for current text in suggestion box. These will replace anything in your current text in suggestion box. \
  5107. <br> You can use these to replace translated strings that you need to correct them. \
  5108. These will be processed after other replacements applied. \
  5109. <br> You can enable/disable replacements, case-sensitive mode and RegExp mode by using checkboxes below. \
  5110. ";
  5111. eleForm.appendChild(eleInstruction);
  5112. eleForm.appendChild(document.createElement("br"));
  5113. eleMarker = document.createElement("div");
  5114. eleMarker.classList.add("stsh_autoReplace_marker");
  5115. eleForm.appendChild(eleMarker);
  5116. eleDefine = document.createElement("input");
  5117. eleDefine.classList.add("stsh_autoReplace_define");
  5118. eleDefine.setAttribute("onclick", "return false;");
  5119. eleDefine.type = "submit";
  5120. eleDefine.value = "Define";
  5121. eleDefine.title = "Define auto-replacements and refresh this page";
  5122. eleMore = document.createElement("input");
  5123. eleMore.classList.add("stsh_autoReplace_more");
  5124. eleMore.setAttribute("onclick", "return false;");
  5125. eleMore.type = "button";
  5126. eleMore.value = "Add More";
  5127. eleMore.title = "Add a new auto-replacement";
  5128. // Checkbox enabled
  5129. {
  5130. eleEnabled = document.createElement("input");
  5131. eleEnabled.classList.add("stsh_autoReplace_enabled");
  5132. eleEnabled.setAttribute("type", "checkbox");
  5133. eleEnabled.setAttribute("value", "true");
  5134. eleEnabledLabel = document.createElement("label");
  5135. eleEnabledLabel.classList.add("stsh_checkbox_label");
  5136. eleEnabledLabel.classList.add("stsh_autoReplace_enabled_label");
  5137. eleEnabledLabel.classList.add("stsh_unselectable");
  5138. eleEnabledLabel.classList.add("stsh_cursor_pointer");
  5139. eleEnabledContent = document.createElement("span");
  5140. eleEnabledContent.textContent = " Enable Auto-replacements";
  5141. eleEnabledLabel.appendChild(eleEnabled);
  5142. eleEnabledLabel.appendChild(eleEnabledContent);
  5143. }
  5144. // Checkbox case
  5145. {
  5146. eleCase = document.createElement("input");
  5147. eleCase.classList.add("stsh_autoReplace_case");
  5148. eleCase.setAttribute("type", "checkbox");
  5149. eleCase.setAttribute("value", "true");
  5150. eleCaseLabel = document.createElement("label");
  5151. eleCaseLabel.classList.add("stsh_checkbox_label");
  5152. eleCaseLabel.classList.add("stsh_autoReplace_case_label");
  5153. eleCaseLabel.classList.add("stsh_unselectable");
  5154. eleCaseLabel.classList.add("stsh_cursor_pointer");
  5155. eleCaseContent = document.createElement("span");
  5156. eleCaseContent.textContent = " Case-sensitive";
  5157. eleCaseLabel.appendChild(eleCase);
  5158. eleCaseLabel.appendChild(eleCaseContent);
  5159. }
  5160. // Checkbox regexp
  5161. {
  5162. eleRgx = document.createElement("input");
  5163. eleRgx.classList.add("stsh_autoReplace_rgx");
  5164. eleRgx.setAttribute("type", "checkbox");
  5165. eleRgx.setAttribute("value", "true");
  5166. eleRgxLabel = document.createElement("label");
  5167. eleRgxLabel.classList.add("stsh_checkbox_label");
  5168. eleRgxLabel.classList.add("stsh_autoReplace_rgx_label");
  5169. eleRgxLabel.classList.add("stsh_unselectable");
  5170. eleRgxLabel.classList.add("stsh_cursor_pointer");
  5171. eleRgxContent = document.createElement("span");
  5172. eleRgxContent.textContent = " Use RegExp";
  5173. eleRgxLabel.appendChild(eleRgx);
  5174. eleRgxLabel.appendChild(eleRgxContent);
  5175. }
  5176. eleForm.appendChild(document.createElement("br"));
  5177. eleForm.appendChild(eleDefine);
  5178. eleForm.appendChild(document.createTextNode(" "));
  5179. eleForm.appendChild(eleMore);
  5180. eleForm.appendChild(document.createTextNode(" "));
  5181. eleForm.appendChild(eleEnabledLabel);
  5182. eleForm.appendChild(document.createTextNode(" "));
  5183. eleForm.appendChild(eleCaseLabel);
  5184. eleForm.appendChild(document.createTextNode(" "));
  5185. eleForm.appendChild(eleRgxLabel);
  5186. eleForm.appendChild(document.createElement("br"));
  5187. eleForm.appendChild(document.createElement("br"));
  5188. } // Add elements
  5189. // Bind events
  5190. {
  5191. var defineAutoReplaceText = function()
  5192. {
  5193. var objText = {};
  5194. var elesTextOrg = document.querySelectorAll(".stsh_autoReplace_text_org");
  5195. for (var i = 0; i < elesTextOrg.length; i++)
  5196. {
  5197. var eleTextOrg = elesTextOrg[i];
  5198. var eleTextDef = eleTextOrg.nextElementSibling;
  5199. var textOrg = eleTextOrg.value;
  5200. var textDef = eleTextDef.value;
  5201. var index = "text" + i;
  5202. objText[index] = {};
  5203. objText[index].textOrg = textOrg;
  5204. objText[index].textDef = textDef;
  5205. }
  5206. GM_setValue("autoReplace_text", objText);
  5207. reload();
  5208. };
  5209. eleDefine.addEventListener("click", defineAutoReplaceText);
  5210. eleMore.addEventListener("click", function()
  5211. {
  5212. var eleMarker = document.querySelector(".stsh_autoReplace_marker");
  5213. addAutoReplaceText(eleMarker);
  5214. });
  5215. eleEnabled.addEventListener("click", function (ev)
  5216. {
  5217. var ele = ev.target;
  5218. GM_setValue("autoReplace_enabled", ele.checked ? "true" : "false");
  5219. });
  5220. eleCase.addEventListener("click", function (ev)
  5221. {
  5222. var ele = ev.target;
  5223. GM_setValue("autoReplace_case", ele.checked ? "true" : "false");
  5224. });
  5225. eleRgx.addEventListener("click", function (ev)
  5226. {
  5227. var ele = ev.target;
  5228. GM_setValue("autoReplace_rgx", ele.checked ? "true" : "false");
  5229. });
  5230. addKeyCtrlEnter(eleForm, eleDefine);
  5231. } // Bind events
  5232. // User defined value
  5233. {
  5234. var valEnabled = GM_getValue("autoReplace_enabled", 0);
  5235. if (valEnabled === "true")
  5236. {
  5237. eleEnabled.checked = true;
  5238. }
  5239. var valCase = GM_getValue("autoReplace_case", 0);
  5240. if (valCase === "true")
  5241. {
  5242. eleCase.checked = true;
  5243. }
  5244. var valRgx = GM_getValue("autoReplace_rgx", 0);
  5245. if (valRgx === "true")
  5246. {
  5247. eleRgx.checked = true;
  5248. }
  5249. var autoReplaceTextCount = 4;
  5250. var objText = GM_getValue("autoReplace_text", 0);
  5251. if (!objText)
  5252. {
  5253. objText = {};
  5254. }
  5255. else
  5256. {
  5257. for (var i = Object.keys(objText).length - 1; i > autoReplaceTextCount - 1; i--)
  5258. {
  5259. var index = "text" + i;
  5260. if (objText[index].textOrg !== "" || objText[index].textDef !== "")
  5261. {
  5262. autoReplaceTextCount = i + 1;
  5263. break;
  5264. }
  5265. }
  5266. // Auto replace text
  5267. if (valEnabled === "true")
  5268. {
  5269. var isTextReplaced = false;
  5270. if (document.referrer === document.documentURI)
  5271. {
  5272. isTextReplaced = true;
  5273. }
  5274. if (!isTextReplaced && getQueryByName("action"))
  5275. {
  5276. isTextReplaced = true;
  5277. }
  5278. if (!isTextReplaced)
  5279. {
  5280. var eleError = document.querySelector(".suggestion_error");
  5281. if (eleError && eleError.textContent.trim() !== "")
  5282. {
  5283. isTextReplaced = true;
  5284. }
  5285. }
  5286. if (!isTextReplaced)
  5287. {
  5288. var eleBtnResummit = document.querySelector(".stsh_text_submit[value^='RESUBMIT']");
  5289. if (eleBtnResummit)
  5290. {
  5291. isTextReplaced = true;
  5292. }
  5293. }
  5294. if (!isTextReplaced)
  5295. {
  5296. setTimeoutCustom(function(objText)
  5297. {
  5298. var isTextReplaced = false;
  5299. var isRgx = (GM_getValue("autoReplace_rgx") === "true");
  5300. var isCase = (GM_getValue("autoReplace_case") === "true");
  5301. var keysText = Object.keys(objText);
  5302. for (var i = 0; i < keysText.length; i++)
  5303. {
  5304. var textOrg = objText[keysText[i]].textOrg;
  5305. if (textOrg !== "")
  5306. {
  5307. var textDef = objText[keysText[i]].textDef;
  5308. var eleTextNew = document.querySelector("#suggestion_value_new");
  5309. if (eleTextNew)
  5310. {
  5311. var textOld = eleTextNew.value;
  5312. var textNew = "";
  5313. var rgxOrg = null;
  5314. var rgxFlag = isCase ? "g" : "ig";
  5315. if (isRgx)
  5316. {
  5317. rgxOrg = new RegExp(textOrg, rgxFlag);
  5318. }
  5319. else
  5320. {
  5321. rgxOrg = new RegExp(escapeRegExp(textOrg), rgxFlag);
  5322. }
  5323. textNew = textOld.replace(rgxOrg, textDef);
  5324. if (textOld !== textNew)
  5325. {
  5326. isTextReplaced = true;
  5327. eleTextNew.value = textNew;
  5328. }
  5329. }
  5330. }
  5331. }
  5332. if (isTextReplaced)
  5333. {
  5334. var eleForm = document.querySelector(".stsh_autoReplace_form");
  5335. if (eleForm)
  5336. {
  5337. eleForm.style.display = "";
  5338. }
  5339. if (eleTextSubmit)
  5340. {
  5341. var eleDiv = document.createElement("div");
  5342. eleDiv.classList.add("stsh_autoReplace_notice");
  5343. eleDiv.classList.add("stsh_orange_light3");
  5344. eleDiv.textContent = "Auto-replacement for suggestion applied!";
  5345. eleTextSubmit.parentElement.appendChild(eleDiv);
  5346. }
  5347. }
  5348. }, timingInit.autoReplaceText, objText);
  5349. }
  5350. }
  5351. }
  5352. for (var i = 0; i < autoReplaceTextCount; i++)
  5353. {
  5354. var textOrg = "";
  5355. var textDef = "";
  5356. var index = "text" + i;
  5357. if (typeof objText[index] !== "undefined")
  5358. {
  5359. textOrg = objText[index].textOrg;
  5360. textDef = objText[index].textDef;
  5361. }
  5362. addAutoReplaceText(eleMarker, textOrg, textDef);
  5363. }
  5364. // Add one more empty row
  5365. addAutoReplaceText(eleMarker);
  5366. } // User defined value
  5367. }
  5368. } // Add auto-replacement for suggestion box
  5369. // Add scroll to top
  5370. // Find next unmatched
  5371. {
  5372. var eleInvert = document.querySelector("input[value='Invert display']");
  5373. if (eleInvert)
  5374. {
  5375. eleInvert.value = "Invert Display";
  5376. // Add scroll to top
  5377. {
  5378. var eleScroll = document.createElement("input");
  5379. eleScroll.classList.add("stsh_scrollToTop");
  5380. eleScroll.setAttribute("onclick", "return false;");
  5381. eleScroll.type = "button";
  5382. eleScroll.value = "Scroll to Top";
  5383. eleScroll.addEventListener("click", function (ev)
  5384. {
  5385. window.scrollTo(0, 0);
  5386. });
  5387. var eleContainer = document.createElement("div");
  5388. eleContainer.classList.add("stsh_bottom_container");
  5389. eleContainer.classList.add("stsh_inline");
  5390. eleContainer.appendChild(document.createTextNode(" "));
  5391. eleContainer.appendChild(eleScroll);
  5392. insertAfterElement(eleContainer, eleInvert);
  5393. }
  5394. // Find next unmatched
  5395. // Sample: https://translation.steampowered.com/translate.php?paginationrows=1000&search_input=%01
  5396. {
  5397. var eleUnmatched = document.createElement("input");
  5398. eleUnmatched.classList.add("stsh_nextUnmatched");
  5399. eleUnmatched.setAttribute("type", "checkbox");
  5400. eleUnmatched.setAttribute("value", "true");
  5401. var eleUnmatchedLabel = document.createElement("label");
  5402. eleUnmatchedLabel.classList.add("stsh_checkbox_label");
  5403. eleUnmatchedLabel.classList.add("stsh_nextUnmatched_label");
  5404. eleUnmatchedLabel.classList.add("stsh_unselectable");
  5405. eleUnmatchedLabel.classList.add("stsh_cursor_pointer");
  5406. eleUnmatchedLabel.title =
  5407. "Find next unmatched for special chars, combining diacritical marks, \nand HTML elements count. "
  5408. + "\nClick any position to stop finding.";
  5409. var eleUnmatchedContent = document.createElement("span");
  5410. eleUnmatchedContent.classList.add("stsh_nextUnmatched_content");
  5411. eleUnmatchedContent.textContent = " Find Next Unmatched";
  5412. eleUnmatchedLabel.appendChild(eleUnmatched);
  5413. eleUnmatchedLabel.appendChild(eleUnmatchedContent);
  5414. eleContainer.appendChild(document.createTextNode(" "));
  5415. eleContainer.appendChild(eleUnmatchedLabel);
  5416. var findNextUnmatched = function(isInitial)
  5417. {
  5418. isInitial = isInitial || false;
  5419. console.log("FindNextUnmatched: In " + timingInit.findNextUnmatched + "ms");
  5420. setTimeoutCustom(function()
  5421. {
  5422. var eleUnmatched = document.querySelector(".stsh_nextUnmatched");
  5423. if (eleUnmatched && eleUnmatched.checked)
  5424. {
  5425. var isClicked = false;
  5426. var eleNext = document.querySelector(".stsh_nav_next:not(:disabled)");
  5427. if (eleNext)
  5428. {
  5429. if (!isInitial)
  5430. {
  5431. var eleStatusUnmatched = document.querySelector(".stsh_status_unmatched");
  5432. if (eleStatusUnmatched)
  5433. {
  5434. isClicked = false;
  5435. if (eleStatusUnmatched.classList.contains("stsh_spanStatusTrn"))
  5436. {
  5437. if (document.querySelector(".stsh_spanStatusSug.stsh_status_matched"))
  5438. {
  5439. isClicked = true;
  5440. }
  5441. }
  5442. }
  5443. else
  5444. {
  5445. isClicked = true;
  5446. }
  5447. }
  5448. else
  5449. {
  5450. isClicked = true;
  5451. }
  5452. }
  5453. if (!isClicked)
  5454. {
  5455. eleUnmatched.checked = false;
  5456. GM_setValue("nextUnmatched", "false");
  5457. }
  5458. else
  5459. {
  5460. GM_setValue("timeNextUnmatchedLast", getUnixTimestamp());
  5461. eleNext.click();
  5462. }
  5463. }
  5464. }, timingInit.findNextUnmatched);
  5465. }
  5466. var tmDiff = getUnixTimestamp() - GM_getValue("timeNextUnmatchedLast", 0);
  5467. if (tmDiff > 10)
  5468. {
  5469. // > 10s
  5470. eleUnmatched.checked = false;
  5471. GM_setValue("nextUnmatched", "false");
  5472. }
  5473. if (window !== window.parent)
  5474. {
  5475. var eleOuter = window.parent.document.querySelector("#suggestions_box_outer");
  5476. if (eleOuter)
  5477. {
  5478. if (eleOuter.style.display === "none")
  5479. {
  5480. // Closed iFrame
  5481. eleUnmatched.checked = false;
  5482. GM_setValue("nextUnmatched", "false");
  5483. }
  5484. }
  5485. }
  5486. if (GM_getValue("nextUnmatched", 0) === "true")
  5487. {
  5488. eleUnmatched.checked = true;
  5489. findNextUnmatched();
  5490. var uncheckFindNextUnmatched = function (ev)
  5491. {
  5492. var eleTarget = ev.target;
  5493. if (eleTarget.id !== "stsh_btn_displaySpecialChars"
  5494. && !eleTarget.classList.contains("stsh_nextUnmatched")
  5495. && !eleTarget.classList.contains("stsh_nextUnmatched_content")
  5496. && !eleTarget.classList.contains("stsh_nav_next"))
  5497. {
  5498. // Skip auto click
  5499. var eleUnmatched = document.querySelector(".stsh_nextUnmatched");
  5500. if (eleUnmatched)
  5501. {
  5502. console.log("FindNextUnmatched: Stop");
  5503. eleUnmatched.checked = false;
  5504. GM_setValue("nextUnmatched", "false");
  5505. document.removeEventListener("click", uncheckFindNextUnmatched);
  5506. }
  5507. }
  5508. };
  5509. // Stop finding with any clicked
  5510. document.addEventListener("click", uncheckFindNextUnmatched);
  5511. // Display specialChars
  5512. var eleSpecialChars = document.querySelector("#stsh_btn_displaySpecialChars");
  5513. if (eleSpecialChars)
  5514. {
  5515. eleSpecialChars.click();
  5516. }
  5517. }
  5518. eleUnmatched.addEventListener("click", function (ev)
  5519. {
  5520. var eleTarget = ev.target;
  5521. if (eleTarget.checked)
  5522. {
  5523. GM_setValue("nextUnmatched", "true");
  5524. findNextUnmatched(true);
  5525. }
  5526. else
  5527. {
  5528. GM_setValue("nextUnmatched", "false");
  5529. }
  5530. });
  5531. }
  5532. }
  5533. }
  5534. // Add copy button
  5535. {
  5536. if (eleTextSubmit)
  5537. {
  5538. var eleInput = document.createElement("input");
  5539. eleInput.classList.add("stsh_copy_new");
  5540. eleInput.type = "button";
  5541. eleInput.value = "Copy";
  5542. eleInput.title = "Copy current suggestion to clipboard";
  5543. insertAfterElement(eleInput, eleTextSubmit);
  5544. eleInput.addEventListener("click", function()
  5545. {
  5546. var eleTextNew = document.querySelector("#suggestion_value_new");
  5547. if (eleTextNew)
  5548. {
  5549. GM_setClipboard(eleTextNew.value);
  5550. focusWithoutScroll(eleTextNew);
  5551. }
  5552. });
  5553. }
  5554. var titleExtra = "\nSome tags and attributes were generated or removed by STS. "
  5555. + "\nSingle quote ' may be changed to double quote \" "
  5556. + "\n and double quote \" may be added for attribute values by browser. ";
  5557. var elesEdit = document.querySelectorAll(".stsh_action_edit");
  5558. for (var i = 0; i < elesEdit.length; i++)
  5559. {
  5560. var eleInput = document.createElement("input");
  5561. eleInput.classList.add("stsh_copy_sug");
  5562. eleInput.classList.add("stsh_blue_light");
  5563. eleInput.type = "button";
  5564. eleInput.value = "Copy";
  5565. eleInput.title = "Copy this suggestion to clipboard. " + titleExtra;
  5566. insertBeforeElement(eleInput, elesEdit[i]);
  5567. eleInput.addEventListener("click", function(ev)
  5568. {
  5569. var eleTarget = ev.target;
  5570. var eleSug = eleTarget.parentElement.parentElement
  5571. .parentElement.parentElement
  5572. .querySelector(".stsh_text_sug");
  5573. if (eleSug)
  5574. {
  5575. var html = removeStsHtmlTags(eleSug);
  5576. if (html)
  5577. {
  5578. GM_setClipboard(html);
  5579. focusWithoutScroll("#suggestion_value_new");
  5580. }
  5581. }
  5582. });
  5583. }
  5584. if (eleHeaderOrg)
  5585. {
  5586. var eleInput = document.createElement("input");
  5587. eleInput.classList.add("stsh_copy_org");
  5588. eleInput.type = "button";
  5589. eleInput.value = "Copy";
  5590. eleInput.title = "Copy original string to clipboard. " + titleExtra;
  5591. insertAfterElement(eleInput, eleHeaderOrg.firstElementChild);
  5592. eleInput.addEventListener("click", function(ev)
  5593. {
  5594. var eleTextOrg = document.querySelector(".stsh_text_org");
  5595. if (eleTextOrg)
  5596. {
  5597. var html = removeStsHtmlTags(eleTextOrg);
  5598. if (html)
  5599. {
  5600. GM_setClipboard(html);
  5601. focusWithoutScroll("#suggestion_value_new");
  5602. }
  5603. }
  5604. });
  5605. }
  5606. if (eleHeaderTrn && eleTextTrn && !eleTextTrn.classList.contains("stsh_text_trn_empty"))
  5607. {
  5608. var eleInput = document.createElement("input");
  5609. eleInput.classList.add("stsh_copy_trn");
  5610. eleInput.type = "button";
  5611. eleInput.value = "Copy";
  5612. eleInput.title = "Copy translated string to clipboard. " + titleExtra;
  5613. insertAfterElement(eleInput, eleHeaderTrn.firstElementChild);
  5614. eleInput.addEventListener("click", function(ev)
  5615. {
  5616. var eleTextTrn = document.querySelector(".stsh_text_trn:not(.stsh_text_trn_empty)");
  5617. if (eleTextTrn)
  5618. {
  5619. var html = removeStsHtmlTags(eleTextTrn);
  5620. if (html)
  5621. {
  5622. GM_setClipboard(html);
  5623. focusWithoutScroll("#suggestion_value_new");
  5624. }
  5625. }
  5626. });
  5627. }
  5628. }
  5629. // Add border to related action
  5630. {
  5631. if (userName)
  5632. {
  5633. var eleSugHistory = document.querySelector(".stsh_suggestion_list_history");
  5634. if (eleSugHistory)
  5635. {
  5636. var isRelated = false;
  5637. var strName = "by " + userName + " ";
  5638. for (var i = 0; i < eleSugHistory.childNodes.length; i++)
  5639. {
  5640. var node = eleSugHistory.childNodes[i];
  5641. if (node.nodeType === document.TEXT_NODE)
  5642. {
  5643. var index = (node.textContent + " ").indexOf(strName);
  5644. if (index > -1 && index < 12)
  5645. {
  5646. isRelated = true;
  5647. break;
  5648. }
  5649. }
  5650. }
  5651. if (isRelated)
  5652. {
  5653. eleSugHistory.classList.add("stsh_suggestion_list_history_related");
  5654. var eleDiv = document.createElement("div");
  5655. eleDiv.innerHTML = eleSugHistory.innerHTML
  5656. .replace(new RegExp("by (" + escapeRegExp(userName) + ")", "g")
  5657. , function(match, p1, offset, string)
  5658. {
  5659. return 'by <span class="stsh_profile_name stsh_blue_light2 stsh_cursor_help"'
  5660. + ' title="This string is related with your action.">'
  5661. + p1.replace(/\</g, "&lt;") + '</span>';
  5662. });
  5663. eleSugHistory.innerHTML = eleDiv.innerHTML;
  5664. }
  5665. }
  5666. }
  5667. }
  5668. } // End suggestions.php
  5669.  
  5670. if (url.indexOf("translate.php") > -1)
  5671. {
  5672. document.body && document.body.classList.add("stsh_page_translate");
  5673. var searchText = getQueryByName("search_input");
  5674. if (searchText !== "")
  5675. {
  5676. if (searchText.indexOf("SUGGESTIONS FROM: ") === 0)
  5677. {
  5678. document.title = searchText.replace("SUGGESTIONS FROM: ", "") + " - " + document.title;
  5679. }
  5680. else if (searchText.indexOf("REVIEWS FROM: ") === 0)
  5681. {
  5682. document.title = searchText.replace("REVIEW: ", "") + " - " + document.title;
  5683. }
  5684. else
  5685. {
  5686. document.title = searchText + " - " + document.title;
  5687. }
  5688. }
  5689. else
  5690. {
  5691. var fileID = getQueryByName("file_ID");
  5692. if (fileID !== "")
  5693. {
  5694. var eleFile = document.querySelector("#leftAreaContainer label[for='chosenfile']");
  5695. if (eleFile)
  5696. {
  5697. var file = eleFile.textContent.trim();
  5698. if (file.indexOf("Limit search results to CURRENT FILE: ") === 0)
  5699. {
  5700. file = file.replace("Limit search results to CURRENT FILE: ", "");
  5701. var fileNew = file.split("#").reverse().join(" # ").trim();
  5702. document.title = fileNew + " - " + document.title;
  5703. }
  5704. }
  5705. }
  5706. else
  5707. {
  5708. var eleInput = document.querySelector("#search_input");
  5709. if (eleInput)
  5710. {
  5711. var valInput = eleInput.value.trim();
  5712. if (valInput.indexOf("SUGGESTIONS FROM: ") === 0)
  5713. {
  5714. document.title = valInput.replace("SUGGESTIONS FROM: ", "") + " - " + document.title;
  5715. }
  5716. else if (valInput.indexOf("REVIEWS FROM: ") === 0)
  5717. {
  5718. document.title = valInput.replace("REVIEWS FROM: ", "REVIEW: ") + " - " + document.title;
  5719. }
  5720. else if (valInput === "---DAYLIGHT SAVINGS BATTLE---")
  5721. {
  5722. document.title = "DAYLIGHT SAVINGS BATTLE - " + document.title;
  5723. }
  5724. }
  5725. }
  5726. }
  5727. var outer = document.querySelector("#suggestions_box_outer");
  5728. if (outer)
  5729. {
  5730. outer.setAttribute("onclick", "doubleClickHideSuggestion(this);");
  5731. outer.dataset.stshHideSuggestion = 0;
  5732. outer.dataset.stshTextEdited = "false";
  5733. }
  5734. var divBtn = document.createElement("div");
  5735. document.body.appendChild(divBtn);
  5736. divBtn.innerHTML =
  5737. ' \
  5738. <div class="stsh_showing_group"> \
  5739. <span class="stsh_showing_header">Hide</span>\
  5740. <br> &nbsp; <input id="stsh_showing_keyApp" value="App" data-hidekey="0" class="stsh_btn_short stsh_showing_key" type="button" /> \
  5741. <input id="stsh_showing_keyGame" value="Game" data-hidekey="1" class="stsh_btn_short stsh_showing_key" type="button" /> \
  5742. <br> &nbsp; <input id="stsh_showing_keyFaq" value="FAQ" data-hidekey="2" class="stsh_btn_short stsh_showing_key" type="button" /> \
  5743. <input id="stsh_showing_keySupport" value="Support" data-hidekey="3" class="stsh_btn_short stsh_showing_key" type="button" /> \
  5744. <br> &nbsp; <input id="stsh_showing_keyPromo" value="Promo" data-hidekey="4" class="stsh_btn_short stsh_showing_key" type="button" /> \
  5745. <input id="stsh_showing_keyEmail" value="Email" data-hidekey="5" class="stsh_btn_short stsh_showing_key" type="button" /> \
  5746. <br> \
  5747. <br> &nbsp; <input id="stsh_showing_strNotMatch" value="Hide not similar" data-hidestr="0" class="stsh_btn_long stsh_showing_str" type="button" /> \
  5748. <br> &nbsp; <input id="stsh_showing_strLong" value="Hide very long" data-hidestr="1" class="stsh_btn_long stsh_showing_str" type="button" /> \
  5749. \
  5750. <br> &nbsp; <span class="stsh_showing_header">Hide Suggestions</span>\
  5751. <br> &nbsp; <input id="stsh_showing_notTranslated" value="Not Translated (0)" data-hidestatus="0" class="stsh_btn_long stsh_showing_status" type="button" /> \
  5752. <br> &nbsp; <input id="stsh_showing_suggested" value="Suggested (0)" data-hidestatus="1" class="stsh_btn_long stsh_showing_status" type="button" /> \
  5753. <br> &nbsp; <input id="stsh_showing_resuggested" value="Resuggested (0)" data-hidestatus="2" class="stsh_btn_long stsh_showing_status" type="button" /> \
  5754. <br> &nbsp; <input id="stsh_showing_approved" value="Approved (0)" data-hidestatus="3" class="stsh_btn_long stsh_showing_status" type="button" /> \
  5755. <br> &nbsp; <input id="stsh_showing_declined" value="Declined (0)" data-hidestatus="4" class="stsh_btn_long stsh_showing_status" type="button" /> \
  5756. <br> &nbsp; <input id="stsh_showing_translated" value="Translated (0)" data-hidestatus="5" class="stsh_btn_long stsh_showing_status" type="button" /> \
  5757. \
  5758. <br> &nbsp; <span class="stsh_showing_header">Sort by</span>\
  5759. <br> &nbsp; <input id="stsh_sort_key" value="Key" data-sort="0" class="stsh_btn_short stsh_sort" type="button" /> \
  5760. <input id="stsh_sort_string" value="String" data-sort="1" class="stsh_btn_short stsh_sort" type="button" /> \
  5761. <br> &nbsp; <input id="stsh_sort_word" value="Word" data-sort="2" class="stsh_btn_short stsh_sort" type="button" /> \
  5762. <input id="stsh_sort_length" value="Length" data-sort="3" class="stsh_btn_short stsh_sort" type="button" /> \
  5763. <br> \
  5764. <br> &nbsp; <input id="stsh_showing_refresh" value="Refresh" class="stsh_btn" type="button" onclick="hideSuggestionsBox(); return false;" /> \
  5765. <br> &nbsp; <input id="stsh_showing_all" value="Show All" class="stsh_btn" type="button" /> \
  5766. <br> \
  5767. </div> \
  5768. <div id="stsh_showing_current"></div> \
  5769. <div id="stsh_showing"></div> \
  5770. ';
  5771.  
  5772. // Count showing
  5773. var countShowing = function()
  5774. {
  5775. var trKeys = document.querySelectorAll("#keylist > table:nth-child(1) > tbody:nth-child(1) > tr");
  5776. var countAll = document.querySelectorAll("#keylist .copysmall").length;
  5777. var countShow = 0;
  5778. var countSuggest = 0;
  5779. var countResuggest = 0;
  5780. var countApprove = 0;
  5781. var countDecline = 0;
  5782. var countNotTranslated = 0;
  5783. var countTranslated = 0;
  5784. var txtApprove = "ready for Admin";
  5785. var txtDecline = "ready for removal";
  5786. var txtSuggest = "suggestion";
  5787. for (var i = 0; i < trKeys.length; i++)
  5788. {
  5789. if (!trKeys[i].classList.contains("stsh_hidden"))
  5790. {
  5791. var eleCounter = trKeys[i].querySelector("tr.copysmall > td:nth-child(3)");
  5792. if (eleCounter)
  5793. {
  5794. countShow++;
  5795. var txtCounter = eleCounter.textContent.trim();
  5796. if (txtCounter.indexOf(txtApprove) > -1)
  5797. {
  5798. countApprove++;
  5799. }
  5800. else if (txtCounter.indexOf(txtDecline) > -1)
  5801. {
  5802. countDecline++;
  5803. }
  5804. else if (txtCounter.indexOf(txtSuggest) > -1)
  5805. {
  5806. var eleNotTranslated = trKeys[i].querySelector("span.token_nottranslated");
  5807. if (eleNotTranslated)
  5808. {
  5809. countSuggest++;
  5810. }
  5811. else
  5812. {
  5813. countResuggest++;
  5814. }
  5815. }
  5816. else
  5817. {
  5818. var eleNotTranslated = trKeys[i].querySelector("span.token_nottranslated");
  5819. if (eleNotTranslated)
  5820. {
  5821. countNotTranslated++;
  5822. }
  5823. else
  5824. {
  5825. countTranslated++;
  5826. }
  5827. }
  5828. }
  5829. else
  5830. {
  5831. var eleTd = trKeys[i].querySelector("td");
  5832. if (eleTd)
  5833. {
  5834. if (eleTd.textContent.trim() === "")
  5835. {
  5836. removeElement(trKeys[i]);
  5837. }
  5838. }
  5839. }
  5840. }
  5841. }
  5842. var eleShowing = document.querySelector("#stsh_showing");
  5843. if (eleShowing)
  5844. {
  5845. var newHtml = "Showing: <span class=\"stsh_showing_counter\">" + countShow + " of " + countAll + "</span>"
  5846. + "<!-- " + countNotTranslated + ", " + countSuggest + ", " + countResuggest
  5847. + ", " + countApprove + ", " + countDecline + ", " + countTranslated + " -->";
  5848. if (eleShowing.innerHTML !== newHtml)
  5849. {
  5850. eleShowing.innerHTML = newHtml;
  5851.  
  5852. var elesBtnShowingStatus = document.querySelectorAll(".stsh_showing_status");
  5853. if (elesBtnShowingStatus.length === 6)
  5854. {
  5855. var counterArr = [countNotTranslated, countSuggest, countResuggest
  5856. , countApprove, countDecline, countTranslated ];
  5857. var counterTextArr = ["Not Translated", "Suggested", "Resuggested"
  5858. , "Approved", "Declined", "Translated" ];
  5859.  
  5860. for (var i = 0; i < elesBtnShowingStatus.length; i++)
  5861. {
  5862. elesBtnShowingStatus[i].value = counterTextArr[i] + " ("+ counterArr[i] +")" ;
  5863. };
  5864. }
  5865. }
  5866. }
  5867. var eleShowingCur = document.querySelector("#stsh_showing_current");
  5868. if (eleShowingCur)
  5869. {
  5870. var eleOuter = document.querySelector("#suggestions_box_outer");
  5871. if (eleOuter)
  5872. {
  5873. if (eleOuter.style.display !== "none")
  5874. {
  5875. if (eleShowingCur.style.display !== "initial")
  5876. eleShowingCur.style.display = "initial";
  5877. var eleIframe = document.querySelector("#suggestions_iframe");
  5878. if (eleIframe)
  5879. {
  5880. var iUrl = eleIframe.contentWindow.location.href;
  5881. var listId = parseInt(getQueryByName("list_id", iUrl)) || 0;
  5882. listId += 1;
  5883. var newHtml = "Current: <span class=\"stsh_showing_counter\">" + listId + " of " + countShow + "</span>";
  5884. if (eleShowingCur.innerHTML !== newHtml)
  5885. {
  5886. eleShowingCur.innerHTML = newHtml;
  5887. }
  5888. }
  5889. }
  5890. else
  5891. {
  5892. if (eleShowingCur.style.display !== "none")
  5893. {
  5894. eleShowingCur.style.display = "none";
  5895. eleShowingCur.innerHTML = "";
  5896. }
  5897. }
  5898. }
  5899. }
  5900. };
  5901. countShowing();
  5902. // Waiting for iframe
  5903. {
  5904. var obTarget_countRand = document.createElement("div");
  5905. obTarget_countRand.id = "stsh_showing_random";
  5906. obTarget_countRand.dataset.random = "0";
  5907. document.body.appendChild(obTarget_countRand);
  5908. var obMu_countRand = new MutationObserver(function(mutations)
  5909. {
  5910. mutations.forEach(function(mutation)
  5911. {
  5912. countShowing();
  5913. });
  5914. });
  5915.  
  5916. var obConfig_countRand = { attributes: true, attributeFilter: ["data-random"] };
  5917. obMu_countRand.observe(obTarget_countRand, obConfig_countRand);
  5918. }
  5919. // End Count showing
  5920.  
  5921. // Line Counter
  5922. var addLineCounter = function()
  5923. {
  5924. var elesCounter = document.querySelectorAll(".stsh_lineCounter");
  5925. if (elesCounter.length > 0)
  5926. {
  5927. var j = 1;
  5928. for (var i = 0; i < elesCounter.length; i++)
  5929. {
  5930. if (!elesCounter[i].parentElement.parentElement.parentElement
  5931. .parentElement.classList.contains("stsh_hidden"))
  5932. {
  5933. if (elesCounter[i].textContent.trim() != j)
  5934. {
  5935. // Compare string with int using loose equality
  5936. elesCounter[i].textContent = j;
  5937. }
  5938. j++;
  5939. }
  5940. }
  5941. }
  5942. else
  5943. {
  5944. var elesDiv = document.querySelectorAll("#keylist td:nth-child(1) > div");
  5945. for (var i = 0; i < elesDiv.length; i++)
  5946. {
  5947. var eleNew = document.createElement("span");
  5948. eleNew.classList.add("stsh_lineCounter_outer");
  5949. eleNew.innerHTML =
  5950. ' <span class="stsh_lineCounter"> ' + (i + 1) + ' </span> ';
  5951. elesDiv[i].appendChild(eleNew);
  5952. }
  5953. }
  5954. };
  5955. addLineCounter();
  5956. // End Line Counter
  5957. // Hide & sort suggestions
  5958. {
  5959. var hideStatus = function(mode)
  5960. {
  5961. /*
  5962. mode:
  5963. 0: notTranslated
  5964. 1: suggested
  5965. 2: resuggested
  5966. 3: approved
  5967. 4: declined
  5968. 5: translated
  5969. */
  5970.  
  5971. //console.log("hideStatus: " + mode);
  5972. if (mode < 0 || mode > 5) return;
  5973.  
  5974. var display = "none";
  5975. var txtApprove = "ready for Admin";
  5976. var txtDecline = "ready for removal";
  5977. var txtSuggest = "suggestion";
  5978. var trKeys = document.querySelectorAll("#keylist > table:nth-child(1) > tbody:nth-child(1) > tr");
  5979. for (var i = 0; i < trKeys.length; i++)
  5980. {
  5981. if (!trKeys[i].classList.contains("stsh_hidden"))
  5982. {
  5983. var curMode = -1;
  5984.  
  5985. var eleCounter = trKeys[i].querySelector("tr.copysmall > td:nth-child(3)");
  5986. if (eleCounter)
  5987. {
  5988.  
  5989. var txtCounter = eleCounter.textContent.trim();
  5990. if (txtCounter.indexOf(txtApprove) > -1)
  5991. {
  5992. curMode = 3; // Approved
  5993. }
  5994. else if (txtCounter.indexOf(txtDecline) > -1)
  5995. {
  5996. curMode = 4; // Declined
  5997. }
  5998. else if (txtCounter.indexOf(txtSuggest) > -1)
  5999. {
  6000. var eleNotTranslated = trKeys[i].querySelector("span.token_nottranslated");
  6001. if (eleNotTranslated)
  6002. {
  6003. curMode = 1; // Suggested
  6004. }
  6005. else
  6006. {
  6007. curMode = 2; // Resuggested
  6008. }
  6009. }
  6010. else
  6011. {
  6012. var eleNotTranslated = trKeys[i].querySelector("span.token_nottranslated");
  6013. if (eleNotTranslated)
  6014. {
  6015. curMode = 0; // Not Translated
  6016. }
  6017. else
  6018. {
  6019. curMode = 5; // Translated
  6020. }
  6021. }
  6022. }
  6023.  
  6024. if (curMode === mode)
  6025. {
  6026. trKeys[i].classList.add("stsh_hidden");
  6027. }
  6028. }
  6029. }
  6030. }
  6031. var sortKey = function(mode)
  6032. {
  6033. /*
  6034. mode:
  6035. 0: key
  6036. 1: string
  6037. 2: word
  6038. 3: length
  6039. */
  6040. if (mode < 0) return;
  6041. var keyArr = [];
  6042. var valArr = [];
  6043. var dot = "...";
  6044. var dotLengthMinus = 0 - dot.length;
  6045. var strNotTranslated = "NOT TRANSLATED";
  6046. var strTr = "";
  6047. var rgxAlphabet = /[a-z0-9]/i;
  6048. var eleKeys = document.querySelectorAll
  6049. (" \
  6050. #keylist > table:nth-child(1) \
  6051. > tbody:nth-child(1) > tr > td:nth-child(1) > div:nth-child(1) \
  6052. > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(1) \
  6053. ");
  6054. for (var i = 0; i < eleKeys.length; i++)
  6055. {
  6056. try
  6057. {
  6058. /*
  6059. key:
  6060. tr: is translated
  6061. sg: is suggested
  6062. dt: has dot
  6063. sb: spacebar count
  6064. sc: special char count
  6065. sp: has special char
  6066. ln: length
  6067. lt: length translated
  6068. st: spacebar count translated
  6069. */
  6070. var dot = "...";
  6071. var dotLengthMinus = 0 - dot.length;
  6072. var isDot = false;
  6073. var isSuggested = false;
  6074. var isTranslated = false;
  6075. var key = eleKeys[i].textContent.trim() + " ";
  6076. var str = "";
  6077. if (mode !== 0)
  6078. {
  6079. str = eleKeys[i].parentElement.nextSibling.nextSibling.firstElementChild.textContent.trim();
  6080. isDot = (str.substr(dotLengthMinus) === dot);
  6081. isSuggested = (eleKeys[i].nextElementSibling.nextElementSibling.textContent.trim() !== "");
  6082. strTr = eleKeys[i].parentElement.nextElementSibling.lastElementChild.textContent.trim();
  6083. isTranslated = (strTr !== strNotTranslated);
  6084. }
  6085. if (mode === 0)
  6086. {
  6087. // mode: key
  6088. if (key.indexOf("GLOSSARY") === 0)
  6089. {
  6090. key = "0" + key;
  6091. }
  6092. }
  6093. if (mode === 1)
  6094. {
  6095. // mode: string
  6096. key = (isTranslated ? "tr00_ " : "tr99_ ") + strTr
  6097. + (isSuggested ? " _sg00" : " _sg99") + " ___ " + key;
  6098. if (str.length > 0 && !rgxAlphabet.test(str[0]))
  6099. {
  6100. key = "zzzzz" + str + " ___ " + key;
  6101. }
  6102. else
  6103. {
  6104. key = str + " ___ " + key;
  6105. }
  6106. }
  6107. else if (mode === 2)
  6108. {
  6109. // mode: word
  6110. key = (isTranslated ? "tr00_" : "tr99_")
  6111. + "st" + padZero(strTr.split(" ").length, 2) + "_"
  6112. + "lt" + padZero(strTr.length, 3) + " "
  6113. + strTr + (isSuggested ? " _sg00" : " _sg99") + " ___ " + key;
  6114. key = (isDot ? "dt99_" : "dt00_")
  6115. + "sb" + padZero(str.split(" ").length, 2)
  6116. + "_sc" + padZero(str.split(/[^a-z0-9 ]/i).length, 2)
  6117. + " ___ " + str + " ___ " + key;
  6118. }
  6119. else if (mode === 3)
  6120. {
  6121. // length
  6122. var length = 0;
  6123. if (str[0] === "<" || str[0] === "[")
  6124. {
  6125. length = str.length + 800;
  6126. }
  6127. else if (str.indexOf("<") > 0 || str.indexOf("[") > 0)
  6128. {
  6129. length = str.length + 600;
  6130. }
  6131. else
  6132. {
  6133. length = str.length;
  6134. }
  6135. key = (isTranslated ? "tr00_" : "tr99_") + "lt" + padZero(strTr.length, 3) + " "
  6136. + strTr + (isSuggested ? " _sg00" : " _sg99") + " ___ " + key;
  6137. key = (isDot ? "dt99_" : "dt00_")
  6138. + "sp" + (str.split(/[^a-z0-9]/i).length > 1 ? "99_" : "00_")
  6139. + "ln" + padZero(length, 3)
  6140. + " ___ " + str + " ___ " + key;
  6141. }
  6142. key = key.toLowerCase();
  6143. keyArr.push(key);
  6144. var eleParent = eleKeys[i].parentElement.parentElement.parentElement
  6145. .parentElement.parentElement.parentElement;
  6146. //eleParent.dataset.stshKey = key;
  6147. //console.log("Key: " + key);
  6148. valArr[key] = eleParent.outerHTML.trim();
  6149. }
  6150. catch (ex)
  6151. {
  6152. console.error("sortKey", ex.message);
  6153. }
  6154. }
  6155. var keyArrTmp = keyArr.slice();
  6156. keyArr.sort();
  6157. var isSame = true;
  6158. for (var i = 0; i < keyArr.length; i++)
  6159. {
  6160. if (keyArr[i] !== keyArrTmp[i])
  6161. {
  6162. isSame = false;
  6163. }
  6164. }
  6165. if (!isSame)
  6166. {
  6167. var eleTable = document.querySelector("#keylist > table:nth-child(1) > tbody:nth-child(1)");
  6168. if (eleTable)
  6169. {
  6170. var newInner = "";
  6171. for (var i = 0; i < keyArr.length; i++)
  6172. {
  6173. newInner += valArr[keyArr[i]];
  6174. }
  6175. eleTable.innerHTML = newInner;
  6176. }
  6177. }
  6178. }
  6179. var activeHideStatus = [0, 0, 0, 0, 0, 0];
  6180. // notTranslated, suggested, resuggested, approved, declined, translated
  6181. var activeHideKey = [0, 0, 0, 0, 0, 0];
  6182. // app, game, faq, support, promo, email
  6183. var activeHideStr = [0, 0];
  6184. // notMatch, long
  6185. var activeSort = -1;
  6186. var eleBtnShowAll = document.querySelector("#stsh_showing_all");
  6187. if (eleBtnShowAll)
  6188. {
  6189. eleBtnShowAll.addEventListener("click", function()
  6190. {
  6191. var elesBtnShowing = document.querySelectorAll(
  6192. ".stsh_showing_status, .stsh_showing_key, .stsh_showing_str");
  6193. for (var i = 0; i < elesBtnShowing.length; i++)
  6194. {
  6195. elesBtnShowing[i].disabled = false;
  6196. }
  6197. for (var i = 0; i < activeHideStatus.length; i++)
  6198. {
  6199. activeHideStatus[i] = 0;
  6200. }
  6201. for (var i = 0; i < activeHideKey.length; i++)
  6202. {
  6203. activeHideKey[i] = 0;
  6204. }
  6205. for (var i = 0; i < activeHideStr.length; i++)
  6206. {
  6207. activeHideStr[i] = 0;
  6208. }
  6209. activeSort = -1;
  6210. hideKey(-1); // Show all
  6211. countShowing();
  6212. });
  6213. }
  6214.  
  6215. var elesBtnShowingStatus = document.querySelectorAll(".stsh_showing_status");
  6216. for (var i = 0; i < elesBtnShowingStatus.length; i++)
  6217. {
  6218. elesBtnShowingStatus[i].addEventListener("click", function(ev)
  6219. {
  6220. var mode = parseInt(ev.target.dataset.hidestatus) || 0;
  6221. activeHideStatus[mode] = 1;
  6222. hideStatus(mode);
  6223. ev.target.disabled = true;
  6224. });
  6225. }
  6226. var obTarget_hider = document.querySelector("#keylist_container");
  6227. if (obTarget_hider)
  6228. {
  6229. var obMu_hider = new MutationObserver(function(mutations)
  6230. {
  6231. mutations.forEach(function(mutation)
  6232. {
  6233. //console.log("obMu_hider");
  6234. for (var i = 0; i < activeHideStatus.length; i++)
  6235. {
  6236. if (activeHideStatus[i] === 1)
  6237. {
  6238. hideStatus(i);
  6239. }
  6240. }
  6241. for (var i = 0; i < activeHideKey.length; i++)
  6242. {
  6243. if (activeHideKey[i] === 1)
  6244. {
  6245. hideKey(i);
  6246. }
  6247. }
  6248. for (var i = 0; i < activeHideStr.length; i++)
  6249. {
  6250. if (activeHideStr[i] === 1)
  6251. {
  6252. hideStr(i);
  6253. }
  6254. }
  6255. sortKey(activeSort);
  6256. });
  6257. });
  6258. var obConfig_hider = { childList: true };
  6259. obMu_hider.observe(obTarget_hider, obConfig_hider);
  6260. }
  6261.  
  6262. var elesBtnSort = document.querySelectorAll(".stsh_sort");
  6263. for (var i = 0; i < elesBtnSort.length; i++)
  6264. {
  6265. elesBtnSort[i].addEventListener("click", function(ev)
  6266. {
  6267. var mode = parseInt(ev.target.dataset.sort) || 0;
  6268. activeSort = mode;
  6269. sortKey(activeSort);
  6270. });
  6271. }
  6272.  
  6273. var setVisibleKey = function(startKey, visible)
  6274. {
  6275. // Use ("", true) to show all
  6276. startKey = startKey.toLowerCase();
  6277. var display = visible !== true ? "none" : "";
  6278. var eleKeys = document.querySelectorAll
  6279. (" \
  6280. #keylist > table:nth-child(1) \
  6281. > tbody:nth-child(1) > tr > td:nth-child(1) > div:nth-child(1) \
  6282. > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(1) \
  6283. ");
  6284. for (var i = 0; i < eleKeys.length; i++)
  6285. {
  6286. try
  6287. {
  6288. if (eleKeys[i].textContent.trim().toLowerCase().indexOf(startKey) > -1)
  6289. {
  6290. var eleTarget = eleKeys[i].parentElement.parentElement.parentElement
  6291. .parentElement.parentElement.parentElement;
  6292. if (visible && eleTarget.classList.contains("stsh_hidden"))
  6293. {
  6294. eleTarget.classList.remove("stsh_hidden");
  6295. }
  6296. else if (!visible && !eleTarget.classList.contains("stsh_hidden"))
  6297. {
  6298. eleTarget.classList.add("stsh_hidden");
  6299. }
  6300. }
  6301. }
  6302. catch (ex)
  6303. {
  6304. console.error("setVisibleKey", ex.message);
  6305. }
  6306. }
  6307. }
  6308. var hideKey = function(mode)
  6309. {
  6310. /*
  6311. mode:
  6312. -1: showAll
  6313. 0: app
  6314. 1: game
  6315. 2: faq
  6316. 3: support
  6317. 4: promo
  6318. 5: email
  6319. */
  6320. if (mode === -1) // showAll
  6321. {
  6322. setVisibleKey("", true);
  6323. }
  6324. else if (mode === 0) // app
  6325. {
  6326. setVisibleKey("# storefront_english_apps.txt #", false);
  6327. setVisibleKey("# storefront_english_main.txt # #app_", false);
  6328. setVisibleKey("# community_english.txt # SharedFiles_App_", false);
  6329. setVisibleKey("# appmgmt_english.txt #", false);
  6330. setVisibleKey("STEAM/VR", false);
  6331. }
  6332. else if (mode === 1) // game
  6333. {
  6334. setVisibleKey("GAMES/", false);
  6335. setVisibleKey("TF_", false);
  6336. }
  6337. else if (mode === 2) // faq
  6338. {
  6339. setVisibleKey("# support_faq_english.txt #", false);
  6340. }
  6341. else if (mode === 3) // support
  6342. {
  6343. setVisibleKey("# supportui_english.txt #", false);
  6344. setVisibleKey("# help_english.txt #", false);
  6345. }
  6346. else if (mode === 4) // promo
  6347. {
  6348. setVisibleKey("#promo", false);
  6349. setVisibleKey("#hardware", false);
  6350. setVisibleKey("ControllerBinding", false);
  6351. setVisibleKey("Library_Controller", false);
  6352. setVisibleKey("STEAM/HARDWARE", false);
  6353. setVisibleKey("STEAM/DELTA", false);
  6354. setVisibleKey("GAMES/KILLINGFLOOR2", false);
  6355. }
  6356. else if (mode === 5) // email
  6357. {
  6358. setVisibleKey("#email", false);
  6359. }
  6360. }
  6361. var elesBtnShowingKey = document.querySelectorAll(".stsh_showing_key");
  6362. for (var i = 0; i < elesBtnShowingKey.length; i++)
  6363. {
  6364. elesBtnShowingKey[i].addEventListener("click", function(ev)
  6365. {
  6366. var mode = parseInt(ev.target.dataset.hidekey) || 0;
  6367. activeHideKey[mode] = 1;
  6368. hideKey(mode);
  6369. ev.target.disabled = true;
  6370. });
  6371. }
  6372. var hideStr = function(mode)
  6373. {
  6374. /*
  6375. mode:
  6376. 0: notMatch
  6377. 1: long
  6378. */
  6379. if (mode === 0) // notMatch
  6380. {
  6381. var searchStr = decodeURIComponent(getQueryByName("search_input")).replace(/\\+/g," ").trim();
  6382. searchStr = searchStr.toLowerCase();
  6383. var eleStrs = document.querySelectorAll
  6384. (" \
  6385. #keylist \
  6386. > table:nth-child(1) > tbody:nth-child(1) > tr > td:nth-child(1) > div:nth-child(1) \
  6387. > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(2) \
  6388. ");
  6389. for (var i = 0; i < eleStrs.length; i++)
  6390. {
  6391. try
  6392. {
  6393. var valStr = eleStrs[i].children[0].textContent.trim().toLowerCase();
  6394. var valTrn = eleStrs[i].children[2].textContent.trim().toLowerCase();
  6395. if (valStr !== searchStr && valTrn !== searchStr)
  6396. {
  6397. var eleTarget = eleStrs[i].parentElement.parentElement
  6398. .parentElement.parentElement.parentElement;
  6399. if (!eleTarget.classList.contains("stsh_hidden"))
  6400. {
  6401. eleTarget.classList.add("stsh_hidden");
  6402. }
  6403. }
  6404. }
  6405. catch (ex)
  6406. {
  6407. console.error("hideStrNotMatch", ex.message);
  6408. }
  6409. }
  6410. }
  6411. else if (mode === 1) // long
  6412. {
  6413. var dot = "...";
  6414. var dotLengthMinus = 0 - dot.length;
  6415. var eleStrs = document.querySelectorAll
  6416. (" \
  6417. #keylist \
  6418. > table:nth-child(1) > tbody:nth-child(1) > tr > td:nth-child(1) > div:nth-child(1) \
  6419. > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(2) > td:nth-child(1) \
  6420. ");
  6421. for (var i = 0; i < eleStrs.length; i++)
  6422. {
  6423. try
  6424. {
  6425. var valStr = eleStrs[i].textContent.trim();
  6426. if (valStr.substr(dotLengthMinus) === dot)
  6427. {
  6428. var eleTarget = eleStrs[i].parentElement.parentElement
  6429. .parentElement.parentElement.parentElement.parentElement;
  6430. if (!eleTarget.classList.contains("stsh_hidden"))
  6431. {
  6432. eleTarget.classList.add("stsh_hidden");
  6433. }
  6434. }
  6435. }
  6436. catch (ex)
  6437. {
  6438. console.error("hideStrLong", ex.message);
  6439. }
  6440. }
  6441. }
  6442. }
  6443. var elesBtnShowingStr = document.querySelectorAll(".stsh_showing_str");
  6444. for (var i = 0; i < elesBtnShowingStr.length; i++)
  6445. {
  6446. elesBtnShowingStr[i].addEventListener("click", function(ev)
  6447. {
  6448. var mode = parseInt(ev.target.dataset.hidestr) || 0;
  6449. activeHideStr[mode] = 1;
  6450. hideStr(mode);
  6451. ev.target.disabled = true;
  6452. });
  6453. }
  6454. } // End Hide & sort suggestions
  6455.  
  6456. resizeSuggestionBox();
  6457. // Add Frame button when iframe load failed
  6458. {
  6459. var obTarget_ifrm = document.querySelector("#suggestions_iframe");
  6460. if (obTarget_ifrm)
  6461. {
  6462. var obMu_ifrm = new MutationObserver(function(mutations)
  6463. {
  6464. mutations.forEach(function(mutation)
  6465. {
  6466. var divFrame = document.querySelector("#stsh_frame");
  6467. if (!divFrame)
  6468. {
  6469. var divOuter = document.querySelector("#suggestions_box_outer");
  6470. if (divOuter)
  6471. {
  6472. divFrame = document.createElement("div");
  6473. divFrame.id = "stsh_frame";
  6474. divOuter.appendChild(divFrame);
  6475. }
  6476. }
  6477. if (divFrame)
  6478. {
  6479. var ifrm = document.querySelector("#suggestions_iframe");
  6480. if (ifrm)
  6481. {
  6482. var src = ifrm.getAttribute("src");
  6483. var token = getQueryByName("token_key", src);
  6484. divFrame.innerHTML =
  6485. ' \
  6486. <br><br> \
  6487. <div id="stsh_frame_sub"> \
  6488. Token: <span class="stsh_blue">' + token + '</span> \
  6489. <br><br> \
  6490. <a class="stsh_a_button" target="_blank" href="' + src + '">Frame</a> \
  6491. <br><br> \
  6492. This frame may be blocked by ad blocker software. \
  6493. <br> \
  6494. Please whitelist https://translation.steampowered.com to prevent this missing frame. \
  6495. </div> \
  6496. ';
  6497. }
  6498. }
  6499. });
  6500. });
  6501.  
  6502. var obConfig_ifrm = { attributes: true, attributeFilter: ["src"] };
  6503. obMu_ifrm.observe(obTarget_ifrm, obConfig_ifrm);
  6504. }
  6505. }
  6506. // Open frame if only one string
  6507. {
  6508. setTimeoutCustom(function()
  6509. {
  6510. var elesCopy = document.querySelectorAll("#keylist .copysmall");
  6511. if (elesCopy.length === 1)
  6512. {
  6513. var eleDiv = elesCopy[0].parentElement.parentElement.parentElement;
  6514. if (eleDiv.tagName === "DIV")
  6515. {
  6516. if (!isVisible())
  6517. {
  6518. eleDiv.click();
  6519. }
  6520. }
  6521. }
  6522. }, timingInit.openFrame);
  6523. }
  6524. // Fix STS search options
  6525. {
  6526. for (var i = 0; i < 6; i++)
  6527. {
  6528. var elesSort = document.querySelectorAll("#search #sort" + i);
  6529. if (elesSort.length === 2)
  6530. {
  6531. elesSort[1].id = "status" + i;
  6532. }
  6533. }
  6534. var elesLabel = document.querySelectorAll("#search label[for='sort0']");
  6535. if (elesLabel.length === 2)
  6536. {
  6537. elesLabel[1].setAttribute("for", "status0");
  6538. }
  6539. var eleLabelEntire = document.querySelector("label[for='keys']");
  6540. if (eleLabelEntire && eleLabelEntire.textContent.trim() === "ENTIRE DB")
  6541. {
  6542. eleLabelEntire.setAttribute("for", "all");
  6543. }
  6544. }
  6545. // Add date navigation
  6546. {
  6547. var eleInput = document.querySelector("input#search_input");
  6548. if (eleInput)
  6549. {
  6550. var date = "";
  6551. var valInput = eleInput.value.trim();
  6552. if (valInput.indexOf("DATE: ") === 0)
  6553. {
  6554. date = valInput.replace("DATE: ", "");
  6555. }
  6556. var eleBtn = document.querySelector("button#search_input");
  6557. if (eleBtn)
  6558. {
  6559. if (!date)
  6560. {
  6561. if (eleBtn.value.indexOf("DATE: ") === 0)
  6562. {
  6563. date = eleBtn.value.replace("DATE: ", "");
  6564. }
  6565. }
  6566. if (date)
  6567. {
  6568. eleBtn.classList.add("stsh_date_cur");
  6569. eleBtn.title = eleBtn.value.replace("DATE: ", "");
  6570. eleBtn.textContent = "TODAY";
  6571. eleBtn.removeAttribute("id");
  6572. eleBtn.removeAttribute("name");
  6573. var eleDiv = document.createElement("div");
  6574. eleDiv.classList.add("stsh_date_group");
  6575. if (eleBtn.previousSibling.nodeType === document.TEXT_NODE)
  6576. {
  6577. // Remove all &nbsp;
  6578. removeElement(eleBtn.previousSibling);
  6579. }
  6580. insertAfterElement(eleDiv, eleBtn.previousElementSibling);
  6581. eleDiv.appendChild(eleBtn);
  6582. // Calc prev and next date
  6583. {
  6584. var ts = getUnixTimestamp(date);
  6585. var sDay = 86400;
  6586. var datePrev = getDateGmt(ts - sDay);
  6587. var dateNext = getDateGmt(ts + sDay);
  6588. var eleBtnLeft = document.createElement("button");
  6589. eleBtnLeft.classList.add("stsh_date_prev");
  6590. eleBtnLeft.setAttribute("type", "submit");
  6591. eleBtnLeft.value = "DATE: " + datePrev;
  6592. eleBtnLeft.title = datePrev;
  6593. eleBtnLeft.textContent = "<<";
  6594. insertBeforeElement(eleBtnLeft, eleBtn);
  6595. var eleBtnRight = document.createElement("button");
  6596. eleBtnRight.classList.add("stsh_date_next");
  6597. eleBtnRight.setAttribute("type", "submit");
  6598. eleBtnRight.value = "DATE: " + dateNext;
  6599. eleBtnRight.title = dateNext;
  6600. eleBtnRight.textContent = ">>";
  6601. insertAfterElement(eleBtnRight, eleBtn);
  6602. var applyInputDate = function(ev)
  6603. {
  6604. var eleTarget = ev.target;
  6605. var eleInput = document.querySelector("input#search_input");
  6606. if (eleInput)
  6607. {
  6608. eleInput.value = eleTarget.value;
  6609. }
  6610. };
  6611. eleBtn.addEventListener("click", applyInputDate);
  6612. eleBtnLeft.addEventListener("click", applyInputDate);
  6613. eleBtnRight.addEventListener("click", applyInputDate);
  6614. }
  6615. }
  6616. }
  6617. }
  6618. }
  6619. // Add shortcut keys for pagination
  6620. var bindPagination = function()
  6621. {
  6622. var elesPrev = document.querySelectorAll(".pagination > a:first-child");
  6623. if (elesPrev.length === 2)
  6624. {
  6625. elesPrev[0].textContent = "Prev";
  6626. elesPrev[1].textContent = "Prev";
  6627. addKeyCtrl(document, elesPrev[0], ["BracketLeft", 219], "[", 2|8); // [
  6628. disableAfterClick(elesPrev[0]);
  6629. }
  6630. var elesNext = document.querySelectorAll(".pagination > a:last-child");
  6631. if (elesNext.length === 2)
  6632. {
  6633. elesNext[0].textContent = "Next";
  6634. elesNext[1].textContent = "Next";
  6635. addKeyCtrl(document, elesNext[0], ["BracketRight", 221, 171], "]", 2|8); // ]
  6636. disableAfterClick(elesNext[0]);
  6637. }
  6638. };
  6639. bindPagination();
  6640. // Clean pagination urls
  6641. var cleanPagination = function()
  6642. {
  6643. var elesPage = document.querySelectorAll(".pagination > a");
  6644. cleanUrlTimestamp(elesPage);
  6645. };
  6646. cleanPagination();
  6647. // Bind observer for keyList
  6648. {
  6649. var obTarget_keyList = document.querySelector("#keylist_container");
  6650. if (obTarget_keyList)
  6651. {
  6652. var tmOb_keyList = -1;
  6653. var obMu_keyList = new MutationObserver(function(mutations)
  6654. {
  6655. mutations.forEach(function(mutation)
  6656. {
  6657. if ((mutation.type !== "attributes"
  6658. || mutation.target.tagName === "TR")
  6659. && mutation.target.tagName !== "A")
  6660. {
  6661. clearTimeout(tmOb_keyList);
  6662. tmOb_keyList = setTimeoutCustom(function(mutation)
  6663. {
  6664. countShowing();
  6665. addLineCounter();
  6666. bindPagination();
  6667. cleanPagination();
  6668. //console.log("keyList: " + tmOb_keyList);
  6669. }, timingInit.bindObserverKeyList, mutation);
  6670. }
  6671. });
  6672. });
  6673. var obConfig_keyList = { childList: true, subtree: true, attributes: true, attributeFilter: ["class"] };
  6674. obMu_keyList.observe(obTarget_keyList, obConfig_keyList);
  6675. }
  6676. }
  6677. } // End translate.php
  6678.  
  6679. if (url.indexOf("user_activity.php") > -1)
  6680. {
  6681. document.body && document.body.classList.add("stsh_page_userActivity");
  6682. setTimeoutCustom(function()
  6683. {
  6684. var isMyProfile = false;
  6685. // Resolve mixed content
  6686. {
  6687. var hostTag =
  6688. [
  6689. ["img", "src"],
  6690. ["img", "src"],
  6691. ["img", "src"],
  6692. ["a", "href"],
  6693. ["a", "href"],
  6694. ];
  6695. var hostOld =
  6696. [
  6697. "http://cdn.akamai.steamstatic.com/",
  6698. "http://media.steampowered.com/",
  6699. "http://cdn.edgecast.steamstatic.com/",
  6700. "http://steamcommunity.com/",
  6701. "http://translation.steampowered.com",
  6702. ];
  6703. var hostReplace =
  6704. [
  6705. "https://steamcdn-a.akamaihd.net/",
  6706. "https://steamcdn-a.akamaihd.net/",
  6707. "https://steamcdn-a.akamaihd.net/",
  6708. "https://steamcommunity.com/",
  6709. "https://translation.steampowered.com",
  6710. ];
  6711. for (var j = 0; j < hostOld.length; j++)
  6712. {
  6713. var eles = document.querySelectorAll(hostTag[j][0] + "[" + hostTag[j][1] + "^='" + hostOld[j] + "']");
  6714. for (var i = 0; i < eles.length; i++)
  6715. {
  6716. eles[i].setAttribute(hostTag[j][1]
  6717. , eles[i].getAttribute(hostTag[j][1]).replace(hostOld[j], hostReplace[j]));
  6718. }
  6719. }
  6720. }
  6721. // Check current profile is my profile or not
  6722. {
  6723. if (userId)
  6724. {
  6725. var userPage = getQueryByName("user", url);
  6726. if (userId === userPage)
  6727. {
  6728. isMyProfile = true;
  6729. }
  6730. }
  6731. if (!isMyProfile)
  6732. {
  6733. var eleASug = document.querySelector(".friend_block_avatar > a[href*='//translation.steampowered.com/translate.php'");
  6734. if (eleASug && eleASug.textContent.trim() === "YOUR SUGGESTIONS")
  6735. {
  6736. isMyProfile = true;
  6737. }
  6738. }
  6739. if (!isMyProfile)
  6740. {
  6741. if (document.querySelector("#moderator_announcement"))
  6742. {
  6743. isMyProfile = true;
  6744. }
  6745. }
  6746. }
  6747. var user = "";
  6748. var eleAvatar = document.querySelector(".friend_block_avatar > a[href^='https://steamcommunity.com']");
  6749. if (eleAvatar)
  6750. {
  6751. if (eleAvatar.href.indexOf("https://steamcommunity.com/profiles/") === 0)
  6752. {
  6753. user = eleAvatar.href.replace("https://steamcommunity.com/profiles/", "");
  6754. }
  6755. var name = eleAvatar.firstElementChild.getAttribute("title");
  6756. if (name === "")
  6757. {
  6758. name = user;
  6759. }
  6760. document.title = name + " - " + document.title;
  6761. }
  6762.  
  6763. var stsh_activityAddLink_start = getTimeMs();
  6764. var stsh_activityAddLink_itv = setIntervalCustom(function(user)
  6765. {
  6766. // Add more links in user activity
  6767. var stsh_activityAddLink_isEnd = false;
  6768. var stsh_activityAddLink_cur = getTimeMs();
  6769. var h3s = document.querySelectorAll("#leftAreaContainer h3");
  6770. if (h3s.length === 2)
  6771. {
  6772. var td = h3s[1].parentElement;
  6773. var matchArr = td.innerHTML.match(/<\/h3>.+<br>/i);
  6774. if (matchArr)
  6775. {
  6776. var name = matchArr[0]
  6777. .replace("</h3>-", "")
  6778. .replace("-<br>", "")
  6779. .replace("<br>", "")
  6780. .trim();
  6781. if (name === "")
  6782. {
  6783. name = user;
  6784. }
  6785. if (name === "")
  6786. {
  6787. name = "Steam";
  6788. }
  6789. var tagNew = "";
  6790. if (user === "")
  6791. {
  6792. tagNew =
  6793. "\
  6794. </h3>\
  6795. <a id='stsh_sectionId' class='stsh_blue' target='_blank' href='https://steamcommunity.com/my'>\
  6796. " + name + "</a>, \
  6797. <a class='stsh_green' target='_blank' href='/WhereIsEsty.php'>Esty</a><br><br>\
  6798. ";
  6799. }
  6800. else
  6801. {
  6802. tagNew =
  6803. "\
  6804. </h3>\
  6805. <a id='stsh_sectionId' class='stsh_blue' target='_blank' href='https://steamcommunity.com/profiles/" + user + "'>\
  6806. " + name + "</a>, \
  6807. <a class='stsh_green' target='_blank' href='/WhereIsEsty.php?collectionof=" + user + "'>Esty</a>\
  6808. "
  6809. /*
  6810. // Typonion
  6811. + ", <a class='stsh_green' target='_blank' href='/translate.php?user="
  6812. + user + "&onionhunter=1&liststatus=1'>Onion</a>
  6813. */
  6814. + " <br><br> ";
  6815. }
  6816. td.innerHTML = td.innerHTML.replace(/<\/h3>.+<br>/i, tagNew);
  6817. stsh_activityAddLink_isEnd = true;
  6818. }
  6819. if (stsh_activityAddLink_isEnd || stsh_activityAddLink_cur - stsh_activityAddLink_start > 10000)
  6820. {
  6821. clearInterval(stsh_activityAddLink_itv);
  6822. }
  6823. }
  6824. }, 300, user);
  6825. var countWord = "";
  6826. var countSugg = "";
  6827. var inputDials = document.querySelectorAll("#leftAreaContainer input.dial");
  6828. if (inputDials.length === 2)
  6829. {
  6830. countWord = inputDials[0].getAttribute("title").replace("words", "").trim();
  6831. countSugg = inputDials[1].getAttribute("title").replace("suggestions", "").trim();
  6832. }
  6833. var tdCount = document.querySelector("#leftAreaContainer td[align='left']");
  6834. if (tdCount)
  6835. {
  6836. tdCount.innerHTML =
  6837. '\
  6838. <div class="stsh_profile_count stsh_profile_count_word">Word: ' + countWord + '</div> \
  6839. <div class="stsh_profile_count stsh_profile_count_sugg">Suggestion: ' + countSugg + '</div>\
  6840. ';
  6841. }
  6842. var sug = document.body.textContent;
  6843. var regComment = /VIEW COMMENT/g;
  6844. var regSuggest = /VIEW SUGGESTION/g;
  6845. var strComment = "...RECEIVED A MODERATOR COMMENT";
  6846. var strPending = "...ARE PENDING";
  6847. var strApproved = "...WERE APPROVED";
  6848. var strDeclined = "...WERE DECLINED";
  6849. var strApplied = "...HAVE BEEN APPLIED WITHIN THE LAST 14 DAYS";
  6850. var strRemoved = "...HAVE BEEN REMOVED WITHIN THE LAST 14 DAYS";
  6851. var startComment = sug.indexOf(strComment);
  6852. var startPending = sug.indexOf(strPending);
  6853. var startApproved = sug.indexOf(strApproved);
  6854. var startDeclined = sug.indexOf(strDeclined);
  6855. var startApplied = sug.indexOf(strApplied);
  6856. var startRemoved = sug.indexOf(strRemoved);
  6857. var sugComment = sug.substring(startComment,startPending);
  6858. var sugPending = sug.substring(startPending,startApproved);
  6859. var sugApproved = sug.substring(startApproved,startDeclined);
  6860. var sugDeclined = sug.substring(startDeclined,startApplied);
  6861. var sugApplied = sug.substring(startApplied,startRemoved);
  6862. var sugRemoved = sug.substring(startRemoved);
  6863. var countComment = (sugComment.match(regComment) || []).length;
  6864. var countPending = (sugPending.match(regSuggest) || []).length;
  6865. var countApproved = (sugApproved.match(regSuggest) || []).length;
  6866. var countDeclined = (sugDeclined.match(regSuggest) || []).length;
  6867. var countApplied = (sugApplied.match(regSuggest) || []).length;
  6868. var countRemoved = (sugRemoved.match(regSuggest) || []).length;
  6869. var divBtn = document.createElement("div");
  6870. document.body.appendChild(divBtn);
  6871. divBtn.innerHTML =
  6872. ' \
  6873. <div class="stsh_menu_group"> \
  6874. &nbsp; <input id="stsh_btnToProgress" value="To Progress" class="stsh_btn_long" type="button" \
  6875. onclick="scrollToId(\'stsh_sectionId\', -50); return false;" /><br> \
  6876. \
  6877. &nbsp; <span class="stsh_scroll_header">Scroll To</span>\
  6878. <li class="stsh_suggestion_btn stsh_suggestion stsh_suggestion_comment"><input value="Comment (' + countComment + ')" \
  6879. class="stsh_btn_long" type="button" onclick="scrollToId(\'stsh_sectionComment\'); return false;" ></li> \
  6880. <li class="stsh_suggestion_btn stsh_suggestion stsh_suggestion_pending"><input value="Pending (' + countPending + ')" \
  6881. class="stsh_btn_long" type="button" onclick="scrollToId(\'stsh_sectionPending\'); return false;" ></li> \
  6882. <li class="stsh_suggestion_btn stsh_suggestion stsh_suggestion_approved"><input value="Approved (' + countApproved + ')" \
  6883. class="stsh_btn_long" type="button" onclick="scrollToId(\'stsh_sectionApproved\'); return false;" ></li> \
  6884. <li class="stsh_suggestion_btn stsh_suggestion stsh_suggestion_declined"><input value="Declined (' + countDeclined + ')" \
  6885. class="stsh_btn_long" type="button" onclick="scrollToId(\'stsh_sectionDeclined\'); return false;" ></li> \
  6886. <li class="stsh_suggestion_btn stsh_suggestion stsh_suggestion_applied"><input value="Applied (' + countApplied + ')" \
  6887. class="stsh_btn_long" type="button" onclick="scrollToId(\'stsh_sectionApplied\'); return false;" ></li> \
  6888. <li class="stsh_suggestion_btn stsh_suggestion stsh_suggestion_removed"><input value="Removed (' + countRemoved + ')" \
  6889. class="stsh_btn_long" type="button" onclick="scrollToId(\'stsh_sectionRemoved\'); return false;" ></li> \
  6890. <br> \
  6891. &nbsp; <input id="stsh_btnHideSuggestion" value="Suggestions" class="stsh_btn_long" type="button" \
  6892. onclick="return false;" title="Toggle hidden/shown suggestion list" /><br> \
  6893. <br> \
  6894. &nbsp; <input value="Refresh" class="stsh_btn_long" type="button" onclick="window.location = window.location.href; return false;" /> \
  6895. <br> \
  6896. </div> \
  6897. ';
  6898.  
  6899. var divContainer = document.querySelector("#leftAreaContainer");
  6900. if (divContainer)
  6901. {
  6902. var inner = divContainer.innerHTML;
  6903. var htmlPending = /\.\.\.ARE \<a [^\<]+\>PENDING\<\/a\>/i.exec(inner);
  6904. var htmlApproved = /\.\.\.WERE \<a [^\<]+\>APPROVED\<\/a\>/i.exec(inner);
  6905. var htmlDeclined = /\.\.\.WERE \<a [^\<]+\>DECLINED\<\/a\>/i.exec(inner);
  6906. if (htmlPending && htmlApproved && htmlDeclined)
  6907. {
  6908. divContainer.innerHTML = inner
  6909. .replace("...RECEIVED A MODERATOR COMMENT",
  6910. "<span id='stsh_sectionComment' class='stsh_suggestion_header'>"
  6911. + "...RECEIVED A MODERATOR COMMENT ("
  6912. + countComment + ")</span>")
  6913. .replace(htmlPending,
  6914. "<span id='stsh_sectionPending' class='stsh_suggestion_header'>" + htmlPending + " ("
  6915. + countPending + ")</span>")
  6916. .replace(htmlApproved,
  6917. "<span id='stsh_sectionApproved' class='stsh_suggestion_header'>" + htmlApproved + " ("
  6918. + countApproved + ")</span>")
  6919. .replace(htmlDeclined,
  6920. "<span id='stsh_sectionDeclined' class='stsh_suggestion_header'>" + htmlDeclined + " ("
  6921. + countDeclined + ")</span>")
  6922. .replace("...HAVE BEEN APPLIED WITHIN THE LAST 14 DAYS",
  6923. "<span id='stsh_sectionApplied' class='stsh_suggestion_header'>"
  6924. + "...HAVE BEEN APPLIED WITHIN THE LAST 14 DAYS ("
  6925. + countApplied + ")</span>")
  6926. .replace("...HAVE BEEN REMOVED WITHIN THE LAST 14 DAYS",
  6927. "<span id='stsh_sectionRemoved' class='stsh_suggestion_header'>"
  6928. + "...HAVE BEEN REMOVED WITHIN THE LAST 14 DAYS ("
  6929. + countRemoved + ")</span>");
  6930. }
  6931. }
  6932. if (document.querySelector("#hours"))
  6933. {
  6934. var eleBtn = document.querySelector("#stsh_btnToProgress");
  6935. if (eleBtn)
  6936. {
  6937. var ele = document.createElement("input");
  6938. ele.classList.add("stsh_btn_long");
  6939. ele.setAttribute("value", "To Hours");
  6940. ele.setAttribute("type", "button");
  6941. ele.setAttribute("onclick", "scrollToElement(\"input[name*='[remarks]']\", -48); return false;");
  6942. insertAfterElement(ele, eleBtn);
  6943. ele = document.createTextNode(" \u00A0 ");
  6944. insertAfterElement(ele, eleBtn);
  6945. ele = document.createElement("br");
  6946. insertAfterElement(ele, eleBtn);
  6947. }
  6948. }
  6949. var cans = document.querySelectorAll("canvas");
  6950. for (var i = 0; i < cans.length; i++)
  6951. {
  6952. removeElement(cans[i]);
  6953. }
  6954. /* // Unknown reason
  6955. var aKeys = document.querySelectorAll("#leftAreaContainer li > a:nth-child(1)");
  6956. for (var i = 0; i < aKeys.length; i++)
  6957. {
  6958. var key = aKeys[i].textContent;
  6959. var keyArr = key.substr(21).trim().split(" >> ");
  6960. keyArr[0] = "<span style='color: #FFF !important;'>" + keyArr[0] + "</span>";
  6961. var keyNew = key.substr(0,21) + keyArr.join(" >> ") + "";
  6962. aKeys[i].innerHTML = keyNew;
  6963. }
  6964. */
  6965. var sugModeComment = 0;
  6966. var sugModePending = 1;
  6967. var sugModeApproved = 2;
  6968. var sugModeDeclined = 3;
  6969. var sugModeApplied = 4;
  6970. var sugModeRemoved = 5;
  6971. var sugMode = sugModeComment;
  6972. var eleSugFirst = document.querySelector
  6973. (" \
  6974. #leftAreaContainer > a[href^='translate.php?search_input='] \
  6975. , #leftAreaContainer > form > a[href^='translate.php?search_input='] \
  6976. ");
  6977. if (eleSugFirst)
  6978. {
  6979. var eleSugHeadPrev = eleSugFirst.previousElementSibling.previousElementSibling;
  6980. if (eleSugHeadPrev.id === "stsh_sectionRemoved")
  6981. {
  6982. sugMode = sugModeRemoved;
  6983. }
  6984. else if (eleSugHeadPrev.id === "stsh_sectionApplied")
  6985. {
  6986. sugMode = sugModeApplied;
  6987. }
  6988. else if (eleSugHeadPrev.id === "stsh_sectionDeclined")
  6989. {
  6990. sugMode = sugModeDeclined;
  6991. }
  6992. else if (eleSugHeadPrev.id === "stsh_sectionApproved")
  6993. {
  6994. sugMode = sugModeApproved;
  6995. }
  6996. else if (eleSugHeadPrev.id === "stsh_sectionPending")
  6997. {
  6998. sugMode = sugModePending;
  6999. }
  7000. var eleSugNext = eleSugFirst;
  7001. while (eleSugNext)
  7002. {
  7003. if (eleSugNext.tagName === "A")
  7004. {
  7005. var attrHref = eleSugNext.getAttribute("href");
  7006. if (attrHref && attrHref.indexOf("translate.php?search_input=") === 0)
  7007. {
  7008. eleSugNext.classList.add("stsh_suggestion");
  7009. if (sugMode === sugModeComment)
  7010. {
  7011. eleSugNext.classList.add("stsh_suggestion_comment");
  7012. }
  7013. else if (sugMode === sugModePending)
  7014. {
  7015. eleSugNext.classList.add("stsh_suggestion_pending");
  7016. }
  7017. else if (sugMode === sugModeApproved)
  7018. {
  7019. eleSugNext.classList.add("stsh_suggestion_approved");
  7020. }
  7021. else if (sugMode === sugModeDeclined)
  7022. {
  7023. eleSugNext.classList.add("stsh_suggestion_declined");
  7024. }
  7025. else if (sugMode === sugModeApplied)
  7026. {
  7027. eleSugNext.classList.add("stsh_suggestion_applied");
  7028. }
  7029. else if (sugMode === sugModeRemoved)
  7030. {
  7031. eleSugNext.classList.add("stsh_suggestion_removed");
  7032. }
  7033. }
  7034. }
  7035. else if (eleSugNext.tagName === "SPAN" && eleSugNext.classList.contains("stsh_suggestion_header"))
  7036. {
  7037. if (eleSugNext.id === "stsh_sectionRemoved")
  7038. {
  7039. sugMode = sugModeRemoved;
  7040. }
  7041. else if (eleSugNext.id === "stsh_sectionApplied")
  7042. {
  7043. sugMode = sugModeApplied;
  7044. }
  7045. else if (eleSugNext.id === "stsh_sectionDeclined")
  7046. {
  7047. sugMode = sugModeDeclined;
  7048. }
  7049. else if (eleSugNext.id === "stsh_sectionApproved")
  7050. {
  7051. sugMode = sugModeApproved;
  7052. }
  7053. else if (eleSugNext.id === "stsh_sectionPending")
  7054. {
  7055. sugMode = sugModePending;
  7056. }
  7057. }
  7058. eleSugNext = eleSugNext.nextElementSibling;
  7059. }
  7060. }
  7061. // Change language & correct url
  7062. {
  7063. var aProgresses = document.querySelectorAll("div > .friend_block_avatar a[onmouseout]");
  7064. for (var i = 0; i < aProgresses.length; i++)
  7065. {
  7066. var langCur = getQueryByName("lang", aProgresses[i].href);
  7067. if (langCur === "")
  7068. {
  7069. aProgresses[i].href = aProgresses[i].href + lang;
  7070. }
  7071. else
  7072. {
  7073. if (langCur !== lang)
  7074. {
  7075. //var langQuery = (url.indexOf("?") > -1) ? "&lang=" : "?lang=";
  7076. //window.location = url + langQuery + langCur;
  7077. console.log("Lang: " + langCur);
  7078. }
  7079. }
  7080. var aContent = aProgresses[i].textContent.trim();
  7081. if (aContent.indexOf("SUGGESTIONS") > -1)
  7082. {
  7083. aProgresses[i].href = aProgresses[i].href + "&listsort=5&liststatus=1&paginationrows=1000";
  7084. }
  7085. else if (aContent.indexOf("REVIEWS") > -1)
  7086. {
  7087. aProgresses[i].href = aProgresses[i].href + "&listsort=5&liststatus=3&paginationrows=1000";
  7088. }
  7089. }
  7090. }
  7091. // Hours
  7092. if (document.querySelector("#hours"))
  7093. {
  7094. var calculateHours = function()
  7095. {
  7096. var rgxDate = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
  7097. var rgxTime = /^(\d{1,2}:\d{2}(:\d{2})?|\d{1,2}\.\d{2})$/;
  7098. var eleFrom = document.querySelector("#stsh_hoursCalc_from");
  7099. var eleTo = document.querySelector("#stsh_hoursCalc_to");
  7100. var eleRes = document.querySelector("#stsh_hoursCalc_result");
  7101. if (eleFrom && eleTo && eleRes)
  7102. {
  7103. var rawFrom = eleFrom.value.trim();
  7104. var rawTo = eleTo.value.trim();
  7105. var valFrom = 0;
  7106. var valTo = 0;
  7107. if (rgxDate.test(rawFrom))
  7108. {
  7109. rawFrom = rawFrom.substr(11);
  7110. }
  7111. if (rgxTime.test(rawFrom))
  7112. {
  7113. var arrTime = rawFrom.split(":");
  7114. if (arrTime.length === 1)
  7115. {
  7116. arrTime = rawFrom.split(".");
  7117. }
  7118. valFrom = parseInt(arrTime[1]) + (parseInt(arrTime[0]) * 60);
  7119. }
  7120. if (rgxDate.test(rawTo))
  7121. {
  7122. rawTo = rawTo.substr(11);
  7123. }
  7124. if (rgxTime.test(rawTo))
  7125. {
  7126. var arrTime = rawTo.split(":");
  7127. if (arrTime.length === 1)
  7128. {
  7129. arrTime = rawTo.split(".");
  7130. }
  7131. valTo = parseInt(arrTime[1]) + (parseInt(arrTime[0]) * 60);
  7132. }
  7133. var valDiff = Math.abs(valTo - valFrom);
  7134. var valHr = parseInt(valDiff / 60);
  7135. var valMn = valDiff % 60;
  7136. eleRes.textContent = padZero(valHr, 2) + ":" + padZero(valMn, 2);
  7137. }
  7138. }
  7139. var curDateStr = getDateUs();
  7140. // Add hours calculator
  7141. {
  7142. var eleFinalize = document.querySelector("#hours input[name='Finalize']");
  7143. if (eleFinalize)
  7144. {
  7145. var eleFinalizeParent = eleFinalize.parentElement;
  7146. eleFinalizeParent.setAttribute("colspan", "2");
  7147. eleFinalizeParent.style.verticalAlign = "top";
  7148. var elePad = document.createElement("td");
  7149. insertBeforeElement(elePad, eleFinalizeParent);
  7150. var eleCalc = document.createElement("td");
  7151. eleCalc.classList.add("stsh_hoursCalc");
  7152. insertBeforeElement(eleCalc, eleFinalizeParent);
  7153. if (eleCalc.parentElement.previousElementSibling.querySelector("input[type='radio']"))
  7154. {
  7155. eleCalc.appendChild(document.createElement("br"));
  7156. }
  7157. var ele = document.createElement("b");
  7158. ele.textContent = " Hours Calculator (Estimated) ";
  7159. eleCalc.appendChild(ele);
  7160. eleCalc.appendChild(document.createElement("br"));
  7161. ele = document.createElement("span");
  7162. ele.innerHTML =
  7163. ' \
  7164. Enter date or time to calculate range (calculate only hours and minutes). \
  7165. <br>You can enter date "2016-01-01 08:05:00" or time "8:05" or time "8.05".\
  7166. ';
  7167. ele.setAttribute("style", "display: inline-block; padding-bottom: 4px;");
  7168. eleCalc.appendChild(ele);
  7169. eleCalc.appendChild(document.createElement("br"));
  7170. ele = document.createElement("span");
  7171. ele.textContent = " From: ";
  7172. eleCalc.appendChild(ele);
  7173. ele = document.createElement("input");
  7174. ele.id = "stsh_hoursCalc_from";
  7175. ele.setAttribute("type", "text");
  7176. ele.setAttribute("onkeypress", "return event.keyCode !== 13;");
  7177. ele.setAttribute("autocomplete", "off");
  7178. ele.addEventListener("keyup", function()
  7179. {
  7180. calculateHours();
  7181. });
  7182. eleCalc.appendChild(ele);
  7183. ele = document.createElement("span");
  7184. ele.innerHTML = "&nbsp;&nbsp; To: ";
  7185. eleCalc.appendChild(ele);
  7186. ele = document.createElement("input");
  7187. ele.id = "stsh_hoursCalc_to";
  7188. ele.setAttribute("type", "text");
  7189. ele.setAttribute("onkeypress", "return event.keyCode !== 13;");
  7190. ele.setAttribute("autocomplete", "off");
  7191. ele.addEventListener("keyup", function()
  7192. {
  7193. calculateHours();
  7194. });
  7195. eleCalc.appendChild(ele);
  7196. ele = document.createElement("input");
  7197. ele.id = "stsh_hoursCalc_toNow";
  7198. ele.setAttribute("type", "button");
  7199. ele.setAttribute("value", "Now");
  7200. ele.setAttribute("onclick", "return false;");
  7201. ele.addEventListener("click", function()
  7202. {
  7203. var eleTo = document.querySelector("#stsh_hoursCalc_to");
  7204. eleTo.value = getTimeUs();
  7205. calculateHours();
  7206. });
  7207. eleCalc.appendChild(ele);
  7208. ele = document.createElement("span");
  7209. ele.innerHTML = "&nbsp;&nbsp; Result: ";
  7210. eleCalc.appendChild(ele);
  7211. ele = document.createElement("b");
  7212. ele.id = "stsh_hoursCalc_result"
  7213. ele.textContent = " 00:00 ";
  7214. eleCalc.appendChild(ele);
  7215. }
  7216. }
  7217. // Hilight current date
  7218. {
  7219. var elesTd = document.querySelectorAll("#hours > table > tbody > tr > td:nth-child(1)");
  7220. for (var i = 0; i < elesTd.length; i++)
  7221. {
  7222. if (elesTd[i].textContent.indexOf(curDateStr) > -1)
  7223. {
  7224. elesTd[i].parentElement.id = "stsh_hours_curDate";
  7225. elesTd[i].parentElement.classList.add("stsh_hours_curDate");
  7226. break;
  7227. }
  7228. }
  7229. }
  7230. // Auto calculate hours in current date
  7231. {
  7232. var timePendingFirst = "";
  7233. var timePendingLast = "";
  7234. var elesPending = document.querySelectorAll("#mainbody .stsh_suggestion_pending");
  7235. for (var i = 0; i < elesPending.length; i++)
  7236. {
  7237. var content = elesPending[i].textContent.trim().substr(0, 19);
  7238. if (content.substr(0, 10) === curDateStr)
  7239. {
  7240. timePendingFirst = content.substr(11, 5);
  7241. if (timePendingLast === "")
  7242. {
  7243. timePendingLast = timePendingFirst;
  7244. }
  7245. }
  7246. else
  7247. {
  7248. break;
  7249. }
  7250. }
  7251. var timeApprovedFirst = "";
  7252. var timeApprovedLast = "";
  7253. var elesApproved = document.querySelectorAll("#mainbody .stsh_suggestion_approved");
  7254. for (var i = 0; i < elesApproved.length; i++)
  7255. {
  7256. var content = elesApproved[i].textContent.trim().substr(0, 19);
  7257. if (content.substr(0, 10) === curDateStr)
  7258. {
  7259. timeApprovedFirst = content.substr(11, 5);
  7260. if (timeApprovedLast === "")
  7261. {
  7262. timeApprovedLast = timeApprovedFirst;
  7263. }
  7264. }
  7265. else
  7266. {
  7267. break;
  7268. }
  7269. }
  7270. if (timePendingFirst === "")
  7271. {
  7272. timePendingFirst = timeApprovedFirst;
  7273. }
  7274. if (timeApprovedFirst === "")
  7275. {
  7276. timeApprovedFirst = timePendingFirst;
  7277. }
  7278. if (timePendingLast === "")
  7279. {
  7280. timePendingLast = timeApprovedLast;
  7281. }
  7282. if (timeApprovedLast === "")
  7283. {
  7284. timeApprovedLast = timePendingLast;
  7285. }
  7286. var timeFirst = timeApprovedFirst < timePendingFirst ? timeApprovedFirst : timePendingFirst;
  7287. var timeLast = timeApprovedLast > timePendingLast ? timeApprovedLast : timePendingLast;
  7288. if (timeFirst !== "")
  7289. {
  7290. var eleFrom = document.querySelector("#stsh_hoursCalc_from");
  7291. if (eleFrom)
  7292. {
  7293. eleFrom.value = timeFirst;
  7294. }
  7295. var eleTo = document.querySelector("#stsh_hoursCalc_to");
  7296. if (eleTo)
  7297. {
  7298. eleTo.value = timeLast;
  7299. }
  7300. calculateHours();
  7301. }
  7302. }
  7303. // Make minutes add to hours
  7304. setTimeoutCustom(function()
  7305. {
  7306. var elesMn = document.querySelectorAll("#hours input[name*='[minutes]']");
  7307. for (var i = 0; i < elesMn.length; i++)
  7308. {
  7309. elesMn[i].setAttribute("min", "-15");
  7310. elesMn[i].setAttribute("max", "60");
  7311. elesMn[i].addEventListener("change", function(ev)
  7312. {
  7313. var eleMn = ev.target;
  7314. var eleHr = eleMn.parentElement.previousElementSibling.firstElementChild;
  7315. var valMn = parseInt(eleMn.value) || 0;
  7316. var valHr = parseInt(eleHr.value) || 0;
  7317. if (valMn < 0)
  7318. {
  7319. if (valHr > 0)
  7320. {
  7321. eleHr.value = valHr - 1;
  7322. eleMn.value = 45;
  7323. }
  7324. else
  7325. {
  7326. eleMn.value = 0;
  7327. }
  7328. }
  7329. else if (valMn > 59)
  7330. {
  7331. if (valHr < 23)
  7332. {
  7333. eleHr.value = valHr + 1;
  7334. eleMn.value = 0;
  7335. }
  7336. else
  7337. {
  7338. eleMn.value = 45;
  7339. }
  7340. }
  7341. });
  7342. }
  7343. }, 500);
  7344. // Make deferred can be clicked
  7345. {
  7346. var eleDeferred = document.querySelector("#hours td > i > span[title^='DATE']");
  7347. if (eleDeferred)
  7348. {
  7349. eleDeferred.dataset.title = eleDeferred.title;
  7350. eleDeferred.title = "Click to reveal";
  7351. eleDeferred.addEventListener("click", function(ev)
  7352. {
  7353. var ele = ev.target;
  7354. var eleDetail = document.querySelector(".stsh_deferred");
  7355. if (!eleDetail)
  7356. {
  7357. eleDetail = document.createElement("div");
  7358. eleDetail.classList.add("stsh_deferred");
  7359. ele.parentElement.parentElement
  7360. .parentElement.parentElement
  7361. .lastElementChild.firstElementChild
  7362. .appendChild(eleDetail);
  7363. }
  7364. var space = String.fromCharCode(160);
  7365. var space3 = space + space + space;
  7366. eleDetail.innerHTML = "<br>TOTAL DEFERRED HOURS" + space3 + " <br>"
  7367. + ele.dataset.title.substr(61).trim()
  7368. .replace(/\n/g, space3 + " <br>")
  7369. + space3;
  7370. });
  7371. }
  7372. }
  7373. // Hide past date
  7374. {
  7375. var hidePast = function ()
  7376. {
  7377. var isHidden = false;
  7378. var elesMn = document.querySelectorAll("#hours input[name*='[minutes]']");
  7379. if (elesMn.length > 0)
  7380. {
  7381. if (elesMn[0].name === "date[1969-12-31][minutes]")
  7382. {
  7383. isHidden = true;
  7384. }
  7385. }
  7386. if (isHidden)
  7387. {
  7388. for (var i = 1, l = elesMn.length - 1; i < l; i++)
  7389. {
  7390. elesMn[i].parentElement.parentElement.classList.add("stsh_hidden");
  7391. }
  7392. }
  7393. };
  7394. setTimeoutCustom(hidePast, 500);
  7395. }
  7396. }
  7397. // Hide wallet
  7398. // Hide email noti
  7399. {
  7400. if (!isMyProfile)
  7401. {
  7402. var elesAWallet = document.querySelectorAll("a[id^='walletkeys']");
  7403. for (var i = 0; i < elesAWallet.length; i++)
  7404. {
  7405. var eleCur = elesAWallet[i];
  7406. for (var j = 0; j < 5; j++)
  7407. {
  7408. eleCur.classList.add("stsh_hidden");
  7409. eleCur = eleCur.nextElementSibling;
  7410. }
  7411. }
  7412. var eleSub = document.querySelector("#subscribe");
  7413. if (eleSub)
  7414. {
  7415. eleSub.classList.add("stsh_hidden");
  7416. eleSub.previousElementSibling.classList.add("stsh_hidden");
  7417. eleSub.previousElementSibling.previousElementSibling.classList.add("stsh_hidden");
  7418. eleSub.nextElementSibling.classList.add("stsh_hidden");
  7419. eleSub.nextElementSibling.nextElementSibling.classList.add("stsh_hidden");
  7420. }
  7421. }
  7422. }
  7423. // Set visible suggestion list
  7424. {
  7425. var setVisibleSuggestion = function(visible)
  7426. {
  7427. var display = visible !== true ? "none" : "";
  7428. var eles = document.querySelectorAll(".copy");
  7429. for (var i = 0; i < eles.length; i++)
  7430. {
  7431. if (eles[i].id && eles[i].id.indexOf("showwalletkeys") < 0
  7432. && eles[i].id !== "abuse_report"
  7433. && eles[i].id !== "moderator_announcement")
  7434. {
  7435. if (eles[i].style.display !== display)
  7436. {
  7437. eles[i].style.display = display;
  7438. }
  7439. }
  7440. }
  7441. }
  7442. var eleHide = document.querySelector("#stsh_btnHideSuggestion");
  7443. if (eleHide)
  7444. {
  7445. var isHide = GM_getValue("profileHideSuggestion", 0);
  7446. if (isHide)
  7447. {
  7448. eleHide.dataset.modeNext = "show";
  7449. eleHide.value = "Suggestions: Hide";
  7450. setVisibleSuggestion(false);
  7451. }
  7452. else
  7453. {
  7454. eleHide.dataset.modeNext = "hide";
  7455. eleHide.value = "Suggestions: Show";
  7456. setVisibleSuggestion(true);
  7457. }
  7458. eleHide.addEventListener("click", function(ev)
  7459. {
  7460. var eleHide = ev.target;
  7461. if (eleHide.dataset.modeNext === "show")
  7462. {
  7463. eleHide.dataset.modeNext = "hide";
  7464. eleHide.value = "Suggestions: Show";
  7465. setVisibleSuggestion(true);
  7466. GM_setValue("profileHideSuggestion", 0);
  7467. }
  7468. else
  7469. {
  7470. eleHide.dataset.modeNext = "show";
  7471. eleHide.value = "Suggestions: Hide";
  7472. setVisibleSuggestion(false);
  7473. GM_setValue("profileHideSuggestion", 1);
  7474. }
  7475. });
  7476. }
  7477. }
  7478. // Add resolved comment checkbox
  7479. {
  7480. if (isMyProfile)
  7481. {
  7482. var objComment = GM_getValue("profile_comment", 0);
  7483. //console.log(GM_getValue("profile_comment"));
  7484. if (!objComment)
  7485. {
  7486. objComment = {};
  7487. }
  7488. if (!objComment[userId])
  7489. {
  7490. objComment[userId] = {};
  7491. }
  7492. var elesSugComment = document.querySelectorAll("#mainbody .stsh_suggestion_comment");
  7493. for (var i = 0; i < elesSugComment.length; i++)
  7494. {
  7495. var eleComment = elesSugComment[i].nextElementSibling.nextElementSibling
  7496. .nextElementSibling.lastElementChild;
  7497. if (eleComment)
  7498. {
  7499. eleComment.classList.add("stsh_suggestion_comment_detail");
  7500. var eleInput = document.createElement("input");
  7501. eleInput.classList.add("stsh_comment_resolved");
  7502. eleInput.setAttribute("type", "checkbox");
  7503. eleInput.setAttribute("value", "true");
  7504. var eleStrong = document.createElement("strong");
  7505. eleStrong.textContent = "Resolved:";
  7506. var eleDate = document.createElement("span");
  7507. eleDate.classList.add("stsh_comment_resolved_date");
  7508. var eleLabel = document.createElement("label");
  7509. eleLabel.classList.add("stsh_comment_resolved_label");
  7510. eleLabel.classList.add("stsh_unselectable");
  7511. eleLabel.classList.add("stsh_blue_light");
  7512. eleLabel.classList.add("stsh_cursor_pointer");
  7513. eleLabel.setAttribute("title", "Mark this comment as resolved. "
  7514. + "\nThis helps you indicated this string was corrected or not.");
  7515. eleLabel.appendChild(eleStrong);
  7516. eleLabel.appendChild(document.createTextNode(" "));
  7517. eleLabel.appendChild(eleInput);
  7518. eleLabel.appendChild(document.createTextNode(" "));
  7519. eleLabel.appendChild(eleDate);
  7520. insertAfterElement(eleLabel, eleComment);
  7521. var comment = eleComment.lastChild.textContent.trim();
  7522. var key = elesSugComment[i].textContent.trim();
  7523. var identifer = key + " ___ " + comment;
  7524. eleInput.dataset.stshUser = userId;
  7525. eleInput.dataset.stshIdentifier = identifer;
  7526. if (objComment[userId][identifer])
  7527. {
  7528. if (objComment[userId][identifer].resolved === "true")
  7529. {
  7530. eleInput.checked = true;
  7531. eleLabel.lastElementChild.textContent =
  7532. getDateTimeUs(objComment[userId][identifer].time);
  7533. }
  7534. }
  7535. else
  7536. {
  7537. objComment[userId][identifer] =
  7538. {
  7539. resolved: "false",
  7540. time: getUnixTimestamp(),
  7541. };
  7542. }
  7543. eleInput.addEventListener("click", function (ev)
  7544. {
  7545. var ele = ev.target;
  7546. var userId = ele.dataset.stshUser;
  7547. var identifer = ele.dataset.stshIdentifier;
  7548. var objComment = GM_getValue("profile_comment", 0);
  7549. if (!objComment)
  7550. {
  7551. objComment = {};
  7552. }
  7553. if (!objComment[userId])
  7554. {
  7555. objComment[userId] = {};
  7556. }
  7557. objComment[userId][identifer] =
  7558. {
  7559. resolved: ele.checked ? "true" : "false",
  7560. time: getUnixTimestamp(),
  7561. };
  7562. GM_setValue("profile_comment", objComment);
  7563. //console.log(GM_getValue("profile_comment"));
  7564. if (ele.checked && ele.nextElementSibling)
  7565. {
  7566. ele.nextElementSibling.textContent = "Now";
  7567. }
  7568. });
  7569. }
  7570. }
  7571. // Clean up
  7572. {
  7573. }
  7574. // Save
  7575. GM_setValue("profile_comment", objComment);
  7576. }
  7577. }
  7578. // Check mod status
  7579. {
  7580. if (isMyProfile)
  7581. {
  7582. var isMod = !!document.querySelector("#moderator_announcement");
  7583. var userMod = GM_getValue("mod", "");
  7584. if (userId && userId !== userMod)
  7585. {
  7586. GM_setValue("mod", userId);
  7587. }
  7588. }
  7589. }
  7590. }, timingInit.pageUserActivity);
  7591. } // End user_activity.php
  7592. if (/\/rally[0-9]{0,4}/.test(url))
  7593. {
  7594. document.body && document.body.classList.add("stsh_page_rally");
  7595. resizeSuggestionBox();
  7596. var outer = document.querySelector("#suggestions_box_outer");
  7597. if (outer)
  7598. {
  7599. outer.setAttribute("onclick", "hideSuggestionsBox();");
  7600. }
  7601. // Set cur lang to first
  7602. {
  7603. var first = document.querySelector(".gradienttable tr:nth-child(6)");
  7604. if (first)
  7605. {
  7606. var cur = null;
  7607. var tdLangs = document.querySelectorAll(".gradienttable tr > td:nth-child(1)");
  7608. for (var i = 0; i < tdLangs.length; i++)
  7609. {
  7610. if (lang === tdLangs[i].textContent.trim().toLowerCase())
  7611. {
  7612. cur = tdLangs[i].parentElement;
  7613. break;
  7614. }
  7615. }
  7616. if (cur)
  7617. {
  7618. cur.classList.add("stsh_curLang");
  7619. first.parentElement.insertBefore(cur, first);
  7620. }
  7621. }
  7622. }
  7623. // Change rows per page
  7624. {
  7625. var eleAs = document.querySelectorAll(".gradienttable tr:nth-child(6) a[href^='translate.php?']");
  7626. for (var i = 0; i < eleAs.length; i++)
  7627. {
  7628. eleAs[i].href = eleAs[i].href + "&paginationrows=1000";
  7629. }
  7630. }
  7631. var inputClose = document.querySelector("td:nth-child(3) > input:nth-child(1)");
  7632. if (inputClose)
  7633. {
  7634. inputClose.value = "Close (Esc)";
  7635. }
  7636. } // End rally.php
  7637. if (/\/rally_results_?[0-9]{0,4}/.test(url))
  7638. {
  7639. document.body && document.body.classList.add("stsh_page_rallyResults");
  7640. var h3 = document.querySelector("table.curved h3");
  7641. if (h3)
  7642. {
  7643. document.title = h3.textContent.trim();
  7644. }
  7645. var eleTable = document.querySelector("body > div:nth-child(1) > table:nth-child(1)");
  7646. if (eleTable)
  7647. {
  7648. eleTable.style.width = "";
  7649. }
  7650. var inputClose = document.querySelector("td:nth-child(3) > input:nth-child(1)");
  7651. if (inputClose)
  7652. {
  7653. inputClose.value = "Close (Esc)";
  7654. inputClose.focus();
  7655. }
  7656. // Add frame and background button
  7657. {
  7658. var eleTdFirst = document.querySelector("td:nth-child(1)");
  7659. if (eleTdFirst)
  7660. {
  7661. var eleTdFrame = document.createElement("td");
  7662. eleTdFrame.setAttribute("align", "right");
  7663. eleTdFrame.innerHTML =
  7664. ' <a class="stsh_a_button" target="_blank" href="' + url + '">Frame</a> ';
  7665. insertBeforeElement(eleTdFrame, eleTdFirst);
  7666. var img = document.body.style.backgroundImage;
  7667. if (img.indexOf("url(\"") === 0)
  7668. {
  7669. img = img.replace("url(\"", "").replace("\")", "");
  7670. var eleTdImage = document.createElement("td");
  7671. eleTdImage.setAttribute("align", "right");
  7672. eleTdImage.innerHTML =
  7673. ' <a class="stsh_a_button" target="_blank" href="' + img + '">View Background</a> ';
  7674. insertAfterElement(eleTdImage, eleTdFrame);
  7675. }
  7676. }
  7677. }
  7678. var inputPrev = document.querySelector("input[value^='Prev']");
  7679. if (inputPrev)
  7680. {
  7681. addKeyCtrl(document, inputPrev, ["BracketLeft", 219], "[", 1|2); // [
  7682. disableAfterClick(inputPrev);
  7683. }
  7684. var inputNext = document.querySelector("input[value^='Next']");
  7685. if (inputNext)
  7686. {
  7687. addKeyCtrl(document, inputNext, ["BracketRight", 221, 171], "]", 1|2); // ]
  7688. disableAfterClick(inputNext);
  7689. }
  7690. // Hilight cur lang
  7691. {
  7692. var elesLang = document.querySelectorAll("table.curved > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(3) > h2:nth-child(1)");
  7693. for (var i = 0; i < elesLang.length; i++)
  7694. {
  7695. if (lang === elesLang[i].textContent.trim().toLowerCase())
  7696. {
  7697. var eleParent = elesLang[i].parentElement.parentElement.parentElement.parentElement;
  7698. //eleParent.style.backgroundColor = "#474D1A";
  7699. eleParent.classList.add("stsh_curLang");
  7700. eleParent.setAttribute("bgcolor", "#474D1A");
  7701. eleParent.setAttribute("onmouseout", "this.bgColor='#474D1A'");
  7702. eleParent.setAttribute("onmouseover", "this.bgColor='#76802B'");
  7703. break;
  7704. }
  7705. }
  7706. }
  7707. // Reset points position
  7708. {
  7709. var eleSpan = document.querySelector("h5 > span");
  7710. if (eleSpan)
  7711. {
  7712. eleSpan.parentElement.parentElement.removeAttribute("style");
  7713. }
  7714. }
  7715. } // End rally_results.php
  7716. if (/\/rallyreplay_?[0-9]{0,4}/.test(url))
  7717. {
  7718. document.body && document.body.classList.add("stsh_page_rallyReplay");
  7719. // Set cur lang to first
  7720. {
  7721. var elesFrame = document.querySelectorAll("#leftAreaContainer div[id^='frame']");
  7722. for (var i = 0; i < elesFrame.length; i++)
  7723. {
  7724. var first = elesFrame[i].querySelector(".gradienttable tr:nth-child(6)");
  7725. if (first)
  7726. {
  7727. var cur = null;
  7728. var tdLangs = elesFrame[i].querySelectorAll(".gradienttable tr > td:nth-child(1)");
  7729. for (var j = 0; j < tdLangs.length; j++)
  7730. {
  7731. if (lang === tdLangs[j].textContent.trim().toLowerCase())
  7732. {
  7733. cur = tdLangs[j].parentElement;
  7734. break;
  7735. }
  7736. }
  7737. if (cur)
  7738. {
  7739. cur.classList.add("stsh_curLang");
  7740. first.parentElement.insertBefore(cur, first);
  7741. }
  7742. }
  7743. }
  7744. }
  7745. var eleBtn = document.querySelector("input[value='FASTEST']");
  7746. if (eleBtn)
  7747. {
  7748. var ele = document.createElement("input");
  7749. ele.setAttribute("type", "button");
  7750. ele.setAttribute("value", "RESTART");
  7751. ele.setAttribute("style", "padding: 0; border: none; background: none;");
  7752. ele.setAttribute("onclick",
  7753. " \
  7754. indexReplay = 0; \
  7755. elsFrame.eq(indexReplay).fadeOut(0, function() \
  7756. { \
  7757. indexReplay = (indexReplay + 1) % lenFrame; \
  7758. elsFrame.eq(indexReplay).fadeIn(0); \
  7759. }); \
  7760. ");
  7761. insertAfterElement(ele, eleBtn);
  7762. insertAfterElement(document.createTextNode(" | "), eleBtn);
  7763. }
  7764. } // End rallyreplay.php
  7765. if (url.indexOf("/WhereIsEsty.php") > -1)
  7766. {
  7767. document.body && document.body.classList.add("stsh_page_whereIsEsty");
  7768. resizeSuggestionBox();
  7769. var outer = document.querySelector("#suggestions_box_outer");
  7770. if (outer)
  7771. {
  7772. outer.setAttribute("onclick", "hideSuggestionsBox();");
  7773. }
  7774. var divContainer = document.querySelector("#pageContainer");
  7775. if (divContainer)
  7776. {
  7777. var ele = document.createElement("div");
  7778. ele.id = "logout";
  7779. ele.innerHTML =
  7780. ' <a class="stsh_a_button" target="_blank" href="/home.php">Home</a> ';
  7781. divContainer.appendChild(ele);
  7782. }
  7783.  
  7784. var divContent = document.querySelector("#leftAreaContainer > div");
  7785. if (divContent)
  7786. {
  7787. var countSnap = document.querySelectorAll("div.box").length;
  7788. var user = "";
  7789. var name = "";
  7790.  
  7791. var eleImg = document.querySelector("#leftAreaContainer > div > div > a > img ");
  7792. if (eleImg)
  7793. {
  7794. name = eleImg.getAttribute("title");
  7795. user = eleImg.parentElement.getAttribute("href").replace("https://steamcommunity.com/profiles/", "");
  7796. }
  7797. var ele = document.createElement("div");
  7798. ele.classList.add("stsh_snapshot");
  7799. ele.innerHTML = "<a class='stsh_blue' target='_blank' href='/user_activity.php?user="
  7800. + user + "'>" + name + "</a>"
  7801. + "<br>Snapshot: " + countSnap;
  7802.  
  7803. divContent.appendChild(ele);
  7804. }
  7805. } // End WhereIsEsty.php
  7806. if (url.indexOf("/stickerbox.php") > -1)
  7807. {
  7808. document.body && document.body.classList.add("stsh_page_stickerbox");
  7809. document.querySelector("textarea[name='add_comment']").focus();
  7810. var inputPrev = document.querySelector("img[src*='z0lEQVRIx5WWaWxVRRTH'");
  7811. if (inputPrev)
  7812. {
  7813. addKeyCtrl(document, inputPrev, ["BracketLeft", 219]); // [
  7814. disableAfterClick(inputPrev);
  7815. }
  7816. var inputNext = document.querySelector("img[src*='40lEQVRIx5WWe0xXZRjH'");
  7817. if (inputNext)
  7818. {
  7819. addKeyCtrl(document, inputNext, ["BracketRight", 221, 171]); // ]
  7820. disableAfterClick(inputNext);
  7821. }
  7822. } // End stickerbox.php
  7823. if (/\/(home\.php|index\.php)/i.test(url))
  7824. {
  7825. document.body && document.body.classList.add("stsh_page_home");
  7826. // Add class
  7827. {
  7828. var elesH1 = document.querySelectorAll("#leftAreaContainer h1");
  7829. for (var i = 0; i < elesH1.length; i++)
  7830. {
  7831. var text = elesH1[i].textContent.trim();
  7832. if (text === "Current Serverwide Focus")
  7833. {
  7834. elesH1[i].classList.add("stsh_home_focus");
  7835. }
  7836. else if (text.indexOf("Oldest") === 0)
  7837. {
  7838. elesH1[i].classList.add("stsh_home_application");
  7839. }
  7840. else if (text.indexOf("Most Outdated") === 0)
  7841. {
  7842. elesH1[i].classList.add("stsh_home_untranslated");
  7843. }
  7844. else if (text === "Latest 10 Cross-Language Discussions About Certain Tokens")
  7845. {
  7846. elesH1[i].classList.add("stsh_home_discussion");
  7847. }
  7848. else if (text === "Overall Progress")
  7849. {
  7850. elesH1[i].classList.add("stsh_home_progress");
  7851. }
  7852. }
  7853. var elesLi = document.querySelectorAll("#alldiscussions > ul > li > ul > li");
  7854. for (var i = 0; i < elesLi.length; i++)
  7855. {
  7856. var eleFirst = elesLi[i].firstElementChild;
  7857. if (eleFirst && eleFirst.tagName === "FONT")
  7858. {
  7859. elesLi[i].classList.add("stsh_home_discussion_langCur");
  7860. }
  7861. else
  7862. {
  7863. elesLi[i].classList.add("stsh_home_discussion_langOther");
  7864. }
  7865. }
  7866. }
  7867. // Set cur lang to first
  7868. {
  7869. var first = null;
  7870. var cur = null;
  7871. var curLang = lang.substring(0, 4);
  7872. if (curLang === "schi")
  7873. curLang = "sim.";
  7874. else if (curLang === "tchi")
  7875. curLang = "tra.";
  7876. var eleLangs = document.querySelectorAll("#overall .progress");
  7877. if (eleLangs.length > 0)
  7878. {
  7879. first = eleLangs[0];
  7880. for (var i = 0; i < eleLangs.length; i++)
  7881. {
  7882. if (curLang === eleLangs[i].textContent.trim().substring(0, 4).toLowerCase())
  7883. {
  7884. cur = eleLangs[i];
  7885. break;
  7886. }
  7887. }
  7888. if (cur)
  7889. {
  7890. cur.classList.add("stsh_blue");
  7891. var curSib1 = cur.nextSibling;
  7892. var curSib2 = curSib1.nextSibling;
  7893. var curSib3 = curSib2.nextSibling;
  7894. var curSib4 = curSib3.nextSibling;
  7895. var curSib5 = curSib4.nextSibling;
  7896. var curSib6 = curSib5.nextSibling;
  7897. insertBeforeElement(cur, first);
  7898. insertAfterElement(curSib6, cur);
  7899. insertAfterElement(curSib5, cur);
  7900. insertAfterElement(curSib4, cur);
  7901. insertAfterElement(curSib3, cur);
  7902. insertAfterElement(curSib2, cur);
  7903. insertAfterElement(curSib1, cur);
  7904. }
  7905. }
  7906. }
  7907. if (document.querySelector("#logout"))
  7908. {
  7909. var tmplHome =
  7910. ' \
  7911. <div class="stsh_home_group"> \
  7912. <span class="stsh_home_header">Shortcuts</span> \
  7913. <div> \
  7914. <a class="stsh_a_button stsh_btn_med" target="_blank" \
  7915. href="/translate.php?search_input=DATE%3A+%DATE%&paginationrows=1000">New Today</a \
  7916. ><a class="stsh_a_button stsh_btn_med" target="_blank" href="/glossary.php">Glossary</a> \
  7917. </div> \
  7918. %PROFILE% \
  7919. <span class="stsh_home_header">Rally</span> \
  7920. <div> \
  7921. <a class="stsh_a_button stsh_btn_med" target="_blank" href="/rally.php">Rally</a \
  7922. >%RALLY% \
  7923. </div> \
  7924. <span class="stsh_home_header">Events</span> \
  7925. <div> \
  7926. <a class="stsh_a_button stsh_btn_med stsh_grey" target="_blank" href="/rallyreplay.php">Rally Replay</a \
  7927. ><a class="stsh_a_button stsh_btn_med stsh_grey" target="_blank" href="/onionolooorm.php">Typonion</a \
  7928. ><a class="stsh_a_button stsh_btn_med" target="_blank" href="/dstbattle.php">DST Battle</a \
  7929. ><a class="stsh_a_button stsh_btn_med" target="_blank" href="/dota2.php">DOTA 2</a> \
  7930. </div> \
  7931. <span class="stsh_home_header stsh_home_section_scroll">Scroll To</span> \
  7932. <div class="stsh_home_section_scroll"> \
  7933. <a class="stsh_a_button stsh_btn_med" onclick="window.scrollTo(0, 0); return false;" >Focus</a \
  7934. ><a class="stsh_a_button stsh_btn_med" onclick="scrollToElement(\'.stsh_home_untranslated\', -4); return false;" >Untranslated</a \
  7935. ><a class="stsh_a_button stsh_btn_med" onclick="scrollToElement(\'.stsh_home_discussion\', -4); return false;" >Discussion</a \
  7936. ><a class="stsh_a_button stsh_btn_med" onclick="scrollToElement(\'.stsh_home_progress\', -4); return false;" >Progress</a> \
  7937. </div> \
  7938. <br> \
  7939. <div><a class="stsh_a_button stsh_btn_med" target="_self" href="/home.php">Refresh</a></div> \
  7940. </div> \
  7941. ';
  7942. tmplHome = tmplHome.replace("%DATE%", getDateUs());
  7943. // Rally
  7944. {
  7945. var date = new Date();
  7946. var yearLast = date.getUTCFullYear();
  7947. var yearFirst = 2013;
  7948. var yearDisabled = [2015];
  7949. var isEven = (yearLast - yearFirst + (isRally() ? 1 : 0)) % 2 === 0;
  7950. var count = 0;
  7951. var strRally = "";
  7952. for (var i = yearLast; i >= yearFirst; i--)
  7953. {
  7954. if (i < yearLast || isRally())
  7955. {
  7956. if (count % 2 === (isEven ? 0 : 1))
  7957. {
  7958. strRally += '<div>';
  7959. }
  7960. if (count === 0 && !isEven)
  7961. {
  7962. strRally += '<div><a class="stsh_a_button stsh_btn_med'
  7963. + (yearDisabled.indexOf(i) > -1 ? " stsh_grey" : "")
  7964. + '" target="_blank" '
  7965. + 'href="/rally' + i + '.php">Rally ' + i + '</a></div>';
  7966. }
  7967. else
  7968. {
  7969. strRally += '<a class="stsh_a_button stsh_btn_short'
  7970. + (yearDisabled.indexOf(i) > -1 ? " stsh_grey" : "")
  7971. + '" target="_blank" '
  7972. + 'href="/rally' + i + '.php">' + i + '</a>';
  7973. }
  7974. if (count > 0 && count % 2 === (isEven ? 1 : 0))
  7975. {
  7976. strRally += '</div>';
  7977. }
  7978. count++;
  7979. }
  7980. }
  7981. tmplHome = tmplHome.replace("%RALLY%", strRally);
  7982. }
  7983. // Profile
  7984. {
  7985. var strProfile = "";
  7986. if (userId)
  7987. {
  7988. strProfile = '<div class="stsh_group_space">'
  7989. + '<a class="stsh_a_button stsh_btn_med" target="_blank" '
  7990. + 'href="/translate.php?user=' + userId
  7991. + '&listsort=5&liststatus=1&paginationrows=1000">My Suggestions</a>';
  7992. var userMod = GM_getValue("mod", "");
  7993. if (userMod === userId)
  7994. {
  7995. strProfile += '<a class="stsh_a_button stsh_btn_med" target="_blank" '
  7996. + 'href="/translate.php?user=' + userId
  7997. + '&moderator=1&listsort=5&liststatus=3&paginationrows=1000">My Reviews</a>';
  7998. }
  7999. strProfile += '</div>';
  8000. }
  8001. tmplHome = tmplHome.replace("%PROFILE%", strProfile);
  8002. }
  8003. var eleNew = document.createElement("div");
  8004. eleNew.innerHTML = tmplHome;
  8005. document.body.appendChild(eleNew);
  8006. }
  8007. // Fix STS JS error
  8008. {
  8009. var eleTimer = document.querySelector("#timer");
  8010. if (!eleTimer)
  8011. {
  8012. var ele = document.createElement("div");
  8013. ele.id = "timer";
  8014. ele.classList.add("stsh_hidden");
  8015. document.body.appendChild(ele);
  8016. }
  8017. }
  8018. // Add rows per page
  8019. {
  8020. var eleAs = document.querySelectorAll("#leftAreaContainer > div:not([id]) >.progress a[href^='translate.php?']");
  8021. for (var i = 0; i < eleAs.length; i++)
  8022. {
  8023. eleAs[i].href = eleAs[i].href + "&paginationrows=1000";
  8024. }
  8025. }
  8026. // Add counter to title
  8027. {
  8028. var counter = [0, 0];
  8029. var eleComment = document.querySelector("#leftAreaContainer > b > a[href^='user_activity.php?user=']:nth-child(3)");
  8030. if (eleComment)
  8031. {
  8032. counter[0] = eleComment.textContent.trim();
  8033. }
  8034. var elePrivate = document.querySelector("#titleprivatemessages");
  8035. if (elePrivate)
  8036. {
  8037. var rgxPrivate = /Private Messages \((\d) new\)/i;
  8038. counter[1] =(elePrivate.textContent.match(rgxPrivate) || [0, 0])[1];
  8039. }
  8040. if (counter[0] && counter[1])
  8041. {
  8042. document.title = "(" + counter[0] + "," + counter[1] + ") " + document.title;
  8043. }
  8044. else if (counter[0] || counter[1])
  8045. {
  8046. document.title = "(" + (counter[0] || counter[1]) + ") " + document.title;
  8047. }
  8048. }
  8049. // Toggle file discussion
  8050. {
  8051. var elesLi = document.querySelectorAll("#alldiscussions > ul > li");
  8052. for (var i = 0; i < elesLi.length; i++)
  8053. {
  8054. var node = elesLi[i].firstChild;
  8055. if (node && node.nodeType === document.TEXT_NODE)
  8056. {
  8057. var eleSpan = document.createElement("span");
  8058. eleSpan.classList.add("stsh_home_discussion_file");
  8059. eleSpan.textContent = node.textContent;
  8060. elesLi[i].replaceChild(eleSpan, node);
  8061. eleSpan.addEventListener("click", function(ev)
  8062. {
  8063. var eleTarget = ev.target;
  8064. var eleUl = eleTarget.nextElementSibling;
  8065. if (eleUl && eleUl.tagName === "UL")
  8066. {
  8067. if (eleUl.style.display === "none")
  8068. {
  8069. eleUl.style.display = "block";
  8070. }
  8071. else
  8072. {
  8073. eleUl.style.display = "none";
  8074. }
  8075. }
  8076. });
  8077. }
  8078. }
  8079. }
  8080. // Hide other languages
  8081. {
  8082. var eleAllDiscuss = document.querySelector("#alldiscussions");
  8083. if (eleAllDiscuss)
  8084. {
  8085. var strHide = "Hide other languages";
  8086. var strShow = "Show other languages";
  8087. var eleBtn = document.createElement("input");
  8088. eleBtn.classList.add("stsh_home_hideOtherLang");
  8089. eleBtn.type = "button";
  8090. eleBtn.value = strHide;
  8091. eleBtn.dataset.modeNext = "hide";
  8092. insertBeforeElement(eleBtn, eleAllDiscuss.firstElementChild);
  8093.  
  8094. eleBtn.addEventListener("click", function(ev)
  8095. {
  8096. var eleTarget = ev.target;
  8097. var mode = "hide";
  8098. if (eleTarget.dataset.modeNext === "hide")
  8099. {
  8100. mode = "hide";
  8101. eleTarget.dataset.modeNext = "show";
  8102. eleTarget.value = strShow;
  8103. }
  8104. else
  8105. {
  8106. mode = "show";
  8107. eleTarget.dataset.modeNext = "hide";
  8108. eleTarget.value = strHide;
  8109. }
  8110. if (mode === "hide")
  8111. {
  8112. var elesLang = document.querySelectorAll(".stsh_home_discussion_langOther");
  8113. for (var i = 0; i < elesLang.length; i++)
  8114. {
  8115. elesLang[i].classList.add("stsh_hidden");
  8116. }
  8117. }
  8118. else
  8119. {
  8120. var elesLang = document.querySelectorAll(".stsh_home_discussion_langOther.stsh_hidden");
  8121. for (var i = 0; i < elesLang.length; i++)
  8122. {
  8123. elesLang[i].classList.remove("stsh_hidden");
  8124. }
  8125. }
  8126. });
  8127. }
  8128. }
  8129. // Correct app links
  8130. {
  8131. var strIncludeApps = "&includeapps=1";
  8132. var elesApp = document.querySelectorAll("a[href^='translate.php?lang=thai&search_input=%23app_']");
  8133. for (var i = 0; i < elesApp.length; i++)
  8134. {
  8135. var href = elesApp[i].getAttribute("href");
  8136. if (href.indexOf(strIncludeApps) < 0)
  8137. {
  8138. elesApp[i].setAttribute("href", href + strIncludeApps);
  8139. }
  8140. }
  8141. }
  8142. } // End home.php
  8143. if (url.indexOf("/glossary.php") > -1)
  8144. {
  8145. document.body && document.body.classList.add("stsh_page_glossary");
  8146. // Add shortcuts
  8147. {
  8148. var contentGlos =
  8149. ' \
  8150. <div class="stsh_home_group"> \
  8151. <span class="stsh_home_header">Shortcuts</span> \
  8152. <br> &nbsp; \
  8153. <a class="stsh_a_button stsh_btn_med" target="_blank" \
  8154. href="/translate.php?chosenfile=1&listfilter=1&listsort=3&paginationrows=1000&branch_ID=49&file_ID=226"> \
  8155. Glossary</a> &nbsp; \
  8156. <br> &nbsp; \
  8157. <a class="stsh_a_button stsh_btn_med" target="_blank" \
  8158. href="/translate.php?chosenfile=1&listfilter=1&listsort=3&paginationrows=1000&branch_ID=49&file_ID=232"> \
  8159. Phrases</a> &nbsp; \
  8160. <br> \
  8161. </div> \
  8162. ';
  8163. var eleNew = document.createElement("div");
  8164. eleNew.innerHTML = contentGlos;
  8165. document.body.appendChild(eleNew);
  8166. }
  8167. // Improve glossary links
  8168. {
  8169. var elesLink = document.querySelectorAll("#votes_container > .lbAction a[href^='./translate.php?search_input=']");
  8170. for (var i = 0; i < elesLink.length; i++)
  8171. {
  8172. elesLink[i].href = elesLink[i].href.replace("keyonly=0", "keyonly=2")
  8173. .replace("listsort=0", "listsort=4")
  8174. .replace("paginationrows=50", "paginationrows=1000");
  8175. }
  8176. }
  8177. } // End glossary.php
  8178. if (url.indexOf("/dstbattle.php") > -1)
  8179. {
  8180. document.body && document.body.classList.add("stsh_page_dstbattle");
  8181. // Hilight cur lang
  8182. {
  8183. var cur = null;
  8184. var elesLang = document.querySelectorAll(".gradienttable > tbody:nth-child(1) > tr > th:nth-child(1)");
  8185. for (var i = 1; i < elesLang.length; i++)
  8186. {
  8187. if (lang === elesLang[i].textContent.trim().replace(/[0-9]+\. /, "").toLowerCase())
  8188. {
  8189. cur = elesLang[i].parentElement;
  8190. break;
  8191. }
  8192. }
  8193. if (cur)
  8194. {
  8195. cur.classList.add("stsh_dst_curLang");
  8196. }
  8197. }
  8198. } // End dstbattle.php
  8199. if (url.indexOf("/statistics.php") > -1)
  8200. {
  8201. document.body && document.body.classList.add("stsh_page_statistics");
  8202. setTimeoutCustom(function()
  8203. {
  8204. var qBranch = getQueryByName("branch_ID");
  8205. var qFile = getQueryByName("file_ID");
  8206. if (qBranch === "" && qFile === "")
  8207. {
  8208. var getProgress = function(content)
  8209. {
  8210. content = content.trim();
  8211. var rgxNum = /[0-9]+/g;
  8212. var data = "";
  8213. if (content.indexOf("<15") > -1)
  8214. {
  8215. data = "014"
  8216. }
  8217. else if (content.indexOf("100") < 0)
  8218. {
  8219. data = "0" + (content.match(rgxNum) || ["00"])[0];
  8220. }
  8221. else
  8222. {
  8223. data = "100";
  8224. }
  8225. return data;
  8226. }
  8227. var branch = "";
  8228. var elesTr = document.querySelectorAll(".tableprogress tr");
  8229. for (var i = 0; i < elesTr.length; i++)
  8230. {
  8231. var eleH = elesTr[i].querySelector("h2");
  8232. if (eleH)
  8233. {
  8234. branch = eleH.textContent.trim();
  8235. }
  8236. else
  8237. {
  8238. var eleA = elesTr[i].querySelector("td:nth-child(2) > a:nth-child(1)[href^='translate.php']");
  8239. if (eleA)
  8240. {
  8241. elesTr[i].classList.add("stsh_stat_progress");
  8242. elesTr[i].dataset.translated = getProgress(eleA.textContent);
  8243. elesTr[i].dataset.approved = getProgress(
  8244. eleA.parentElement.nextElementSibling.firstElementChild.textContent);
  8245. elesTr[i].dataset.branch = branch;
  8246. elesTr[i].dataset.file = elesTr[i].firstElementChild.textContent.trim();
  8247. }
  8248. }
  8249. }
  8250. var eleDiv = document.createElement("div");
  8251. document.body.appendChild(eleDiv);
  8252. eleDiv.innerHTML =
  8253. ' \
  8254. <div class="stsh_showing_group"> \
  8255. <span class="stsh_showing_header">Hide</span>\
  8256. <br> &nbsp; <input id="stsh_stat_hideGame" value="Game" class="stsh_btn_short" type="button" /> \
  8257. <input id="stsh_stat_hideSteam" value="Steam" class="stsh_btn_short" type="button" /> \
  8258. <br> &nbsp; <input id="stsh_stat_hideApproved" value="Approved" class="stsh_btn_long" type="button" /> \
  8259. <br> &nbsp; <input id="stsh_stat_hideCompleted" value="Completed" class="stsh_btn_long" type="button" /> \
  8260. <br> \
  8261. <br> &nbsp; <input id="stsh_stat_showAll" value="Show All" class="stsh_btn_long" type="button" /> \
  8262. </div> \
  8263. ';
  8264.  
  8265. var eleHideGame = document.querySelector("#stsh_stat_hideGame");
  8266. eleHideGame.addEventListener("click", function()
  8267. {
  8268. var elesProgress = document.querySelectorAll(".stsh_stat_progress:not(.stsh_hidden)");
  8269. for (var i = 0; i < elesProgress.length; i++)
  8270. {
  8271. if (elesProgress[i].dataset.branch.indexOf("games/") === 0)
  8272. {
  8273. elesProgress[i].classList.add("stsh_hidden");
  8274. }
  8275. }
  8276. });
  8277. var eleHideSteam = document.querySelector("#stsh_stat_hideSteam");
  8278. eleHideSteam.addEventListener("click", function()
  8279. {
  8280. var elesProgress = document.querySelectorAll(".stsh_stat_progress:not(.stsh_hidden)");
  8281. for (var i = 0; i < elesProgress.length; i++)
  8282. {
  8283. if (elesProgress[i].dataset.branch.indexOf("steam") === 0)
  8284. {
  8285. elesProgress[i].classList.add("stsh_hidden");
  8286. }
  8287. }
  8288. });
  8289. var eleHideApproved = document.querySelector("#stsh_stat_hideApproved");
  8290. eleHideApproved.addEventListener("click", function()
  8291. {
  8292. var elesProgress = document.querySelectorAll(".stsh_stat_progress:not(.stsh_hidden)");
  8293. for (var i = 0; i < elesProgress.length; i++)
  8294. {
  8295. if (elesProgress[i].dataset.translated === elesProgress[i].dataset.approved)
  8296. {
  8297. elesProgress[i].classList.add("stsh_hidden");
  8298. }
  8299. }
  8300. });
  8301. var eleHideCompleted = document.querySelector("#stsh_stat_hideCompleted");
  8302. eleHideCompleted.addEventListener("click", function()
  8303. {
  8304. var elesProgress = document.querySelectorAll(".stsh_stat_progress:not(.stsh_hidden)");
  8305. for (var i = 0; i < elesProgress.length; i++)
  8306. {
  8307. if (elesProgress[i].dataset.translated === "100" && elesProgress[i].dataset.approved === "100")
  8308. {
  8309. elesProgress[i].classList.add("stsh_hidden");
  8310. }
  8311. }
  8312. });
  8313. var eleShowAll = document.querySelector("#stsh_stat_showAll");
  8314. eleShowAll.addEventListener("click", function()
  8315. {
  8316. var elesProgress = document.querySelectorAll(".stsh_stat_progress.stsh_hidden");
  8317. for (var i = 0; i < elesProgress.length; i++)
  8318. {
  8319. elesProgress[i].classList.remove("stsh_hidden");
  8320. }
  8321. });
  8322. }
  8323. // Add rows per page
  8324. {
  8325. var eleAs = document.querySelectorAll("#leftAreaContainer a[href^='translate.php?']");
  8326. for (var i = 0; i < eleAs.length; i++)
  8327. {
  8328. eleAs[i].href = eleAs[i].href + "&paginationrows=1000";
  8329. }
  8330. }
  8331. }, timingInit.improveStatistics);
  8332. } // End statistics.php
  8333. if (url.indexOf("index.php") > -1
  8334. || url === "https://translation.steampowered.com/")
  8335. {
  8336. document.body && document.body.classList.add("stsh_page_index");
  8337. var eleDes = document.querySelector("#verify-form > form");
  8338. if (eleDes)
  8339. {
  8340. var eleSpan = document.createElement("span");
  8341. eleSpan.classList.add("stsh_autoLoginOption");
  8342.  
  8343. var eleInput = document.createElement("input");
  8344. eleInput.id = "stsh_autoLogin";
  8345. eleInput.setAttribute("type", "checkbox");
  8346. eleInput.setAttribute("value", "auto");
  8347. var autoLogin = function()
  8348. {
  8349. var eleImage = document.querySelector("#verify-form > form > input[class='image']");
  8350. if (eleImage)
  8351. {
  8352. setTimeoutCustom(function()
  8353. {
  8354. var eleInput = document.querySelector("#stsh_autoLogin");
  8355. if (eleInput && eleInput.checked)
  8356. {
  8357. eleImage.click();
  8358. }
  8359. }, timingInit.autoLogin);
  8360. }
  8361. }
  8362. if (GM_getValue("autoLogin", 0) === "true")
  8363. {
  8364. eleInput.checked = true;
  8365. autoLogin();
  8366. }
  8367.  
  8368. eleInput.addEventListener("click", function (e)
  8369. {
  8370. var ele = e.target;
  8371. if (ele.checked)
  8372. {
  8373. GM_setValue("autoLogin", "true");
  8374. autoLogin();
  8375. }
  8376. else
  8377. {
  8378. GM_setValue("autoLogin", "false");
  8379. }
  8380. });
  8381.  
  8382. var eleLabel = document.createElement("label");
  8383. eleLabel.setAttribute("for", "stsh_autoLogin");
  8384. eleLabel.textContent = " Auto Login";
  8385. eleLabel.title = "Auto click login button"
  8386.  
  8387. eleSpan.appendChild(eleInput);
  8388. eleSpan.appendChild(eleLabel);
  8389. eleDes.appendChild(eleSpan);
  8390. }
  8391. } // End index.php
  8392. if (url.indexOf("try_auth.php") > -1)
  8393. {
  8394. document.body && document.body.classList.add("stsh_page_tryAuth");
  8395. setTimeoutCustom(function()
  8396. {
  8397. document.forms[0].submit();
  8398. }, timingInit.authSubmit);
  8399. } // End try_auth.php
  8400. window.addEventListener("beforeunload", function (e)
  8401. {
  8402. clearTimeoutAll();
  8403. clearIntervalAll();
  8404. });
  8405. if (perfStart > 0)
  8406. {
  8407. var perfEnd = performance.now();
  8408. //console.log("STS Helper - Perf: " + (perfEnd - perfStart).toFixed(2) + "ms, Page: " + window.location.pathname);
  8409. }
  8410. } // End Main
  8411.  
  8412. function client()
  8413. {
  8414. var clientScript =
  8415. ' \
  8416. /* STSH JS - clientScript */ \
  8417. var timeoutList = []; \
  8418. var intervalList = []; \
  8419. \
  8420. function setTimeoutCustom(func, tm, params) \
  8421. { \
  8422. var id = setTimeout(func, tm, params); \
  8423. timeoutList.push(id); \
  8424. return id; \
  8425. } \
  8426. \
  8427. function clearTimeoutAll() \
  8428. { \
  8429. for (var i = 0; i < timeoutList.length; i++) \
  8430. { \
  8431. clearTimeout(timeoutList[i]); \
  8432. } \
  8433. } \
  8434. \
  8435. function setIntervalCustom(func, tm, params) \
  8436. { \
  8437. var id = setInterval(func, tm, params); \
  8438. intervalList.push(id); \
  8439. return id; \
  8440. } \
  8441. \
  8442. function clearIntervalAll() \
  8443. { \
  8444. for (var i = 0; i < intervalList.length; i++) \
  8445. { \
  8446. clearInterval(intervalList[i]); \
  8447. } \
  8448. } \
  8449. \
  8450. function scrollToId(id, offset) \
  8451. { \
  8452. scrollToElement("#" + id, offset); \
  8453. } \
  8454. \
  8455. function scrollToElement(selector, offset) \
  8456. { \
  8457. if (typeof offset === "undefined") \
  8458. { \
  8459. offset = -20; \
  8460. } \
  8461. \
  8462. var ele = document.querySelector(selector); \
  8463. if (ele) \
  8464. { \
  8465. ele.scrollIntoView(true); \
  8466. window.scrollBy(0, offset); \
  8467. } \
  8468. } \
  8469. \
  8470. function getTimeMs() \
  8471. { \
  8472. return (new Date()).getTime(); \
  8473. } \
  8474. \
  8475. function registerHideSuggestion() \
  8476. { \
  8477. if (typeof hideSuggestionsBox !== "undefined" || (parent && parent.hideSuggestionsBox)) \
  8478. { \
  8479. document.addEventListener("keydown", function(e) \
  8480. { \
  8481. if (e.keyCode === 27) \
  8482. { \
  8483. if (parent) \
  8484. { \
  8485. parent.hideSuggestionsBox(); \
  8486. } \
  8487. else \
  8488. { \
  8489. hideSuggestionsBox(); \
  8490. } \
  8491. } \
  8492. return false; \
  8493. }); \
  8494. } \
  8495. } \
  8496. registerHideSuggestion(); \
  8497. \
  8498. function doubleClickHideSuggestion(ele) \
  8499. { \
  8500. var maxDiff = 3000; \
  8501. var msDiff = maxDiff; \
  8502. var isEdited = false; \
  8503. \
  8504. if (ele && ele.dataset) \
  8505. { \
  8506. msDiff = getTimeMs() - (ele.dataset.stshHideSuggestion || 0); \
  8507. isEdit = ele.dataset.stshTextEdited === "true"; \
  8508. } \
  8509. \
  8510. if (!isEdit || msDiff < maxDiff) \
  8511. { \
  8512. hideSuggestionsBox(); \
  8513. ele.dataset.stshHideSuggestion = 0; \
  8514. } \
  8515. else \
  8516. { \
  8517. ele.dataset.stshHideSuggestion = getTimeMs(); \
  8518. } \
  8519. } \
  8520. \
  8521. function clickToSelect(ele) \
  8522. { \
  8523. var range = document.createRange(); \
  8524. range.setStartBefore(ele.firstChild); \
  8525. range.setEndAfter(ele.lastChild); \
  8526. var sel = window.getSelection(); \
  8527. sel.removeAllRanges(); \
  8528. sel.addRange(range); \
  8529. } \
  8530. \
  8531. function syncUrlArray() \
  8532. { \
  8533. var strStart = "showSuggestionsBox( \'"; \
  8534. var strEnd = "\' ); return false;"; \
  8535. var strCur = "&list_id="; \
  8536. var strAll = "&endnext="; \
  8537. var regPos = /&list_id=\\d+&endnext=\\d+/g; \
  8538. var isEdit = false; \
  8539. var eleDivs = []; \
  8540. var urls = []; \
  8541. \
  8542. var pattUrlTimestamp = \
  8543. { \
  8544. type2: /\\&t=[0-9]{6,}/g, \
  8545. type4: /\\&[0-9]{6,}\\&/g, \
  8546. }; \
  8547. \
  8548. var trKeys = document.querySelectorAll("#keylist > table:nth-child(1) > tbody:nth-child(1) > tr"); \
  8549. for (var i = 0; i < trKeys.length; i++) \
  8550. { \
  8551. if (!trKeys[i].classList.contains("stsh_hidden")) \
  8552. { \
  8553. var eleDiv = trKeys[i].childNodes[0].childNodes[0]; \
  8554. if (typeof eleDiv.getAttribute !== "undefined" \
  8555. && eleDiv.getAttribute("onclick")) \
  8556. { \
  8557. eleDivs.push(eleDiv); \
  8558. } \
  8559. } \
  8560. } \
  8561. \
  8562. for (var i = 0, l = eleDivs.length; i < l; i++) \
  8563. { \
  8564. var evOld = eleDivs[i].getAttribute("onclick"); \
  8565. if (evOld) \
  8566. { \
  8567. var url = evOld.replace(strStart,"").replace(strEnd,"").replace(regPos,""); \
  8568. url = url + strCur + i + strAll + l; \
  8569. \
  8570. if (pattUrlTimestamp.type2.test(url)) \
  8571. { \
  8572. url = url.replace(pattUrlTimestamp.type2, ""); \
  8573. } \
  8574. if (pattUrlTimestamp.type4.test(url)) \
  8575. { \
  8576. url = url.replace(pattUrlTimestamp.type4, "&"); \
  8577. } \
  8578. \
  8579. urls.push(url); \
  8580. \
  8581. var evNew = strStart + url + strEnd; \
  8582. if (evOld !== evNew) \
  8583. { \
  8584. eleDivs[i].setAttribute("onclick", evNew); \
  8585. isEdit = true; \
  8586. } \
  8587. } \
  8588. } \
  8589. \
  8590. if (isEdit || typeof URLarray === "undefined" || URLarray.length !== urls.length) \
  8591. { \
  8592. URLarray = urls; \
  8593. } \
  8594. } \
  8595. \
  8596. function setFrameColor(color) \
  8597. { \
  8598. var frame = document.querySelector("div#suggestions_box iframe"); \
  8599. if (frame) \
  8600. { \
  8601. if (frame.style.backgroundColor !== color) \
  8602. { \
  8603. frame.style.setProperty("background-color", color, "important"); \
  8604. } \
  8605. } \
  8606. } \
  8607. \
  8608. function padZero(num, size) \
  8609. { \
  8610. return (1e15+num+"").slice(-size); \
  8611. } \
  8612. \
  8613. function doInstant() \
  8614. { \
  8615. var url = document.documentURI; \
  8616. \
  8617. /* Fix STS JS error */ \
  8618. setTimeoutCustom(function() \
  8619. { \
  8620. if (typeof hide_list === "undefined") \
  8621. { \
  8622. hide_list = function() { /*console.log("sts: hide_list");*/ }; \
  8623. } \
  8624. \
  8625. if (typeof changeIt === "undefined") \
  8626. { \
  8627. changeIt = function() { /*console.log("sts: changeIt");*/ }; \
  8628. } \
  8629. \
  8630. if (typeof getendnext === "undefined") \
  8631. { \
  8632. getendnext = function() { /*console.log("sts: getendnext");*/ return ""; }; \
  8633. } \
  8634. }, 1000); \
  8635. \
  8636. if (url.indexOf("user_activity.php") > -1) \
  8637. { \
  8638. setTimeoutCustom(function() \
  8639. { \
  8640. if (typeof $ !== "undefined") \
  8641. { \
  8642. /* Restore drawing progress */ \
  8643. $(".dial").css("display", "inline"); \
  8644. $(".dial").knob( \
  8645. { \
  8646. "draw": function() \
  8647. { \
  8648. $(this.i).val(this.cv + "%"); \
  8649. } \
  8650. }); \
  8651. } \
  8652. }, 500); \
  8653. } \
  8654. else if (url.indexOf("translate.php") > -1) \
  8655. { \
  8656. getsuggestionURL = function(urlno) \
  8657. { \
  8658. /* Overwrite STS to remove timestamp */ \
  8659. return URLarray[urlno]; \
  8660. }; \
  8661. \
  8662. var obTarget_sync = document.querySelector("#keylist_container"); \
  8663. if (obTarget_sync) \
  8664. { \
  8665. var tmOb_sync = -1; \
  8666. var obMu_sync = new MutationObserver(function(mutations) \
  8667. { \
  8668. mutations.forEach(function(mutation) \
  8669. { \
  8670. if (mutation.type !== "attributes" \
  8671. || mutation.target.tagName === "TR") \
  8672. { \
  8673. clearTimeout(tmOb_sync); \
  8674. tmOb_sync = setTimeoutCustom(function() \
  8675. { \
  8676. syncUrlArray(); \
  8677. /*console.log("syncUrlArray: " + tmOb_sync);*/ \
  8678. }, 50); \
  8679. } \
  8680. }); \
  8681. }); \
  8682. \
  8683. var obConfig_sync = { childList: true, subtree: true, attributes: true, attributeFilter: ["class"] }; \
  8684. obMu_sync.observe(obTarget_sync, obConfig_sync); \
  8685. } \
  8686. } \
  8687. else if (url.indexOf("suggestions.php") > -1) \
  8688. { \
  8689. if (parent !== window) \
  8690. { \
  8691. var main = document.querySelector("#suggestionmain"); \
  8692. if (main) \
  8693. { \
  8694. var styleCp = window.getComputedStyle(main); \
  8695. if (styleCp) \
  8696. { \
  8697. var color = styleCp.backgroundColor; \
  8698. parent.setFrameColor(color); \
  8699. } \
  8700. } \
  8701. } \
  8702. } \
  8703. \
  8704. window.addEventListener("beforeunload", function (e) \
  8705. { \
  8706. clearTimeoutAll(); \
  8707. clearIntervalAll(); \
  8708. }); \
  8709. \
  8710. } \
  8711. doInstant(); \
  8712. \
  8713. ';
  8714.  
  8715. var eleClientScript = document.createElement("script");
  8716. eleClientScript.innerHTML = clientScript;
  8717. document.head.appendChild(eleClientScript);
  8718. } // End client
  8719.  
  8720. attachOnReady(initStyle);
  8721. attachOnReady(client);
  8722. attachOnReady(main);
  8723.  
  8724. })();
  8725.  
  8726. // End