STS Helper

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

目前為 2018-03-24 提交的版本,檢視 最新版本

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