Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions duolingo/lessons_progress.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,35 @@ function f($) {
estText.appendTo(stats);
}
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) === 0) return c.substring(name.length,c.length);
}
return "";
}


var activitiesLeft = totalActivities - doneActivities;
var goalFinishDate = new Date(getCookie("finishDateGoal")).getTime();
var goalFinishDateLocale = new Date(goalFinishDate).toLocaleDateString();
var daysToGoal = Math.round(goalFinishDate / (1000*3600*24))-Math.round(new Date().getTime()/(1000*3600*24));
var lessonsEachDay = Math.round((activitiesLeft/daysToGoal)*100)/100;
var lessonPerDay = createElem(lessonsEachDay, goalFinishDateLocale + " Goal Finish Date", 'Lessons-Per-Day', 'D');
lessonPerDay.appendTo(stats);


if ($('#app').hasClass('home') && !$('.lesson-progress').length) {
$('.strengthen-skills-container').before(stats);
}
} catch (ex) {
console.log(ex);
}
}
var mouseOverCounter = 0;
function createElem(normalText, altText, name, icon) {
var elemText = $('<span id="' + name + '_text"><strong>' + normalText + '</strong> ' + name + '</span>');
var percentage = $('<span id="' + name + '_percent"><strong>' + altText + '</strong></span>');
Expand All @@ -81,12 +103,32 @@ function f($) {
$('.' + name + '-icon').mouseover(function () {
$('#' + name + '_text').hide();
$('#' + name + '_percent').css('display', 'inline-block');
if (name == "Lessons-Per-Day" && mouseOverCounter===0){
mouseOverCounter++;
clickWaiter();
}
}).mouseout(function () {
$('#' + name + '_percent').hide();
$('#' + name + '_text').show();
});
return elem;
}
function clickWaiter(){

$('.Lessons-Per-Day-icon').click(function () {
var goalDateUser = prompt("Please enter the date you would like to finish by","YYYY-MM-DD");
function goalCookie(cname, cvalue) {
var d = new Date();
d.setTime(d.getTime() + (36500*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
setTimeout(function(){
location.reload();
}, 250);
}
goalCookie("finishDateGoal", goalDateUser);
});
}
$(document).ready(function () {
duolingoStats();
});
Expand Down