ET Summary Timer

Displays crafting timers in Summary menu. Settings available in console via window.et_summaryTimer

  1. // ==UserScript==
  2. // @name ET Summary Timer
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.8
  5. // @description Displays crafting timers in Summary menu. Settings available in console via window.et_summaryTimer
  6. // @author Aes Sedai
  7. // @match http*://*.eternitytower.net/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Default settings, use window.et_summaryTimer in console to change settings
  15. // showCrafting: BOOLEAN, default: true; if true, shows a timer for crafting in summary list
  16. // showInscription: BOOLEAN, default: true; if true, shows a timer for inscription in summary list
  17. // showAdventure: BOOLEAN, default: true; if true, shows a timer for adventures in summary list
  18. // showReforging: BOOLEAN, default: true; if true, shows a timer for reforging in summary list
  19. // interval: INTEGER, default: 1000; time in millisecons to wait before refreshing timer
  20. window.et_summaryTimer = {
  21. showCrafting: true,
  22. showInscription: true,
  23. showAdventure: true,
  24. showReforging: true,
  25. interval: 1000
  26. };
  27.  
  28. if(localStorage.getItem('et_summaryTimer')) window.et_summaryTimer = Object.assign({}, window.et_summaryTimer, JSON.parse(localStorage.getItem('et_summaryTimer')));
  29.  
  30. $(window).on("beforeunload", function() {
  31. localStorage.setItem('et_summaryTimer', JSON.stringify(window.et_summaryTimer));
  32. });
  33.  
  34. function getTimeRemaining(endtime) {
  35. let t = Date.parse(endtime) - Date.parse(new Date());
  36. let seconds = Math.floor( (t/1000) % 60 );
  37. let minutes = Math.floor( (t/1000/60) % 60 );
  38. let hours = Math.floor( (t/(1000*60*60)) % 24 );
  39. let days = Math.floor( t/(1000*60*60*24) );
  40. return {
  41. 'total': t,
  42. 'days': days,
  43. 'hours': hours.toString().padStart(2, '0'),
  44. 'minutes': minutes.toString().padStart(2, '0'),
  45. 'seconds': seconds.toString().padStart(2, '0')
  46. };
  47. }
  48.  
  49. function formatTimeRemaining(time) {
  50. if(time.days > 0) return time.days + ":" + time.hours + ":" + time.minutes + ":" + time.seconds;
  51. if(time.hours > 0) return time.hours + ":" + time.minutes + ":" + time.seconds;
  52. if(time.minutes > 0) return time.minutes + ":" + time.seconds;
  53. if(time.seconds > 0) return "00:" + time.seconds;
  54. }
  55.  
  56. function cleanup(summary) {
  57. if($(summary.classSelector).length > 0) $(summary.classSelector).remove();
  58. }
  59.  
  60. let summaries = [
  61. {classSelector: ".crafting-timer", type: 'crafting', redis: Meteor.connection._mongo_livedata_collections.crafting.find(), rowSelector: ".summary-crafting", active: window.et_summaryTimer.showCrafting},
  62. {classSelector: ".inscription-timer", type: 'crafting', redis: Meteor.connection._mongo_livedata_collections.inscription.find(), rowSelector: ".summary-inscription", active: window.et_summaryTimer.showInscription},
  63. {classSelector: ".adventures-timer", type: 'adventure', redis: Meteor.connection._mongo_livedata_collections.adventures.find(), rowSelector: ".summary-adventures", active: window.et_summaryTimer.showAdventure},
  64. {classSelector: ".reforging-timer", type: 'reforging', redis: Meteor.connection._mongo_livedata_collections.crafting.find(), rowSelector: ".summary-reforging", active: window.et_summaryTimer.showReforging},
  65. ];
  66.  
  67. let interval = setInterval(function() {
  68. summaries.forEach(function(summary) {
  69. if(!summary.active) return;
  70. let elems = null;
  71. if(summary.type == 'crafting') {
  72. let fetch = summary.redis.fetch();
  73. if(fetch.length === 0) {
  74. cleanup(summary);
  75. return;
  76. }
  77. let currentlyCrafting = fetch[0].currentlyCrafting;
  78. if (currentlyCrafting.length === 0) {
  79. cleanup(summary);
  80. return;
  81. }
  82. let firstCraft = currentlyCrafting[0];
  83. if(!firstCraft.hasOwnProperty('endDate')) {
  84. cleanup(summary);
  85. return;
  86. }
  87. elems = currentlyCrafting;
  88. } else if(summary.type == 'adventure') {
  89. let fetch = summary.redis.fetch();
  90. if(fetch.length === 0) {
  91. cleanup(summary);
  92. return;
  93. }
  94. elems = fetch[0].adventures.filter((a) => !!a.startDate && !a.hasOwnProperty('win'));
  95. if(elems.length === 0) {
  96. cleanup(summary);
  97. return;
  98. }
  99. } else if(summary.type == 'reforging') {
  100. let fetch = summary.redis.fetch();
  101. if(fetch.length === 0) {
  102. cleanup(summary);
  103. return;
  104. }
  105. let currentlyReforging = fetch[0].currentlyReforging;
  106. if (currentlyReforging.length === 0) {
  107. cleanup(summary);
  108. return;
  109. }
  110. let firstReforge = currentlyReforging[0];
  111. if(!firstReforge.hasOwnProperty('endDate')) {
  112. cleanup(summary);
  113. return;
  114. }
  115. elems = currentlyReforging;
  116. }
  117.  
  118. if($(summary.classSelector).length > 0) {
  119. if(elems.length > 1) {
  120. $(summary.classSelector).html(formatTimeRemaining(getTimeRemaining(elems[0].endDate)) + " (" + formatTimeRemaining(getTimeRemaining(elems[elems.length - 1].endDate)) + ")");
  121. } else if(elems.length == 1) {
  122. $(summary.classSelector).html(formatTimeRemaining(getTimeRemaining(elems[0].endDate)));
  123. }
  124. } else if($(summary.rowSelector).length > 0) {
  125. let row = $(summary.rowSelector);
  126. let timeContainer = document.createElement("span");
  127. timeContainer.className = summary.classSelector.replace('.', '');
  128. timeContainer.style.cssText = 'padding-left: 6px;';
  129. if(elems.length > 1) {
  130. timeContainer.innerHTML = formatTimeRemaining(getTimeRemaining(elems[0].endDate) + " (" + formatTimeRemaining(getTimeRemaining(elems[elems.length - 1].endDate)) + ")");
  131. } else if(elems.length == 1) {
  132. timeContainer.innerHTML = formatTimeRemaining(getTimeRemaining(elems[0].endDate));
  133. }
  134.  
  135. row.after(timeContainer);
  136. }
  137. });
  138. }, window.et_summaryTimer.interval);
  139. })();