ET Summary Timer

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

目前为 2017-11-13 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name ET Summary Timer
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  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.secodns > 0) return time.seconds;
  50. }
  51.  
  52. var summaries = [
  53. {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(1)", active: window.et_summaryTimer.showCrafting},
  54. {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(2)", active: window.et_summaryTimer.showInscription}
  55. ];
  56.  
  57. var interval = setInterval(function() {
  58. summaries.forEach(function(summary) {
  59. if(!summary.active) return;
  60. if($(summary.classSelector).length > 0) {
  61. $(summary.classSelector).html(formatTimeRemaining(getTimeRemaining(summary.redis.fetch()[0].currentlyCrafting[0].endDate)));
  62. } else if($(summary.rowSelector).length > 0) {
  63. var row = $(summary.rowSelector);
  64. var timeContainer = document.createElement("span");
  65. timeContainer.className = summary.classSelector.replace('.', '');
  66. timeContainer.style.cssText = 'padding-left: 6px;';
  67. timeContainer.innerHTML = formatTimeRemaining(getTimeRemaining(summary.redis.fetch()[0].currentlyCrafting[0].endDate));
  68. row.after(timeContainer);
  69. }
  70. });
  71. }, window.et_summaryTimer.interval);
  72. })();