STS Helper

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

当前为 2018-05-29 提交的版本,查看 最新版本

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