|
// ==UserScript== |
|
// @name Polito Video Clipboard |
|
// @version 3 |
|
// @author Marco Montanari (happyzleaf) |
|
// @namespace https://happyzleaf.com/ |
|
// @description Copies all the video urls from the selected course. Makes downloading entire courses easier with JDownloader 2. |
|
// @include https://didattica.polito.it/portal/pls/portal/* |
|
// @grant GM.xmlHttpRequest |
|
// @grant GM.setClipboard |
|
// ==/UserScript== |
|
|
|
var box = document.getElementsByClassName("video-js-box")[0]; |
|
// The script does not support BigBlueBox players yet, therefore they're exluded here. |
|
if (box == null) { |
|
//box = document.getElementsByClassName("col-md-8")[0]; |
|
return; |
|
} |
|
|
|
function findVideo(data) { |
|
var match = data.match(/https:\/\/video\.polito\.it\/dl\/.*\.mp4/gi); |
|
return match.length > 0 ? match[0] : null; |
|
} |
|
|
|
var clipboardText = document.createElement("span"); |
|
clipboardText.textContent = "Clipboard: "; |
|
|
|
var copyButton = document.createElement("button"); |
|
copyButton.innerHTML = "Copy video"; |
|
copyButton.onclick = function() { |
|
GM.setClipboard(findVideo(document.documentElement.innerHTML)); |
|
} |
|
|
|
var videoRegex = /href="(sviluppo\.(videolezioni.vis|pagina_corso.main|virtual_classroom.vis).*)">/gi; |
|
|
|
var copyAllButton = document.createElement("button"); |
|
copyAllButton.innerHTML = "Copy all videos"; |
|
copyAllButton.onclick = function() { |
|
loadingAllText.textContent = "Loading..."; |
|
|
|
// Adapted from https://github.com/lucaceriani |
|
var baseUrl = "https://didattica.polito.it/portal/pls/portal/"; |
|
|
|
var matches, lessons = []; |
|
while (matches = videoRegex.exec(document.documentElement.innerHTML)) { |
|
lessons.push(matches[1].replace(new RegExp("&", 'g'), "&")); |
|
} |
|
|
|
if (lessons.length == 0) { |
|
loadingAllText.textContent = "Error!"; |
|
return; |
|
} |
|
|
|
var count = 0; |
|
var total = lessons.length; |
|
var clipboard = ""; |
|
|
|
function updateStatus() { |
|
if (count == total) { |
|
loadingAllText.textContent = "Copied!"; |
|
GM.setClipboard(clipboard); |
|
} else { |
|
loadingAllText.textContent = "Loading... " + count + "/" + total; |
|
} |
|
} |
|
|
|
lessons.forEach(function(item, index) { |
|
GM.xmlHttpRequest({ |
|
method: "GET", |
|
url: baseUrl + item, |
|
onload: function(res) { |
|
// Little hack cause for some reasons findVideo(res.responseText) with a BigBlueButton lesson blocks everything. |
|
// Needs further investigation |
|
if (res.responseText.includes("https://virtualclassroom24.polito.it/")) { |
|
total--; |
|
} else { |
|
count++; |
|
clipboard += findVideo(res.responseText) + "\n"; |
|
} |
|
updateStatus(); |
|
}, |
|
onerror: function() { |
|
total--; |
|
updateStatus(); |
|
}, |
|
ontimeout: function() { |
|
total--; |
|
updateStatus(); |
|
} |
|
}); |
|
}); |
|
} |
|
|
|
var loadingAllText = document.createElement("span"); |
|
|
|
var div = document.createElement("div"); |
|
div.appendChild(clipboardText); |
|
div.appendChild(copyButton); |
|
div.appendChild(copyAllButton); |
|
div.appendChild(loadingAllText); |
|
div.appendChild(document.createElement("br")); |
|
|
|
box.insertBefore(div, box.firstChild); |