hwm_time_seconds

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

目前为 2014-06-10 提交的版本。查看 最新版本

  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.0
  9. // @encoding utf-8
  10. // @include http://*heroeswm.ru/*
  11. // @include http://178.248.235.15/*
  12. // @include http://209.200.152.144/*
  13. // @include http://*lordswm.com/*
  14. // @exclude */rightcol.php*
  15. // @exclude */ch_box.php*
  16. // @exclude */chat*
  17. // @exclude */ticker.html*
  18. // @exclude */frames*
  19. // @exclude */brd.php*
  20. // ==/UserScript==
  21.  
  22. // (c) 2011-2014, demin ( http://www.heroeswm.ru/pl_info.php?id=15091 )
  23.  
  24. (function() {
  25.  
  26. var version = '3.0';
  27.  
  28.  
  29. if (!this.GM_getValue || (this.GM_getValue.toString && this.GM_getValue.toString().indexOf("not supported")>-1)) {
  30. this.GM_getValue=function (key,def) {
  31. return localStorage[key] || def;
  32. };
  33. this.GM_setValue=function (key,value) {
  34. return localStorage[key]=value;
  35. };
  36. this.GM_deleteValue=function (key) {
  37. return delete localStorage[key];
  38. };
  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. var string = /now (\d+)/;
  54. if( !GM_getValue("95725_time_error_gm") ) GM_setValue("95725_time_error_gm", '0');
  55. if( !GM_getValue("95725_time_error2_gm") ) GM_setValue("95725_time_error2_gm", '0');
  56. if( !GM_getValue("95725_last_synch_gm") ) GM_setValue("95725_last_synch_gm", '1318000000000');
  57.  
  58. var time_serv = /([^,]*)(, \d+ online.*)/;
  59. var time_top = /(\d+):(\d+), \d+ online/;
  60. var all_td = document.getElementsByTagName('td');
  61. var td_len = all_td.length;
  62. var td_i;
  63. var td_ih;
  64. var time_sec;
  65. var online;
  66. var hm;
  67.  
  68. for (var i=0; i<td_len; i++) {
  69. td_i = all_td[i];
  70. td_ih = td_i.innerHTML;
  71. if (td_ih.indexOf("<td")!=-1) {continue;}
  72. if (td_ih.search(time_top)!=-1) {
  73. online = (time_serv.exec(td_ih))[2];
  74. hm = time_top.exec(td_ih);
  75.  
  76. td_add = document.createElement( 'td' );
  77. td_add.setAttribute('align', 'right');
  78. td_add.setAttribute('id', 'jsset_ts');
  79. td_add.setAttribute('valign', 'bottom');
  80. td_add.setAttribute('width', '60');
  81. td_add.innerHTML="";
  82. td_i.parentNode.insertBefore(td_add, td_i);
  83. addEvent($("jsset_ts"), "click", settings);
  84.  
  85. if (parseInt(GM_getValue("95725_last_synch_gm", '0')) + 21600000 < (new Date().getTime())) { get_time(); }
  86. else if ( GM_getValue("95725_time_sec_gm") ) { show_time(); }
  87. else { get_time(); }
  88.  
  89. break;
  90. }
  91. }
  92.  
  93. }
  94.  
  95. function show_time() {
  96. time_sec = parseInt(GM_getValue("95725_time_sec_gm"));
  97.  
  98. // true time
  99. ct = Math.round( ((new Date().getTime())-time_sec)/1000 );
  100. dd = Math.floor( ct / 86400 );
  101. dh = Math.floor( ( ct - dd * 86400 ) / 3600 );
  102. dm = Math.floor( ( ct - dd * 86400 - dh * 3600 ) / 60 );
  103. ds = ct % 60;
  104.  
  105. if ( (dh!=hm[1]) || (dm-hm[2])>1 || hm[2]>dm ) {
  106. if ( (dh-hm[1]==1 || hm[1]-dh==23) && (hm[2]-dm==59) ) { showtop(td_i); }
  107. else {
  108. GM_setValue("95725_time_sec_gm", '');
  109. var err4 = parseInt(GM_getValue("95725_time_error2_gm"))+1;
  110. GM_setValue("95725_time_error2_gm", ''+err4);
  111. //alert(hm[1]+':'+hm[2]+' - '+dh+':'+dm+':'+ds);
  112. get_time();
  113. }
  114. }
  115. else { GM_setValue("95725_time_error2_gm", '0'); showtop(td_i); }
  116. }
  117.  
  118. function get_time() {
  119. if ( parseInt(GM_getValue("95725_time_error_gm"))<4 && parseInt(GM_getValue("95725_time_error2_gm"))<4 ) {
  120. if ( parseInt(GM_getValue("95725_last_synch_gm", '0')) + 60000 < (new Date().getTime()) ) {
  121. GM_setValue("95725_last_synch_gm", ''+(new Date().getTime()));
  122. var objXMLHttpReqTime = new XMLHttpRequest();
  123. objXMLHttpReqTime.open('GET', 'time.php' + '?rand=' + (Math.random()* 1000000), true);
  124. objXMLHttpReqTime.onreadystatechange = function() { handleHttpResponseTime(objXMLHttpReqTime); }
  125. objXMLHttpReqTime.send(null);
  126. } else {
  127. setTimeout(function() { get_time(); }, 60000);
  128. }
  129. }
  130. }
  131.  
  132. function handleHttpResponseTime(obj) {
  133. if (obj.readyState == 4 && obj.status == 200) {
  134. if (string.exec(obj.responseText)) {
  135. var sec_serv = string.exec(obj.responseText);
  136. // 1318550400000 72000000
  137. sec_serv = parseInt(sec_serv[1])*1000+parseInt(GM_getValue("95725_hwm_time_sec_add"))*1000-1318622400000;
  138. sec_serv = (new Date().getTime())-sec_serv;
  139. GM_setValue("95725_time_sec_gm", ''+sec_serv);
  140. GM_setValue("95725_time_error_gm", '0');
  141. show_time();
  142. }
  143. else {
  144. var err3 = parseInt(GM_getValue("95725_time_error_gm"))+1;
  145. GM_setValue("95725_time_error_gm", ''+err3);
  146. setTimeout(function() { get_time(); }, 60000);
  147. }
  148. }
  149. }
  150.  
  151. function showtop(td_i) {
  152. ct = Math.round( ((new Date().getTime())-time_sec)/1000 );
  153. dd = Math.floor( ct / 86400 );
  154. dh = Math.floor( ( ct - dd * 86400 ) / 3600 );
  155. dm = Math.floor( ( ct - dd * 86400 - dh * 3600 ) / 60 );
  156. ds = ct % 60;
  157. td_i.innerHTML = dh + ':' + ( (dm < 10) ? '0' : '' ) + dm + ':' + ( (ds < 10) ? '0' : '') + ds + online;
  158. setTimeout(function() {showtop(td_i)}, 1000);
  159. }
  160.  
  161. function settings_close()
  162. {
  163. var bg = $('bgOverlay');
  164. var bgc = $('bgCenter');
  165. bg.parentNode.removeChild(bg);
  166. bgc.parentNode.removeChild(bgc);
  167. }
  168.  
  169. function settings()
  170. {
  171. var bg = $('bgOverlay');
  172. var bgc = $('bgCenter');
  173. var bg_height = ScrollHeight();
  174.  
  175. if ( !bg )
  176. {
  177. bg = document.createElement('div');
  178. document.body.appendChild( bg );
  179.  
  180. bgc = document.createElement('div');
  181. document.body.appendChild( bgc );
  182. }
  183.  
  184. bg.id = 'bgOverlay';
  185. bg.style.position = 'absolute';
  186. bg.style.left = '0px';
  187. bg.style.width = '100%';
  188. bg.style.background = "#000000";
  189. bg.style.opacity = "0.5";
  190. bg.style.zIndex = "7";
  191.  
  192. bgc.id = 'bgCenter';
  193. bgc.style.position = 'absolute';
  194. bgc.style.left = ( ( ClientWidth() - 650 ) / 2 ) + 'px';
  195. bgc.style.width = '650px';
  196. bgc.style.background = "#F6F3EA";
  197. bgc.style.zIndex = "8";
  198.  
  199. addEvent(bg, "click", settings_close);
  200.  
  201. if ( url.match('lordswm') ) {
  202.  
  203. var st_1 = 'Adding';
  204. var st_2 = 'second(s) to the sync (page load time from the server)';
  205. var st_3 = 'Restart the script';
  206. var st_author = 'Script author';
  207.  
  208. } else {
  209.  
  210. var st_1 = '\u0414\u043E\u0431\u0430\u0432\u043B\u044F\u0442\u044C';
  211. 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)';
  212. var st_3 = '\u041F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u044C \u0441\u043A\u0440\u0438\u043F\u0442';
  213. var st_author = '\u0410\u0432\u0442\u043E\u0440 \u0441\u043A\u0440\u0438\u043F\u0442\u0430';
  214.  
  215. }
  216.  
  217. 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>'+
  218. '<tr><td>'+st_1+' <input id="hwm_time_add" value="'+
  219. GM_getValue("95725_hwm_time_sec_add")+
  220. '" size="1" maxlength="2"> '+st_2+'</b> <input type="submit" id="hwm_time_add_ok" value="ok"><br><br></td></tr>'+
  221.  
  222. '<tr><td><input type="submit" id="ref48" value="'+st_3+'"></td></tr>'+
  223.  
  224. '</table><table width=100%>'+
  225. '<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>'+
  226. '</table></div>';
  227.  
  228. addEvent($("bt_close_tr"), "click", settings_close);
  229. addEvent($("hwm_time_add_ok"), "click", hwm_time_add_f);
  230. addEvent($("ref48"), "click", ref48_f);
  231. addEvent($("open_transfer_id"), "click", open_transfer_f);
  232.  
  233. bg.style.top = '0px';
  234. bg.style.height = bg_height + 'px';
  235. bgc.style.top = ( window.pageYOffset + 150 ) + 'px';
  236. bg.style.display = '';
  237. bgc.style.display = '';
  238. }
  239.  
  240. function hwm_time_add_f()
  241. {
  242. if ( Number( $("hwm_time_add").value ) >= 0 ) {
  243. GM_setValue( "95725_hwm_time_sec_add" , '' + $("hwm_time_add").value );
  244. }
  245. }
  246.  
  247. function ref48_f()
  248. {
  249. GM_setValue("95725_time_error_gm", '0');
  250. GM_setValue("95725_time_error2_gm", '0');
  251. GM_setValue("95725_time_sec_gm", '');
  252. GM_setValue("95725_last_synch_gm", '');
  253. }
  254.  
  255. function open_transfer_f()
  256. {
  257. if ( location.href.match('lordswm') )
  258. {
  259. window.location = "transfer.php?nick=demin&shortcomment=Transferred 10000 Gold 5 Diamonds";
  260. } else {
  261. 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";
  262. }
  263. }
  264.  
  265. function ClientHeight() {
  266. return document.compatMode=='CSS1Compat' && document.documentElement?document.documentElement.clientHeight:document.body.clientHeight;
  267. }
  268.  
  269. function ClientWidth() {
  270. return document.compatMode=='CSS1Compat' && document.documentElement?document.documentElement.clientWidth:document.body.clientWidth;
  271. }
  272.  
  273. function ScrollHeight() {
  274. return Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);
  275. }
  276.  
  277. function $(id) { return document.querySelector("#"+id); }
  278.  
  279. function addEvent(elem, evType, fn) {
  280. if (elem.addEventListener) {
  281. elem.addEventListener(evType, fn, false);
  282. }
  283. else if (elem.attachEvent) {
  284. elem.attachEvent("on" + evType, fn);
  285. }
  286. else {
  287. elem["on" + evType] = fn;
  288. }
  289. }
  290.  
  291. 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)}}}
  292.  
  293. })();