NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name Download videos
// @namespace openuserjs.org
// @description adds download button
// @include http://study.com/academy/*
// @author Dexmaster
// @version 0.0.11
// @grant none
// @run-at document-end
// ==/UserScript==
function vidStarter(){
var videoContainers = document.querySelectorAll('.videoContainer');
if(videoContainers && videoContainers.length){
Array.prototype.forEach.call(videoContainers, function(el, i){
timer(el, i);
});
}
}
function timer(el, indx, count){
if(isNaN(count)){
count = 8;
}
if(count > 0){
setTimeout(function() {
checkVid(el, indx, count-1);
}, 1000);
}
}
function makeTitle(){
var headChaps = document.querySelectorAll('.pageNavigation .left-content:not(.hidden-xs) .crumb:not(.transcriptLink)'),
headTitle = document.querySelector('.headerTitle'), fileName = '';
if(headChaps && headChaps.length){
Array.prototype.forEach.call(headChaps, function(el, i){
fileName += el.textContent.trim() + ' - ';
});
}
fileName += headTitle.textContent.trim();
return fileName.replace(/\s/g,' ');
}
function checkVid(el, indx, count){
if(el.querySelector('video source')){
var chldEl = document.createElement("a");
chldEl.href = el.querySelector('video source').src;
chldEl.download = makeTitle() + ' video-' + indx + '.mp4';
chldEl.target = '_blank';
chldEl.style = 'position: absolute; z-index: 9999; top: 17px; right: 75px; display:block; width: 35px; height: 35px; box-shadow: 0px 1px 3px #999; ' +
'border-radius: 35px; background-image: url(http://icons.iconarchive.com/icons/graphicloads/100-flat-2/256/arrow-download-icon.png); background-size: 100%; content: " "';
el.appendChild(chldEl);
} else {
//console.log(el.querySelector('video source'), count);
timer(el, indx, count);
}
}
setTimeout(vidStarter, 1000);