Skip to content

Instantly share code, notes, and snippets.

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 dotWee/7e55748e6d8d874e498990996433cf01 to your computer and use it in GitHub Desktop.
Save dotWee/7e55748e6d8d874e498990996433cf01 to your computer and use it in GitHub Desktop.
Add a Download button below the currently viewing video on GRIPS OTH-Regensburg elearning.uni-regensburg.de
// ==UserScript==
// @name elearning.uni-regensburg.de_add-video-download-button.user
// @description Add a Download button below the currently viewing video on GRIPS OTH-Regensburg elearning.uni-regensburg.de
// @match *://elearning.uni-regensburg.de/*
// @version 1.0.0
// @grant none
// @author Lukas Wolfsteiner <lukas@wolfsteiner.media>
// ==/UserScript==
// get all iframes
var frames = document.getElementsByTagName("iframe");
// for each iframe
for (var frameId = 0; frameId < frames.length; ++frameId) {
var frameSrc = frames[frameId].src;
// check if is video
if (/^https?:\/\/([a-zA-Z\d-]+\.){0,}vimp\.oth-regensburg\.de\/media/.test(frameSrc)) {
// if yes, parse the video key
var frameUrl = new URL(frameSrc);
var frameKey = frameUrl.searchParams.get('key');
console.log(frameKey);
// var videoUrl = `https://vimp.oth-regensburg.de/getMedium/${frameKey}.mp4`;
var videoUrl = `https://vimp.oth-regensburg.de/getMedia.php?key=${frameKey}&type=mp4`;
var buttonDownload = `<br><a class="btn btn-primary downloadMedia" href="${videoUrl}"><i class="icon-cloud-download"></i> Download</a>`;
// if video key if defined
if (!!frameKey) {
// frames[frameId].parentElement.innerHTML += '<br><a class="btn btn-primary downloadMedia" href="https://vimp.oth-regensburg.de/media/download/format/none/key/' + frameKey + '.mp4"><i class="icon-cloud-download"></i> Download</a>';
frames[frameId].parentElement.innerHTML += buttonDownload;
console.log('added button');
} else {
console.log('couldnt parse key from url: ' + frameSrc);
}
// Only works on Chrome/Firefox; Safari is unsupported
//var downloading = browser.downloads.download({
// url: videoUrl,
// saveAs: true
//});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment