diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..25475de --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +build.sh +Archive.zip \ No newline at end of file diff --git a/.web-extension-id b/.web-extension-id new file mode 100644 index 0000000..dbe5fab --- /dev/null +++ b/.web-extension-id @@ -0,0 +1,3 @@ +# This file was created by https://github.com/mozilla/web-ext +# Your auto-generated extension ID for addons.mozilla.org is: +{f412be1a-3260-47a6-811c-f0d6c309828f} \ No newline at end of file diff --git a/content.js b/content.js new file mode 100644 index 0000000..54fd151 --- /dev/null +++ b/content.js @@ -0,0 +1,78 @@ +function findStreamLinks() { + const $btnLinks = document.querySelectorAll("a.btn"); + console.log($btnLinks); + + for (const linkElement of $btnLinks) { + if (linkElement.href.includes("cmd=streamVideo") && linkElement.classList.contains("btn")) { + addDirectLinkEvent(linkElement); + } + } +} + +function addDirectLinkEvent(e) { + const newLink = document.createElement('a'); + newLink.classList.add('btn'); + newLink.classList.add('btn-info'); + newLink.innerHTML = `Direktlink`; + newLink.addEventListener('click', () => { + loadExternalPage(e, newLink); + }); + e.parentElement.appendChild(newLink); +} + +function loadExternalPage(e, newLink) { + newLink.innerHTML = "Loading"; + let timeout = setTimeout(() => { + newLink.innerHTML = "Timeout!" + setTimeout(() => newLink.innerHTML = "Direktlink") + }, 10000); + + fetch(e.href) + .then(function(response) { + // When the page is loaded convert it to text + return response.text() + }) + .then(function(html) { + // Initialize the DOM parser + let parser = new DOMParser(); + // Parse the text + let targetDocument = parser.parseFromString(html, "text/html"); + + clearTimeout(timeout); + openDirectDownloadLink(e, targetDocument, newLink); + }) + .catch(function(err) { + console.log('Failed to fetch page: ', err); + }); +} + +function openDirectDownloadLink(originalLink, targetDocument, newLink) { + try { + let x = targetDocument.getElementsByTagName('script') + let script = x[x.length - 1] + let text = script.text.replaceAll("\n", "").replaceAll("\t", "").replaceAll("xoctPaellaPlayer.init(", "[").replaceAll(")", "]") + let link = JSON.parse(text)[0].streams[0].sources.mp4[0].src + navigator.clipboard.writeText(link).then(function () { + console.log('Async: Copying to clipboard was successful!'); + newLink.innerHTML = "Copied!"; + setTimeout(() => newLink.innerHTML = "Direktlink", 2500); + }, function (err) { + console.error('Async: Could not copy text: ', err); + newLink.innerHTML = "Error"; + setTimeout(() => newLink.innerHTML = "Direktlink", 2500); + }); + } catch (err) { + newLink.innerHTML = "Error"; + setTimeout(() => newLink.innerHTML = "Direktlink", 2500); + } +} + +const checkExist = setInterval(function() { + if (document.querySelector('#il_center_col form').childNodes) { + console.log("Exists!"); + clearInterval(checkExist); + findStreamLinks(); + } else { + console.log("does not exist"); + } +}, 100); diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..a7f9f63 --- /dev/null +++ b/manifest.json @@ -0,0 +1,24 @@ +{ + "manifest_version": 2, + "name": "ILIAS Opencast DL", + "version": "1.0.1", + "description": "Adda direct download link to any ILIAS Opencast pages", + "icons": {}, + + "background": { + "scripts": [] + }, + + "content_scripts": [ + { + "matches": ["*://ilias.studium.kit.edu/*"], + "js": ["content.js"] + } + ], + + "applications": { + "gecko": { + "update_url": "https://pages.foxat.de/browser-addons-repository/updates.json" + } + } +} \ No newline at end of file diff --git a/web-ext-artifacts/ilias_opencast_dl-1.0.1-an+fx.xpi b/web-ext-artifacts/ilias_opencast_dl-1.0.1-an+fx.xpi new file mode 100644 index 0000000..2338248 Binary files /dev/null and b/web-ext-artifacts/ilias_opencast_dl-1.0.1-an+fx.xpi differ