Skip to content

Instantly share code, notes, and snippets.

@keyosk
Last active January 11, 2023 00:49
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keyosk/eba5c295b4960f31ee0bfbae044e94b9 to your computer and use it in GitHub Desktop.
Save keyosk/eba5c295b4960f31ee0bfbae044e94b9 to your computer and use it in GitHub Desktop.
GDQ Schedule Page Current Run Reloader

Games Done Quick Schedule Enhancements

This script1 will allow you to click the name of a game and it will open the corresponding Speed Run Listings for the game

Footnotes

  1. Using the tampermonkey browser extension you can add a custom user script which runs on the Games Done Quick schedule page.

// ==UserScript==
// @name Games Done Quick Schedule Enhancements
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Get latest at: https://gist.github.com/keyosk/eba5c295b4960f31ee0bfbae044e94b9
// @author Keyosk
// @match https://gamesdonequick.com/schedule
// @grant GM_xmlhttpRequest
// @grant GM_openInTab
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_addStyle
// @grant GM_notification
// @connect www.speedrun.com
// ==/UserScript==
// Maximum query string size for speedrun.com queries
let MAX_QUERY_LENGTH = 29;
let SEARCH_BASE = 'https://www.speedrun.com/';
let SEARCH_URL = SEARCH_BASE + 'ajax_search.php?term=';
let LOCAL_STORAGE_PREFIX = 'slug_';
let BLANK_SLUG = ' ';
if (document.location.hash != '#current') {
document.location.hash = 'current';
}
function openSlug(term, slug) {
if (slug) {
GM_openInTab(SEARCH_BASE + slug, {active: true, setParent: true});
if (slug === BLANK_SLUG) {
GM_notification({
text: "Unable to find the game: " + decodeURIComponent(term),
title: "SpeedRun.com Lookup Failure",
});
}
} else {
// Likely here due to a second click while results were loading
}
}
GM_addStyle('.runName:hover { color: #08a; text-decoration: underline; cursor: pointer; }');
$('#runTable > tbody:nth-child(2) > tr:not(".second-row") > td:nth-child(2):has(~ td > i.fa-clock-o)').each((_, element) => {
// Make sure we can get some styling on our new links
element.className = element.className + " runName";
let clicked = false;
$(element).click(event => {
// Pull a searchable term out of the game name
let term = encodeURIComponent(event.target.textContent.trim().replace(/^BONUS GAME [0-9]+ \- /, '').substring(0, MAX_QUERY_LENGTH));
// It's possible we've already searched for and found a slug in the past, let's look for it
let slug = GM_getValue(LOCAL_STORAGE_PREFIX + term, null);
if (slug || clicked) {
openSlug(term, slug);
// Prevent a second click from searching a second time
return;
}
clicked = true;
// Query Speedrun.com for the slug for the game name
GM_xmlhttpRequest({
method: 'GET',
url: SEARCH_URL + term,
onload: function(response) {
try {
let games = JSON.parse(response.responseText).filter(item => item && item.category == "Games");
if (games && games.length > 0 && games[0] && games[0].url) {
slug = games[0].url;
} else {
slug = BLANK_SLUG;
}
} catch (_) {
slug = BLANK_SLUG;
}
GM_setValue(LOCAL_STORAGE_PREFIX + term, slug);
openSlug(term, slug);
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment