Skip to content

Instantly share code, notes, and snippets.

@milichev
Last active December 13, 2015 16:49
Show Gist options
  • Save milichev/4942832 to your computer and use it in GitHub Desktop.
Save milichev/4942832 to your computer and use it in GitHub Desktop.
(function(w,d,$){
"use strict";
if (typeof $ == 'undefined'){
alert('no jquery');
return;
}
//d.body.appendChild(d.createElement('script')).src='http://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.0-rc.3/lodash.js';
req("http://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.0-rc.3/lodash.js", function(){
$(grab);
});
req("http://eligrey.com/demos/FileSaver.js/FileSaver.js");
var partIdx = -1;
var pageUrlBase = 'http://pluralsight.com/training/Player?'; //window.location.protocol + "//" + window.location.host + '/training/Player?';
var title = d.title;
var storageKey = '___pages: ' + title;
var parts = localStorage.getItem(storageKey);
if (parts){
parts = JSON.parse(parts);
console.log('local parts retrived');
} else {
parts = [];
}
var moduleTitles = [];
function grab(){
$('.clipTitle a[onclick*="Launch"]').each(function(){
partIdx++;
var link = $(this);
var url = pageUrlBase + /Player\(\'([^\']+)\'\)/g.exec(link.attr('onclick'))[1];
var ex = _.where(parts, {url: url})[0];
if (ex)
return;
var moduleTitle = $.trim( link.closest('.tocClips').prevAll('.module:first').find('.title').text() );
if (!_.contains(moduleTitles, moduleTitle))
moduleTitles.push(moduleTitle);
parts.push({
index: partIdx,
title: link.text(),
moduleTitle: moduleTitle,
moduleIdx: moduleTitles.length,
url: url,
saved: false
});
});
//bak();
parts = parts.slice(0, 1);
partIdx = -1;
nextPage();
}
w.___onpage = function(res){
debugger;
var p = parts[partIdx];
p.pHtml = res;
bak();
nextPage();
}
function nextPage(){
partIdx++;
if (partIdx === parts.length){
console.log('all pages done: ' + partIdx);
partIdx = -1;
nextVideo();
return;
}
var p = parts[partIdx];
//$.ajax(p.url).done(___onpage);
debugger;
var iframe = $('<iframe />')
.attr({
src: p.url
})
.on({
load: function(e){
debugger;
iframe.remove();
}
})
.appendTo('body');
}
function bak(){
localStorage.setItem(storageKey, JSON.stringify(parts));
}
function req(src, cb){
var s = d.createElement('script');
s.onload = cb;
d.body.appendChild(s).src=src;
}
function nextVideo(){
partIdx++;
if (partIdx === parts.length){
console.log('all videos done: ' + partIdx);
partIdx = -1;
nextVideo();
return;
}
}
})(window,document,window.jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment