Skip to content

Instantly share code, notes, and snippets.

@yanick
Created November 7, 2014 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanick/3aad016b952c127f2bbd to your computer and use it in GitHub Desktop.
Save yanick/3aad016b952c127f2bbd to your computer and use it in GitHub Desktop.
Coursera GMscript for time left
// ==UserScript==
// @name Show time remaining
// @namespace Yanick
// @description Show the tiem of videos remaining
// @include https://class.coursera.org/proglang-003/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @version 1
// @grant none
// ==/UserScript==
function updateLeftover() {
$('div.course-item-list-header').each(function(){
if( $(this).find('h3 .remainder' ).length === 0 ) {
$(this).children('h3')
.append('<span class="remainder" style="font-size: small">'
+ ' -- ' + '<span class="r"></span> mins left</span>');
}
var time_left = $(this).next().children('li.unviewed').map(function(){
var r = $(this).text().match(/\((\d+):(\d+)\)/);
return r ? 60 * parseInt(r[1]) + parseInt(r[2]) : 0;
}
).get().reduce(function(x,a){ return x + a },0);
if ( time_left > 0 ) {
$(this).find('h3 .remainder').show();
$(this).find('h3 .remainder .r').text(
parseInt(time_left / 60)
);
}
else {
$(this).find('h3 .remainder').hide();
}
});
}
updateLeftover();
var t = setInterval(updateLeftover, 60000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment