Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
)
  • Loading branch information
DeveloperTK committed May 19, 2021
0 parents commit a87f992
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
build.sh
Archive.zip
3 changes: 3 additions & 0 deletions .web-extension-id
Original file line number Diff line number Diff line change
@@ -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}
78 changes: 78 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
@@ -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);
24 changes: 24 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Binary file not shown.

0 comments on commit a87f992

Please sign in to comment.