Skip to content

Instantly share code, notes, and snippets.

@allenanie
Last active October 9, 2015 23:42
Show Gist options
  • Save allenanie/f7cbd20b0c4edaad7a13 to your computer and use it in GitHub Desktop.
Save allenanie/f7cbd20b0c4edaad7a13 to your computer and use it in GitHub Desktop.
Easy To Calculate Coursera Video Length
//For "# min" type
var searchCorpus = $('a.lecture-link').text();
var matches = searchCorpus.match(/(\d).+min/gm);
var bigResult = [];
for (index in matches) {bigResult.push(matches[index].match(/([\d]+)/g)[0]);}
var sum = 0;
for (index in bigResult) {sum = sum + parseInt(bigResult[index]);}
/*=============================================
= User Guide
=============================================*/
For Chrome:
Open your browser console by: view->developer->JavaScript Console
Then copy and paste the code below to the console, then hit "ENTER" button
It will print out a string of text like "The videos you are watching have a total time length of xxx minutes".
For IE:
I don't use IE. Go get a Chrome.
For FireFox:
Open console by: Tools->Web Developer->Web Console
Then copy and paste the code below to the console, then hit "ENTER" button
It will print out a string of text like "The videos you are watching have a total time length of xxx minutes".
Author:
Allen Nie
/*----- End of comment ------*/
/**
* Script Starts here:
**/
(function($) {
var bigResult = [];
var sum = 0;
var searchCorpus = $('a.lecture-link').text();
var matches = searchCorpus.match(/((\d)(?:.+min))|((\d).?):(?:\d*)/gm);
for (index in matches) {bigResult.push(matches[index].match(/([\d]+)(?=:)|([\d]+) /g)[0]);}
for (index in bigResult) {sum = sum + parseInt(bigResult[index]);}
console.log("The videos you are watching have a total time length of: "+sum+" min.");
sum;
})(jQuery);
/**
* Executable Script ends here. Do not copy anything below this line.
**/
var groups;
re = /([\d]+)(?=:)|([\d]+) /g; //if g is flagged, and "exec" is used, must add while loop to finish the run.
while (groups = re.exec(str)) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment