STS Helper

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

当前为 2018-03-21 提交的版本,查看 最新版本

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