TW Fred Timer

Timer View for Event's free action

当前为 2016-03-23 提交的版本,查看 最新版本

  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.5
  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.5";
  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. if (cdl) // cuz no data at end of Event
  77. {
  78. ctime = cd[0].cdstamp
  79. var stime = Game.getServerTime();
  80. diff = ctime-stime;
  81. }
  82. }
  83. else if (cd.states !== undefined) // IndDay
  84. {
  85. cd = cd.states;
  86. cdl = Object.keys(cd).length;
  87. if (cdl)
  88. {
  89. ctime = cd[0].finish_date;
  90. var stime = Game.getServerTime();
  91. if (!ctime) ctime = stime;
  92. diff = ctime-stime;
  93. }
  94. }
  95. else {console.log('No Fred data'); TWFred.destroy(); return;} // no data
  96. if (!cdl) {console.log('No Fred length'); TWFred.destroy(); return;}
  97. TWFred.diff = diff;
  98. TWFredTimer();
  99. }
  100. ); //post
  101. };
  102. TWFred.showTimer = function()
  103. {
  104. var str = TWFred.diff.formatDuration();
  105. fcWrap.html(str);
  106. };
  107. TWFred.doTimer = function()
  108. {
  109. //console.log('doTimer:' + TWFred.execCount + ',' + TWFred.reInitVal);
  110. TWFred.timerId = 0;
  111. if (undefined === TWFred) return;
  112. if (!TWFred.clickObj) TWFred.getClicker(); // init clicker
  113. var diff = TWFred.diff - TWFred.timer;
  114. if (diff < 0) diff = 0;
  115. if (!diff) TWFred.reInitVal = TWFred.reInitValI;
  116. TWFred.diff = diff;
  117. TWFred.showTimer();
  118. TWFred.execCount++;
  119. if (TWFred.execCount > TWFred.reInitVal)
  120. {
  121. TWFred.init();
  122. }
  123. else
  124. {
  125. TWFredTimer();
  126. }
  127. };
  128. TWFred.getClicker = function()
  129. {
  130. if (TWFred.clickObj) return;
  131. var bar = WestUi.NotiBar.getBar();
  132. if (!bar) return;
  133. bar = bar.list;
  134. TWFred.reInitVal = TWFred.reInitValN;
  135. $.each(bar, function(key,val)
  136. {
  137. //console.log(val);
  138. if ((val.uid == 'easterwof')||(val.uid == 'independencewof'))
  139. {
  140. TWFred.clickObj = val.element;
  141. }
  142. });
  143. if (TWFred.clickObj) fcWrap.css("cursor","pointer");
  144. };
  145. TWFred.click = function()
  146. {
  147. if (!TWFred.clickObj) return;
  148. TWFred.init();
  149. TWFred.clickObj.click();
  150. };
  151. TWFred.destroy = function()
  152. {
  153. console.log('Removing TWFred');
  154. fcContainer.remove();
  155. delete TWFred;
  156. TWFred = undefined;
  157. };
  158. function TWFredTimer()
  159. {
  160. if (undefined === TWFred) return;
  161. if (!TWFred.timerId) TWFred.timerId = setTimeout(TWFred.doTimer,TWFred.timer * 1000);
  162. };
  163. TWFred.init();
  164. }
  165. );

QingJ © 2025

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