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 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         GC Sidebar Timezone and Remaining Time
// @namespace    http://tampermonkey.net/
// @version      0.3
// @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.
// @author       Twiggies
// @match        *://www.grundos.cafe/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
// @grant        none
// @license      MIT
// ==/UserScript==

//MINUTES remaining before quest text will be highlighted red as a warning. Set to -1 to disable this.
const warningTime = 15;

function getOffsetBetweenTimezonesForDate(date, timezone1, timezone2) {
  const timezone1Date = convertDateToAnotherTimeZone(date, timezone1);
  const timezone2Date = convertDateToAnotherTimeZone(date, timezone2);
  return timezone1Date.getTime() - timezone2Date.getTime();
}

function convertDateToAnotherTimeZone(date, timezone) {
  const dateString = date.toLocaleString('en-US', {
    timeZone: timezone
  });
  return new Date(dateString);
}

let offset = getOffsetBetweenTimezonesForDate(new Date(), 'America/Tijuana', Intl.DateTimeFormat().resolvedOptions().timeZone);

let rightMeow = new Date()
let nowTime = new Date(1970, 1, 1, rightMeow.getHours(), rightMeow.getMinutes())

const questTimeList = document.querySelectorAll('span.aio-subtext'); //#aio_sidebar div.quests div.aioImg div span.aio-subtext

for (let i = 0; i < questTimeList.length; i++) {
    //First remove the word 'next: ' from it just in case, and also 'nst'
    let timeText = questTimeList[i].innerText.replace('next: ', '').replace('nst','').trim();
    //Now split it.
    let splitTime = timeText.split(/[\s:]+/)

    //If time can't be parsed as a Number then skip this. ie Faerie quests don;t display times, just names
    if (!Number(splitTime[0])) {
        continue;
    }
    //[0] = Hour, [1] = minutes, [2] = am/pm
    if (splitTime[2] == 'pm' && splitTime[0] != 12) {
        //Add 12 hours to the hour if it's pm but not 12.
        splitTime[0] = Number(splitTime[0]) + 12;
    }
    let questTime = new Date(1970, 1, 1, splitTime[0], splitTime[1])
    let localTime = new Date(questTime.getTime() - offset);


    questTimeList[i].innerText = localTime.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });

    var diffMs = (localTime - nowTime); // milliseconds between server time and goal time
    var diffHrs = Math.floor((diffMs % 86400000) / 3600000); // hours
    var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes

    const totalMinutes = (diffHrs*60) + diffMins;
    const timeTo = (diffHrs > 0 ? diffHrs + " hr " + (diffHrs == 1 ? "" : "s ") : "") + diffMins + " mins";
    questTimeList[i].insertAdjacentHTML('beforeend',`<br style="display:block;"><span style="font-size:0.75em">${timeTo}</span>`);

    //If this is a quest item.. Mark the text red is there is less than x mins until the thing.
    if (questTimeList[i].closest('div.quests')) {
        if (totalMinutes <= warningTime) {
            questTimeList[i].style.color = 'red';
        }
    }

}