Last active
June 4, 2019 09:23
-
-
Save dima1034/b6cab1b789a4aaece688f497f3ff6bfc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1 | |
var jq = document.createElement('script'); | |
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"; | |
document.getElementsByTagName('head')[0].appendChild(jq); | |
//2 | |
jQuery.noConflict(); | |
var counter = 1; | |
var courseTitle = jQuery("h1").first().text().trim().replace(/[^a-zA-Z0-9]/g, "_") | |
var lastVideoName = jQuery("li").last().find("h3").text().trim(); | |
var lastVideoDuration = jQuery("li").last().find("div.duration").text().trim(); | |
var lastModule = jQuery("h2").last().text().trim(); | |
var lastVidToDl = false; | |
var nextVid = ""; | |
var nextTitle = ""; | |
var nextDuration = ""; | |
var nextModule = ""; | |
var dlSpeed = 150; | |
var minuteSizeInMB = 3; | |
var titlesArray = []; | |
(function (console) { | |
console.save = function (data, filename) { | |
if (!data) { | |
console.error('Console.save: No data') | |
return; | |
} | |
if (!filename) filename = 'console.json' | |
if (typeof data === "object") { | |
data = JSON.stringify(data, undefined, 4) | |
} | |
var blob = new Blob([data], { type: 'text/json' }), | |
e = document.createEvent('MouseEvents'), | |
a = document.createElement('a') | |
a.download = filename | |
a.href = window.URL.createObjectURL(blob) | |
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':') | |
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null) | |
a.dispatchEvent(e) | |
} | |
})(console); | |
function stopDefAction(evt) { | |
evt.stopPropagation(); | |
// evt.preventDefault(); | |
} | |
function downloadURI(uri, name) { | |
var link = document.createElement("a"); | |
link.download = name; | |
link.href = uri; | |
document.body.appendChild(link); | |
link.click(); | |
document.body.removeChild(link); | |
delete link; | |
} | |
HTMLElement.prototype.click = function() { | |
var evt = this.ownerDocument.createEvent('MouseEvents'); | |
evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null); | |
this.dispatchEvent(evt); | |
} | |
function dlVid() { | |
var a = document.createElement('a'); | |
a.href = jQuery("video").attr("src"); | |
var currTitle = jQuery("ul.clips > li.selected").find("h3").text().trim(); | |
var currLink = document.getElementsByClassName('vjs-tech')[0].src | |
var currMod = jQuery("header.active").find("h2").text().trim(); | |
a.download = currTitle; | |
debugger | |
console.log(counter + " ñ " + currMod + " ñ " + currTitle); | |
titlesArray.push(counter + " ñ " + currMod + " ñ " + currTitle); | |
counter = counter + 1; | |
var minutes = parseInt(jQuery("span.total-time").text().trim().split(":")[0]) + 1; | |
var size = minutes * minuteSizeInMB * 1024 * 1024; | |
var timeNeeded = Math.ceil((size / (dlSpeed * 1024)) * 1000); | |
console.log("Rounded duration: ", minutes, " minutes", | |
"\nEstimated size: ", size, " bytes", | |
"\nEstimated time needed: ", timeNeeded, " msec"); | |
debugger | |
//a.trigger("click"); | |
//a.click(); | |
let s = jQuery('<a>some div</a>'); | |
jQuery("body").append(s); | |
s.on( "click", function() { | |
debugger | |
//downloadURI(currLink, currTitle) | |
jQuery('<a/>',{ | |
"href":currLink, | |
"download":currTitle, | |
id: "videoDownloadLink" | |
}).appendTo(document.body); | |
debugger | |
jQuery('#videoDownloadLink').get(0).addEventListener( | |
'click', stopDefAction, false | |
); | |
//jQuery('#videoDownloadLink').get(0).click().remove(); | |
jQuery('#videoDownloadLink').get(0).click(); | |
jQuery('#videoDownloadLink').trigger( "click" ); | |
}); | |
s.trigger( "click" ); | |
debugger | |
jQuery("#next-control").click(); | |
setTimeout(function () { jQuery("#play-control").click(); }, 10000); | |
if (!lastVidToDl) { | |
setTimeout(dlVid, timeNeeded); | |
nextVid = jQuery("ul.clips > li.selected").next(); | |
nextTitle = nextVid.find("h3").text().trim(); | |
nextDuration = nextVid.find("div.duration").text().trim(); | |
nextModule = nextVid.parent().parent().find("h2").text().trim(); | |
if (nextTitle == lastVideoName && | |
nextDuration == lastVideoDuration && | |
nextModule == lastModule) { | |
lastVidToDl = true; | |
} | |
} | |
else { | |
console.save(titlesArray, courseTitle + ".json"); | |
} | |
} | |
//3 | |
dlSpeed = 750; dlVid(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment