GC Sidebar Timezone and Remaining Time

Changes the times of stuff in the aio sidebar to both be user's local timezone, adds how many hours/minutes until that time, and highlights quest timers if less than 15 mins remain.

当前为 2023-11-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GC Sidebar Timezone and Remaining Time
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.22
  5. // @description Changes the times of stuff in the aio sidebar to both be user's local timezone, adds how many hours/minutes until that time, and highlights quest timers if less than 15 mins remain.
  6. // @author Twiggies
  7. // @match *://www.grundos.cafe/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. //MINUTES remaining before quest text will be highlighted red as a warning. Set to -1 to disable this.
  14. const warningTime = 15;
  15.  
  16. function getOffsetBetweenTimezonesForDate(date, timezone1, timezone2) {
  17. const timezone1Date = convertDateToAnotherTimeZone(date, timezone1);
  18. const timezone2Date = convertDateToAnotherTimeZone(date, timezone2);
  19. return timezone1Date.getTime() - timezone2Date.getTime();
  20. }
  21.  
  22. function convertDateToAnotherTimeZone(date, timezone) {
  23. const dateString = date.toLocaleString('en-US', {
  24. timeZone: timezone
  25. });
  26. return new Date(dateString);
  27. }
  28.  
  29. let offset = getOffsetBetweenTimezonesForDate(new Date(), 'America/Tijuana', Intl.DateTimeFormat().resolvedOptions().timeZone);
  30.  
  31. let rightMeow = new Date()
  32. let nowTime = new Date(1970, 1, 1, rightMeow.getHours(), rightMeow.getMinutes())
  33.  
  34. const questTimeList = document.querySelectorAll('span.aio-subtext'); //#aio_sidebar div.quests div.aioImg div span.aio-subtext
  35.  
  36. for (let i = 0; i < questTimeList.length; i++) {
  37. //First remove the word 'next: ' from it just in case, and also 'nst'
  38. let timeText = questTimeList[i].innerText.replace('next: ', '').replace('nst','').trim();
  39. //Now split it.
  40. let splitTime = timeText.split(/[\s:]+/)
  41.  
  42. //If time can't be parsed as a Number then skip this. ie Faerie quests don;t display times, just names
  43. if (!Number(splitTime[0])) {
  44. continue;
  45. }
  46. //[0] = Hour, [1] = minutes, [2] = am/pm
  47. if (splitTime[2] == 'pm') {
  48. //Add 12 hours to the hour if it's pm
  49. splitTime[0] = Number(splitTime[0]) + 12;
  50. }
  51. let questTime = new Date(1970, 1, 1, splitTime[0], splitTime[1])
  52. let localTime = new Date(questTime.getTime() - offset);
  53.  
  54.  
  55. questTimeList[i].innerText = localTime.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
  56.  
  57. var diffMs = (localTime - nowTime); // milliseconds between server time and goal time
  58. var diffHrs = Math.floor((diffMs % 86400000) / 3600000); // hours
  59. var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes
  60.  
  61. const totalMinutes = (diffHrs*60) + diffMins;
  62. const timeTo = (diffHrs > 0 ? diffHrs + " hr " + (diffHrs == 1 ? "" : "s ") : "") + diffMins + " mins";
  63. questTimeList[i].insertAdjacentHTML('beforeend',`<br style="display:block;"><span style="font-size:0.75em">${timeTo}</span>`);
  64.  
  65. //If this is a quest item.. Mark the text red is there is less than x mins until the thing.
  66. if (questTimeList[i].closest('div.quests')) {
  67. if (totalMinutes <= warningTime) {
  68. questTimeList[i].style.color = 'red';
  69. }
  70. }
  71.  
  72. }