Skip to content

Instantly share code, notes, and snippets.

@brubsby
Last active December 15, 2020 00:25
Show Gist options
  • Save brubsby/2b4442608d233fbcd4b62dd257de6e7f to your computer and use it in GitHub Desktop.
Save brubsby/2b4442608d233fbcd4b62dd257de6e7f to your computer and use it in GitHub Desktop.
Tampermonkey script to add some hotkeys to youtube watch pages to find rips for a track
// ==UserScript==
// @name YouTube - Open wikia link for rip
// @namespace brubsby.com
// @description script to open the respective rip wikia page from a SiIvaGunner/TimmyTurnersGrandDad/VvvvvaVvvvvvr youtube watch page.
// @include http://www.youtube.com/watch*
// @include https://www.youtube.com/watch*
// @include http://youtube.com/watch*
// @include https://youtube.com/watch*
// @include http://youtube.com/*
// @include https://youtube.com/*
// @version 1
// @grant GM_openInTab
// ==/UserScript==
//press ctrl+shift+f to open the respective rip wikia page from a SiIvaGunner/TimmyTurnersGrandDad/VvvvvaVvvvvvr youtube watch page.
//press ctrl+alt+f to open a search to (hopefully) find most rips for the track on the watch page you're currently on
function wikiLinkFromTitle(title, wikia='siivagunner') {
if (wikia == "TimmyTurnersGrandDad") {
wikia = "ttgd";
}
if (wikia == "VvvvvaVvvvvvr") {
wikia = "vvvvvavvvvvr";
}
if (wikia == "GilvaSunner") {
wikia = "siivagunner";
}
return 'https://' + wikia + '.fandom.com/wiki/' + title.replaceAll(' ', '_').replaceAll(/[#|]+/gi,'').replaceAll('[','(').replaceAll(']',')').replaceAll('?','%3F');
}
function getTitle() {
return document.querySelector('#container > h1 > yt-formatted-string').textContent;
}
function getChannelName() {
return document.querySelector('#text > a').textContent;
}
function getVidTitle() {
return document.querySelector('#container > h1 > yt-formatted-string').textContent;
}
function getSongTitle() {
return getVidTitle().match(/(^.*?)(\s(-|\|)\s|$)/)[1];
}
function getSongTitleNoMixNames() {
return getSongTitle().match(/^([^\(]*)/)[0].trim();
}
function getGameName() {
return getVidTitle().match(/.+((-|\|) )(.*)/)[3];
}
function getMixNames() {
const songTitle = getSongTitle();
return songTitle.match(/\([^\)]+\)/g);
}
document.addEventListener("keydown", (e) => {
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.keyCode == 70) {
var channelName = getChannelName();
if (!['GilvaSunner', 'SiIvaGunner', 'TimmyTurnersGrandDad', 'VvvvvaVvvvvvr'].includes(channelName)) {
return;
}
var url = wikiLinkFromTitle(getTitle(), channelName);
GM_openInTab(url);
}
if ((e.ctrlKey || e.metaKey) && e.altKey && e.keyCode == 70) {
const query = `"${getSongTitleNoMixNames()}"${getGameName() ? ' "'+ getGameName() +'"':""} "Music: ${getSongTitleNoMixNames()}" channel description`.replaceAll(' ', '+')
GM_openInTab("https://www.youtube.com/results?search_query=" + query);
}
//overcast search suggestion
//"<track title>" "<game title>" "music <track title>" "composer <composer's name>" channel description
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment