Skip to content

Instantly share code, notes, and snippets.

@halfdan
Last active August 29, 2015 14:13
Show Gist options
  • Save halfdan/3a327abd242b3456d94a to your computer and use it in GitHub Desktop.
Save halfdan/3a327abd242b3456d94a to your computer and use it in GitHub Desktop.
Duolingo Userscript for setting custom daily XP goals
// ==UserScript==
// @name Custom Goal Setter
// @namespace http://duolingo.com/skelkingur
// @version 0.1
// @description Adds a new field to add a custom daily goal.
// @author Fabian Becker <[email protected]>
// @match https://www.duolingo.com/settings/*
// @grant none
// ==/UserScript==
function attachCustomGoal() {
if ($("#xp-custom").length !== 0) {
return;
}
var el = $('.goal-chooser'),
item = '<li><label class="btn btn-standard btn-small btn-outline daily-goal-option"><input id="xp-radio" name="daily_goal" data-goal="100" type="radio"> <span class="title">Custom</span> <span class="xp-text"><input id="xp-custom" type="number" style="width:50px;"></input>&nbsp; XP per day</span></label></li>',
dailyGoal = duo.user.attributes.daily_goal;
el.append(item);
$("#xp-custom").click(function() {
$("#xp-radio").attr('checked', true);
});
$("#xp-custom").blur(function() {
var radio = $("#xp-radio"),
input = $("#xp-custom");
radio.data("goal", input.val());
});
if ([1,10,20,30,50].indexOf(dailyGoal) == -1) {
$("#xp-radio").attr('checked', true);
$("#xp-custom").val(dailyGoal);
} else {
$("#xp-custom").val(100);
}
}
$("#coach_tab").mouseup(function() {
// This is silly
setTimeout(attachCustomGoal, 100);
});
$(document).ready(attachCustomGoal);
$(document).ajaxComplete(attachCustomGoal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment