Skip to content

Instantly share code, notes, and snippets.

@mbikovitsky
Last active January 6, 2022 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbikovitsky/761d3a61a52aaa189ffcf1dfda2a47c9 to your computer and use it in GitHub Desktop.
Save mbikovitsky/761d3a61a52aaa189ffcf1dfda2a47c9 to your computer and use it in GitHub Desktop.
// ==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