|
// ==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."; |
|
} |
|
} |
|
} |
|
} ); |
|
} |