hwm_time_seconds

Время с секундами (by Demin)

  1. // ==UserScript==
  2. // @name hwm_time_seconds
  3. // @author Demin
  4. // @namespace Demin_95725
  5. // @description Время с секундами (by Demin)
  6. // @homepage https://greasyfork.org/users/1602-demin
  7. // @icon http://i.imgur.com/LZJFLgt.png
  8. // @version 3.2
  9. // @encoding utf-8
  10. // @include http://*heroeswm.ru/*
  11. // @include http://178.248.235.15/*
  12. // @include http://*lordswm.com/*
  13. // @exclude */rightcol.php*
  14. // @exclude */ch_box.php*
  15. // @exclude */chat*
  16. // @exclude */ticker.html*
  17. // @exclude */frames*
  18. // @exclude */brd.php*
  19. // @grant GM_deleteValue
  20. // @grant GM_getValue
  21. // @grant GM_listValues
  22. // @grant GM_setValue
  23. // @grant GM_addStyle
  24. // @grant GM_log
  25. // @grant GM_openInTab
  26. // ==/UserScript==
  27.  
  28. // (c) 2011-2014, demin ( http://www.heroeswm.ru/pl_info.php?id=15091 )
  29.  
  30. (function() {
  31.  
  32. var version = '3.2';
  33.  
  34.  
  35. if (typeof GM_getValue != 'function') {
  36. this.GM_getValue=function (key,def) {return localStorage[key] || def;};
  37. this.GM_setValue=function (key,value) {return localStorage[key]=value;};
  38. this.GM_deleteValue=function (key) {return delete localStorage[key];};
  39. }
  40.  
  41.  
  42. var script_num = 95725;
  43. var script_name = "hwm_time_seconds: Время с секундами (by Demin)";
  44. update_n(version,script_num,script_name);
  45.  
  46. var url_cur = location.href;
  47. var url = 'http://'+location.hostname+'/';
  48.  
  49.  
  50. if ( document.querySelector("body") ) {
  51.  
  52. if( !GM_getValue("95725_hwm_time_sec_add") ) GM_setValue("95725_hwm_time_sec_add" , '0');
  53. if( !GM_getValue("95725_time_error_gm") ) GM_setValue("95725_time_error_gm", '0');
  54. if( !GM_getValue("95725_time_error2_gm") ) GM_setValue("95725_time_error2_gm", '0');
  55. if( !GM_getValue("95725_last_synch_gm") ) GM_setValue("95725_last_synch_gm", '1318000000000');
  56.  
  57. var time_serv = /([^,]*)(, \d+ online.*)/;
  58. var time_top = /(\d+):(\d+), \d+ online/;
  59. var all_td = document.getElementsByTagName('td');
  60. var td_len = all_td.length;
  61. var td_i;
  62. var td_ih;
  63. var time_sec;
  64. var online;
  65. var hm;
  66.  
  67. for (var i=0; i<td_len; i++) {
  68. td_i = all_td[i];
  69. td_ih = td_i.innerHTML;
  70. if (td_ih.indexOf("<td")!=-1) {continue;}
  71. if (td_ih.search(time_top)!=-1) {
  72. online = (time_serv.exec(td_ih))[2];
  73. hm = time_top.exec(td_ih);
  74.  
  75. td_add = document.createElement( 'td' );
  76. td_add.setAttribute('align', 'right');
  77. td_add.setAttribute('id', 'jsset_ts');
  78. td_add.setAttribute('valign', 'bottom');
  79. td_add.setAttribute('width', '60');
  80. td_add.innerHTML="";
  81. td_i.parentNode.insertBefore(td_add, td_i);
  82. addEvent($("jsset_ts"), "click", settings);
  83.  
  84. if (Number(GM_getValue("95725_last_synch_gm", '0')) + 21600000 < (new Date().getTime())) { get_time(); }
  85. else if ( GM_getValue("95725_time_sec_gm") ) { show_time(); }
  86. else { get_time(); }
  87.  
  88. break;
  89. }
  90. }
  91.  
  92. }
  93.  
  94. function show_time() {
  95. time_sec = Number(GM_getValue("95725_time_sec_gm"));
  96.  
  97. // true time
  98. ct = Math.round( ((new Date().getTime())-time_sec)/1000 );
  99. dd = Math.floor( ct / 86400 );
  100. dh = Math.floor( ( ct - dd * 86400 ) / 3600 );
  101. dm = Math.floor( ( ct - dd * 86400 - dh * 3600 ) / 60 );
  102. ds = ct % 60;
  103.  
  104. if ( (dh!=hm[1]) || (dm-hm[2])>1 || hm[2]>dm ) {
  105. if ( (dh-hm[1]==1 || hm[1]-dh==23) && (hm[2]-dm==59) ) { showtop(td_i); }
  106. else {
  107. GM_setValue("95725_time_sec_gm", '');
  108. var err4 = Number(GM_getValue("95725_time_error2_gm"))+1;
  109. GM_setValue("95725_time_error2_gm", ''+err4);
  110. //alert(hm[1]+':'+hm[2]+' - '+dh+':'+dm+':'+ds);
  111. get_time();
  112. }
  113. }
  114. else { GM_setValue("95725_time_error2_gm", '0'); showtop(td_i); }
  115. }
  116.  
  117. function get_time() {
  118. if ( Number(GM_getValue("95725_time_error_gm"))<4 && Number(GM_getValue("95725_time_error2_gm"))<4 ) {
  119. if ( Number(GM_getValue("95725_last_synch_gm", '0')) + 60000 < (new Date().getTime()) ) {
  120. GM_setValue("95725_last_synch_gm", ''+(new Date().getTime()));
  121. var objXMLHttpReqTime = new XMLHttpRequest();
  122. objXMLHttpReqTime.open('GET', 'time.php' + '?rand=' + (Math.random()* 1000000), true);
  123. objXMLHttpReqTime.onreadystatechange = function() { handleHttpResponseTime(objXMLHttpReqTime); }
  124. objXMLHttpReqTime.send(null);
  125. } else {
  126. setTimeout(function() { get_time(); }, 60000);
  127. }
  128. }
  129. }
  130.  
  131. function handleHttpResponseTime(obj) {
  132. if (obj.readyState == 4 && obj.status == 200) {
  133. if ( sec_serv = /now (\d+)/.exec(obj.responseText) ) {
  134. // 1318550400000 75600000
  135. sec_serv = Number( sec_serv[1] ) * 1000 + Number( GM_getValue("95725_hwm_time_sec_add") ) * 1000 - 1318626000000;
  136. sec_serv = new Date().getTime() - sec_serv;
  137. GM_setValue("95725_time_sec_gm", '' + sec_serv);
  138. GM_setValue("95725_time_error_gm", '0');
  139. show_time();
  140. }
  141. else {
  142. var err3 = Number(GM_getValue("95725_time_error_gm"))+1;
  143. GM_setValue("95725_time_error_gm", ''+err3);
  144. setTimeout(function() { get_time(); }, 60000);
  145. }
  146. }
  147. }
  148.  
  149. function showtop(td_i) {
  150. ct = Math.round( ((new Date().getTime())-time_sec)/1000 );
  151. dd = Math.floor( ct / 86400 );
  152. dh = Math.floor( ( ct - dd * 86400 ) / 3600 );
  153. dm = Math.floor( ( ct - dd * 86400 - dh * 3600 ) / 60 );
  154. ds = ct % 60;
  155. td_i.innerHTML = dh + ':' + ( (dm < 10) ? '0' : '' ) + dm + ':' + ( (ds < 10) ? '0' : '') + ds + online;
  156. setTimeout(function() {showtop(td_i)}, 1000);
  157. }
  158.  
  159. function settings_close()
  160. {
  161. var bg = $('bgOverlay');
  162. var bgc = $('bgCenter');
  163. bg.parentNode.removeChild(bg);
  164. bgc.parentNode.removeChild(bgc);
  165. }
  166.  
  167. function settings()
  168. {
  169. var bg = $('bgOverlay');
  170. var bgc = $('bgCenter');
  171. var bg_height = ScrollHeight();
  172.  
  173. if ( !bg )
  174. {
  175. bg = document.createElement('div');
  176. document.body.appendChild( bg );
  177.  
  178. bgc = document.createElement('div');
  179. document.body.appendChild( bgc );
  180. }
  181.  
  182. bg.id = 'bgOverlay';
  183. bg.style.position = 'absolute';
  184. bg.style.left = '0px';
  185. bg.style.width = '100%';
  186. bg.style.background = "#000000";
  187. bg.style.opacity = "0.5";
  188. bg.style.zIndex = "7";
  189.  
  190. bgc.id = 'bgCenter';
  191. bgc.style.position = 'absolute';
  192. bgc.style.left = ( ( ClientWidth() - 650 ) / 2 ) + 'px';
  193. bgc.style.width = '650px';
  194. bgc.style.background = "#F6F3EA";
  195. bgc.style.zIndex = "8";
  196.  
  197. addEvent(bg, "click", settings_close);
  198.  
  199. if ( url.match('lordswm') ) {
  200.  
  201. var st_1 = 'Adding';
  202. var st_2 = 'second(s) to the sync (page load time from the server)';
  203. var st_3 = 'Restart the script';
  204. var st_author = 'Script author';
  205.  
  206. } else {
  207.  
  208. var st_1 = '\u0414\u043E\u0431\u0430\u0432\u043B\u044F\u0442\u044C';
  209. var st_2 = '\u0441\u0435\u043A\u0443\u043D\u0434(\u044B) \u043D\u0430 \u0441\u0438\u043D\u0445\u0440\u043E\u043D\u0438\u0437\u0430\u0446\u0438\u044E (\u0432\u0440\u0435\u043C\u044F \u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0438 \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u044B \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430)';
  210. var st_3 = '\u041F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u044C \u0441\u043A\u0440\u0438\u043F\u0442';
  211. var st_author = '\u0410\u0432\u0442\u043E\u0440 \u0441\u043A\u0440\u0438\u043F\u0442\u0430';
  212.  
  213. }
  214.  
  215. bgc.innerHTML = '<div style="border:1px solid #abc;padding:5px;margin:2px;"><div style="float:right;border:1px solid #abc;width:15px;height:15px;text-align:center;cursor:pointer;" id="bt_close_tr" title="Close">x</div><table>'+
  216. '<tr><td>'+st_1+' <input id="hwm_time_add" value="'+
  217. GM_getValue("95725_hwm_time_sec_add")+
  218. '" size="1" maxlength="2"> '+st_2+'</b> <input type="submit" id="hwm_time_add_ok" value="ok"><br><br></td></tr>'+
  219.  
  220. '<tr><td><input type="submit" id="ref48" value="'+st_3+'"></td></tr>'+
  221.  
  222. '</table><table width=100%>'+
  223. '<tr><td style="text-align:right">'+st_author+': <a href="pl_info.php?id=15091">Demin</a> <a href="javascript:void(0);" id="open_transfer_id">?</a></td></tr>'+
  224. '</table></div>';
  225.  
  226. addEvent($("bt_close_tr"), "click", settings_close);
  227. addEvent($("hwm_time_add_ok"), "click", hwm_time_add_f);
  228. addEvent($("ref48"), "click", ref48_f);
  229. addEvent($("open_transfer_id"), "click", open_transfer_f);
  230.  
  231. bg.style.top = '0px';
  232. bg.style.height = bg_height + 'px';
  233. bgc.style.top = ( window.pageYOffset + 150 ) + 'px';
  234. bg.style.display = '';
  235. bgc.style.display = '';
  236. }
  237.  
  238. function hwm_time_add_f()
  239. {
  240. if ( Number( $("hwm_time_add").value ) >= 0 ) {
  241. GM_setValue( "95725_hwm_time_sec_add" , '' + $("hwm_time_add").value );
  242. }
  243. }
  244.  
  245. function ref48_f()
  246. {
  247. GM_setValue("95725_time_error_gm", '0');
  248. GM_setValue("95725_time_error2_gm", '0');
  249. GM_setValue("95725_time_sec_gm", '');
  250. GM_setValue("95725_last_synch_gm", '');
  251. }
  252.  
  253. function open_transfer_f()
  254. {
  255. if ( location.href.match('lordswm') )
  256. {
  257. window.location = "transfer.php?nick=demin&shortcomment=Transferred 10000 Gold 5 Diamonds";
  258. } else {
  259. window.location = "transfer.php?nick=demin&shortcomment=%CF%E5%F0%E5%E4%E0%ED%EE%2010000%20%C7%EE%EB%EE%F2%EE%205%20%C1%F0%E8%EB%EB%E8%E0%ED%F2%FB";
  260. }
  261. }
  262.  
  263. function ClientHeight() {
  264. return document.compatMode=='CSS1Compat' && document.documentElement?document.documentElement.clientHeight:document.body.clientHeight;
  265. }
  266.  
  267. function ClientWidth() {
  268. return document.compatMode=='CSS1Compat' && document.documentElement?document.documentElement.clientWidth:document.body.clientWidth;
  269. }
  270.  
  271. function ScrollHeight() {
  272. return Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);
  273. }
  274.  
  275. function $(id) { return document.querySelector("#"+id); }
  276.  
  277. function addEvent(elem, evType, fn) {
  278. if (elem.addEventListener) {
  279. elem.addEventListener(evType, fn, false);
  280. }
  281. else if (elem.attachEvent) {
  282. elem.attachEvent("on" + evType, fn);
  283. }
  284. else {
  285. elem["on" + evType] = fn;
  286. }
  287. }
  288.  
  289. function update_n(a,b,c,d,e){if(e){e++}else{e=1;d=(Number(GM_getValue(b+'_update_script_last2','0'))||0)}if(e>3){return}var f=new Date().getTime();var g=document.querySelector('#update_demin_script2');if(g){if((d+86400000<f)||(d>f)){g=g.innerHTML;if(/100000=1.1/.exec(g)){var h=new RegExp(b+'=(\\d+\\.\\d+)=(\\d+)').exec(g);var i=/url7=([^%]+)/.exec(g);if(a&&h&&i){if(Number(h[1])>Number(a))setTimeout(function(){if(confirm('\u0414\u043E\u0441\u0442\u0443\u043F\u043D\u043E \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u0435 \u0441\u043A\u0440\u0438\u043F\u0442\u0430: "'+c+'".\n\u0423\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u044C \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u043D\u0443\u044E \u0432\u0435\u0440\u0441\u0438\u044E \u0441\u0435\u0439\u0447\u0430\u0441?\n\nThere is an update available for the script: "'+c+'".\nWould you like install the script now?')){if(typeof GM_openInTab=='function'){GM_openInTab(i[1].replace(/\s/g,'')+h[2])}else{window.open(i[1].replace(/\s/g,'')+h[2],'_blank')}}},500)}GM_setValue(b+'_update_script_last2',''+f)}else{setTimeout(function(){update_n(a,b,c,d,e)},1000)}}}else{var j=document.querySelector('body');if(j){var k=GM_getValue(b+'_update_script_array2');if(e==1&&((d+86400000<f)||(d>f)||!k)){if(k){GM_deleteValue(b+'_update_script_array2')}setTimeout(function(){update_n(a,b,c,d,e)},1000);return}var l=document.createElement('div');l.id='update_demin_script2';l.setAttribute('style','position: absolute; width: 0px; height: 0px; top: 0px; left: 0px; display: none;');l.innerHTML='';j.appendChild(l);if((d+86400000<f)||(d>f)||!k){var m=new XMLHttpRequest();m.open('GET','photo_pl_photos.php?aid=1777'+'&rand='+(Math.random()*100),true);m.onreadystatechange=function(){update(m,a,b,c,d,e)};m.send(null)}else{document.querySelector('#update_demin_script2').innerHTML=k;setTimeout(function(){update_n(a,b,c,d,e)},10)}}}}function update(a,b,c,d,e,f){if(a.readyState==4&&a.status==200){a=a.responseText;var g=/(\d+=\d+\.\d+(=\d+)*)/g;var h='';var i=/(url7=[^%]+\%)/.exec(a);if(i){h+=i[1]}while((i=g.exec(a))!=null){if(h.indexOf(i[1])==-1){h+=' '+i[1]}};GM_setValue(c+'_update_script_array2',''+h);var j=document.querySelector('#update_demin_script2');if(j){j.innerHTML=h;setTimeout(function(){update_n(b,c,d,e,f)},10)}}}
  290.  
  291. })();