Last active
January 6, 2022 11:00
-
-
Save mbikovitsky/761d3a61a52aaa189ffcf1dfda2a47c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 JSONopto | |
// @namespace https://bikodbg.com/ | |
// @match https://*.panopto.eu/Panopto/Pages/Viewer.aspx?id=* | |
// @grant GM_registerMenuCommand | |
// @grant GM_xmlhttpRequest | |
// @grant GM_setClipboard | |
// @version 1.0 | |
// @author Michael Bikovitsky | |
// @description Extracts the Panopto video JSON | |
// @noframes | |
// @homepageURL https://gist.github.com/mbikovitsky/761d3a61a52aaa189ffcf1dfda2a47c9 | |
// ==/UserScript== | |
function getJson(onSuccess) { | |
const windowUrl = new URL(window.location.href); | |
const id = windowUrl.searchParams.get("id"); | |
if (!id) { | |
alert("Weird Panopto URL, can't get ID"); | |
return; | |
} | |
GM_xmlhttpRequest({ | |
url: new URL("/Panopto/Pages/Viewer/DeliveryInfo.aspx", windowUrl), | |
method: "POST", | |
headers: { | |
"Content-Type": "application/x-www-form-urlencoded" | |
}, | |
responseType: "json", | |
data: `deliveryId=${id}&responseType=json`, | |
onload: function (responseObject) { | |
onSuccess(responseObject.response); | |
}, | |
onerror: function () { | |
alert("Failed retrieving JSON"); | |
} | |
}); | |
} | |
GM_registerMenuCommand("Get JSON", function () { | |
getJson(function (response) { | |
GM_setClipboard(JSON.stringify(response)); | |
alert("JSON copied to clipboard"); | |
}); | |
}); | |
GM_registerMenuCommand("Get podcast URL", function () { | |
getJson(function (response) { | |
GM_setClipboard(response.Delivery.PodcastStreams[0].StreamUrl); | |
alert("Podcast URL copied to clipboard"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment