Last active
June 30, 2022 22:58
-
-
Save awsr/f877738341d75894115ac5b2f483b15b to your computer and use it in GitHub Desktop.
Copy the scheduled start time for Games Done Quick runs as a Unix timestamp.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name GDQ Schedule to Unix Timestamp | |
// @namespace https://gist.github.com/awsr | |
// @version 0.1.1 | |
// @description Copy time to unix timestamp (ctrl + doubleclick on row) | |
// @author Tenosis | |
// @downloadURL https://gist.github.com/awsr/f877738341d75894115ac5b2f483b15b/raw/GDQ_Schedule_to_Unix_Timestamp.user.js | |
// @match https://gamesdonequick.com/schedule | |
// @grant none | |
// ==/UserScript== | |
(() => { | |
'use strict'; | |
const tableBody = document.querySelector("#runTable tBody"); | |
const monthArray = ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"]; | |
function getYear() { | |
try { | |
const title = document.querySelector("h1"); | |
const yearData = title.innerText.match(/\d+/); | |
return parseInt(yearData[0]); | |
} | |
catch { | |
// Fallback use current year | |
return new Date().getFullYear(); | |
} | |
} | |
function getMonthDay(cursor) { | |
while (!cursor.classList.contains("day-split")) { | |
cursor = cursor.previousElementSibling; | |
if (!(cursor instanceof HTMLTableRowElement)) { | |
throw "Table cursor for date out of range!"; | |
} | |
} | |
const dateData = cursor.innerText.match(/(\w+)\s(\d+)/); | |
const day = parseInt(dateData[2]); | |
const mIdx = monthArray.indexOf(dateData[1].toLowerCase()); | |
if (mIdx === -1) { | |
throw "Invalid month"; | |
} | |
return [mIdx, day]; | |
} | |
function getHourMinute(current) { | |
current = current.querySelector(".start-time"); | |
if (current) { | |
const timeData = current.innerText.match(/(\d+):(\d+).*([AP]M)/i); | |
if (timeData) { | |
const hours = parseInt(timeData[1]) + (timeData[3].toLowerCase() === "pm" ? 12 : 0); | |
const minutes = parseInt(timeData[2]); | |
return [hours, minutes]; | |
} | |
else { | |
throw "Time format unknown"; | |
} | |
} | |
else { | |
throw "Time not found"; | |
} | |
} | |
function handler(event) { | |
if (event.ctrlKey) { | |
let row = event.target.closest("tr"); | |
if (!row.classList.contains("day-split")) { | |
if (row.classList.contains("second-row")) { | |
row = row.previousElementSibling; | |
} | |
const [monthIndex, day] = getMonthDay(row); | |
const [hours, minutes] = getHourMinute(row); | |
const timestamp = new Date(getYear(), monthIndex, day, hours, minutes); | |
navigator.clipboard.writeText(Math.floor(timestamp.valueOf() / 1000)); | |
} | |
} | |
} | |
if (tableBody) { | |
tableBody.addEventListener("dblclick", handler); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment