ET Summary Timer

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

当前为 2019-02-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name ET Summary Timer
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  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. // interval: INTEGER, default: 1000; time in millisecons to wait before refreshing timer
  18. window.et_summaryTimer = {
  19. showCrafting: true,
  20. showInscription: true,
  21. interval: 1000
  22. };
  23.  
  24. if(localStorage.getItem('et_summaryTimer')) window.et_summaryTimer = Object.assign({}, window.et_summaryTimer, JSON.parse(localStorage.getItem('et_summaryTimer')));
  25.  
  26. $(window).on("beforeunload", function() {
  27. localStorage.setItem('et_summaryTimer', JSON.stringify(window.et_summaryTimer));
  28. });
  29.  
  30. function getTimeRemaining(endtime) {
  31. var t = Date.parse(endtime) - Date.parse(new Date());
  32. var seconds = Math.floor( (t/1000) % 60 );
  33. var minutes = Math.floor( (t/1000/60) % 60 );
  34. var hours = Math.floor( (t/(1000*60*60)) % 24 );
  35. var days = Math.floor( t/(1000*60*60*24) );
  36. return {
  37. 'total': t,
  38. 'days': days,
  39. 'hours': hours.toString().padStart(2, '0'),
  40. 'minutes': minutes.toString().padStart(2, '0'),
  41. 'seconds': seconds.toString().padStart(2, '0')
  42. };
  43. }
  44.  
  45. function formatTimeRemaining(time) {
  46. if(time.days > 0) return time.days + ":" + time.hours + ":" + time.minutes + ":" + time.seconds;
  47. if(time.hours > 0) return time.hours + ":" + time.minutes + ":" + time.seconds;
  48. if(time.minutes > 0) return time.minutes + ":" + time.seconds;
  49. if(time.seconds > 0) return "00:" + time.seconds;
  50. }
  51.  
  52. function cleanup(summary) {
  53. if($(summary.classSelector).length > 0) $(summary.classSelector).remove();
  54. }
  55.  
  56. var summaries = [
  57. {classSelector: ".crafting-timer", redis: Meteor.connection._mongo_livedata_collections.crafting.find(), rowSelector: "#content > div.d-sm-flex.flex-grow > div.hidden-lg-down > div > div:nth-of-type(3)", active: window.et_summaryTimer.showCrafting},
  58. {classSelector: ".inscription-timer", redis: Meteor.connection._mongo_livedata_collections.inscription.find(), rowSelector: "#content > div.d-sm-flex.flex-grow > div.hidden-lg-down > div > div:nth-of-type(4)", active: window.et_summaryTimer.showInscription}
  59. ];
  60.  
  61. var interval = setInterval(function() {
  62. summaries.forEach(function(summary) {
  63. if(!summary.active) return;
  64. var fetch = summary.redis.fetch();
  65. if(fetch.length === 0) {
  66. cleanup(summary);
  67. return;
  68. }
  69. var currentlyCrafting = fetch[0].currentlyCrafting;
  70. if (currentlyCrafting.length === 0) {
  71. cleanup(summary);
  72. return;
  73. }
  74. var firstCraft = currentlyCrafting[0];
  75. if(!firstCraft.hasOwnProperty('endDate')) {
  76. cleanup(summary);
  77. return;
  78. }
  79. if($(summary.classSelector).length > 0) {
  80. $(summary.classSelector).html(formatTimeRemaining(getTimeRemaining(firstCraft.endDate)) + " (" + formatTimeRemaining(getTimeRemaining(currentlyCrafting[currentlyCrafting.length - 1].endDate)) + ")");
  81. } else if($(summary.rowSelector).length > 0) {
  82. var row = $(summary.rowSelector);
  83. var timeContainer = document.createElement("span");
  84. timeContainer.className = summary.classSelector.replace('.', '');
  85. timeContainer.style.cssText = 'padding-left: 6px;';
  86. timeContainer.innerHTML = formatTimeRemaining(getTimeRemaining(firstCraft.endDate) + " (" + formatTimeRemaining(getTimeRemaining(currentlyCrafting[currentlyCrafting.length - 1].endDate)) + ")");
  87. row.after(timeContainer);
  88. }
  89. });
  90. }, window.et_summaryTimer.interval);
  91. })();