Skip to content

Instantly share code, notes, and snippets.

@rebane2001
Last active February 6, 2024 21:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rebane2001/db3806253e366b64855a7781d6866fb5 to your computer and use it in GitHub Desktop.
Save rebane2001/db3806253e366b64855a7781d6866fb5 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Search Hobune for unavailable video IDs
// @namespace hobune.stream
// @match https://www.youtube.com/watch
// @grant GM_xmlhttpRequest
// @connect hobune.stream
// @version 1.1
// @author Rebane
// @description 10/31/2020, 3:47:50 PM
// ==/UserScript==
let hobuneEndpoints = ["https://hobune.stream/videos/", "https://hobune.stream/tpa-h/videos/"];
let urlParams = new URLSearchParams(window.location.search);
let vidID = urlParams.get('v').replace(/[^a-zA-Z0-9_-]/g, "");
window.addEventListener('load', () => {setTimeout(detectRemovedVideo, 500)}, false);
function detectRemovedVideo(){
let element = document.querySelector("div.promo-title.style-scope.ytd-background-promo-renderer");
if (!element)
return;
let msg = document.createElement("P");
msg.classList.add("hobunecheck");
msg.innerText = "Checking Hobune for this video...";
element.appendChild(msg);
checkHobuneEndpoints();
}
function checkHobuneEndpoints(){
GM_xmlhttpRequest ( {
method: 'GET',
url: hobuneEndpoints[0] + vidID,
onload: function (response) {
if (response.status == 200){
/*
* Unused code for retrieving the title, not that it is not html escaped in this form.
* let title = response.responseText.match(/<title>(.*?)<\/title>/)[1];
*/
document.getElementsByClassName("hobunecheck")[0].innerHTML = `Video found: <a href="${hobuneEndpoints[0] + vidID}">${vidID}</a>`;
} else {
hobuneEndpoints.shift();
if (hobuneEndpoints.length > 0){
checkHobuneEndpoints();
} else {
document.getElementsByClassName("hobunecheck")[0].innerText = "Couldn't find this video on Hobune.";
}
}
}
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment