TW Fred Timer

Timer View for Event's free action

  1. // ==UserScript==
  2. // @name TW Fred Timer
  3. // @name:ru TW Fred Timer
  4. // @namespace TW Fred Timer
  5. // @description Timer View for Event's free action
  6. // @description:ru Счетчик времени бесплатного события Праздника
  7. // @include http://*.the-west.*/game.php*
  8. // @include https://*.the-west.*/game.php*
  9.  
  10. // @version 0.5.7
  11. // @grant none
  12.  
  13. // ==/UserScript==
  14.  
  15.  
  16. function TWFredScript(fn) {
  17. var script = document.createElement('script');
  18. script.setAttribute("type", "application/javascript");
  19. script.textContent = '(' + fn + ')();';
  20. document.body.appendChild(script);
  21. document.body.removeChild(script);
  22. }
  23.  
  24. TWFredScript(function() {
  25. var VERSION = "0.5.7";
  26. var NAME = "TW Fred Timer";
  27. var installURL = '';
  28.  
  29. console.log(NAME + ' ' + VERSION + ' : start...');
  30. fcContainer = $("<div />",
  31. {
  32. id: "twfred_container",
  33. //2015 style: "position: absolute; top: 64px; right: 50%; margin-right: 140px; z-index: 10; width: 142px; height: 16px; background: url('/images/interface/character/character.png') no-repeat scroll left -160px transparent;"
  34. style: "position: absolute; top: 64px; left: 50%; margin-left: 140px; z-index: 10; width: 142px; height: 16px; background: url('/images/interface/character/character.png') no-repeat scroll left -160px transparent;"
  35. }
  36. );
  37. fcContainer.appendTo("#user-interface");
  38. fcWrap = $('<div />',
  39. {
  40. id: "twfred_wrap",
  41. style:"padding-top:1px; font-size:10px; color:#FFF; text-align:center;",
  42. }
  43. );
  44. fcContainer.append(fcWrap);
  45. TWFred = {
  46. wofid:13, // don't know where find it //2015 =2, 2016 =13
  47. diff: 0,
  48. timer:2, // seconds
  49. execCount:0,
  50. reInitVal:60, // execs to reinit data - on start
  51. reInitValN:60, // execs to reinit data - on normal work
  52. reInitValI:7, // execs to reinit data - on zero Timer
  53. clickObj: null,
  54. timerId: 0,
  55. };
  56. fcWrap.click(function(){TWFred.click()});
  57. TWFred.init = function()
  58. {
  59. TWFred.execCount = 0;
  60. TWFred.reInitVal = TWFred.reInitValN;
  61. TWFred.getClicker();
  62. $.post("/game.php?window=wheeloffortune&mode=init", {wofid:TWFred.wofid},
  63. function(data)
  64. {
  65. var diff = 0;
  66. var ctime = 0;
  67. var cdl = 0;
  68. //console.log(data);
  69. if (data.error) {TWFred.destroy(); return;}
  70. var diff = 0;
  71. var cd = data.mode;
  72. if (cd.cooldowns !== undefined) // FRED
  73. {
  74. cd = cd.cooldowns;
  75. //cdl = cd.length;
  76. cdl = cd[0];
  77. if (cdl !== undefined) // cuz no data at end of Event
  78. {
  79. ctime = cdl.cdstamp
  80. var stime = Game.getServerTime();
  81. diff = ctime-stime;
  82. }
  83. }
  84. else if (cd.states !== undefined) // IndDay
  85. {
  86. cd = cd.states;
  87. cdl = Object.keys(cd).length;
  88. if (cdl)
  89. {
  90. ctime = cd[0].finish_date;
  91. var stime = Game.getServerTime();
  92. if (!ctime) ctime = stime;
  93. diff = ctime-stime;
  94. }
  95. }
  96. else {console.log('No Fred data'); TWFred.destroy(); return;} // no data
  97. if (!cdl) {console.log('No Fred cooldowns'); TWFred.destroy(); return;}
  98. TWFred.diff = diff;
  99. TWFredTimer();
  100. }
  101. ); //post
  102. };
  103. TWFred.showTimer = function()
  104. {
  105. var str = TWFred.diff.formatDuration();
  106. fcWrap.html(str);
  107. };
  108. TWFred.doTimer = function()
  109. {
  110. //console.log('doTimer:' + TWFred.execCount + ',' + TWFred.reInitVal);
  111. TWFred.timerId = 0;
  112. if (undefined === TWFred) return;
  113. if (!TWFred.clickObj) TWFred.getClicker(); // init clicker
  114. var diff = TWFred.diff - TWFred.timer;
  115. if (diff < 0) diff = 0;
  116. if (!diff) TWFred.reInitVal = TWFred.reInitValI;
  117. TWFred.diff = diff;
  118. TWFred.showTimer();
  119. TWFred.execCount++;
  120. if (TWFred.execCount > TWFred.reInitVal)
  121. {
  122. TWFred.init();
  123. }
  124. else
  125. {
  126. TWFredTimer();
  127. }
  128. };
  129. TWFred.getClicker = function()
  130. {
  131. if (TWFred.clickObj) return;
  132. var bar = WestUi.NotiBar.getBar();
  133. if (!bar) return;
  134. bar = bar.list;
  135. TWFred.reInitVal = TWFred.reInitValN;
  136. $.each(bar, function(key,val)
  137. {
  138. //console.log(val);
  139. if ((val.uid == 'easterwof')||(val.uid == 'independencewof'))
  140. {
  141. TWFred.clickObj = val.element;
  142. }
  143. });
  144. if (TWFred.clickObj) fcWrap.css("cursor","pointer");
  145. };
  146. TWFred.click = function()
  147. {
  148. if (!TWFred.clickObj) return;
  149. TWFred.init();
  150. TWFred.clickObj.click();
  151. };
  152. TWFred.destroy = function()
  153. {
  154. console.log('Removing TWFred');
  155. fcContainer.remove();
  156. delete TWFred;
  157. TWFred = undefined;
  158. };
  159. function TWFredTimer()
  160. {
  161. if (undefined === TWFred) return;
  162. if (!TWFred.timerId) TWFred.timerId = setTimeout(TWFred.doTimer,TWFred.timer * 1000);
  163. };
  164. TWFred.init();
  165. }
  166. );

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址