// ==UserScript== // @name Duolingo Words // @version 1.5 // @description Shows "Words" List for all Languages // @author Miriam Oe // @match https://www.duolingo.com/ // @grant none // @updateURL https://raw.githubusercontent.com/MiriamOe/DuoWords/master/DuoWordsScript.js // @downloadURL https://raw.githubusercontent.com/MiriamOe/DuoWords/master/DuoWordsScript.js // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js // @require https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.2.1/lodash.min.js // ==/UserScript== function inject(f) { var script = document.createElement('script'); script.type = 'text/javascript'; script.setAttribute('name', 'duo_words'); script.textContent = f.toString().substring(15, f.toString().length-1); document.body.appendChild(script); } inject(f); function f($) { var dat, vocab; //loads words & language info into dat & vocab function getData(bool) { dat = null; vocab = null; $.ajax({ url: '/vocabulary/overview', async : bool, success: function (data) { dat = data; vocab = dat.vocab_overview; } }); } //returns an empty string in case it was null function emptyStrings(word) { switch(word) { case null: return ""; break; default: return word; } } //returns the class name for the strength bar span element function getStrengthBarsCode(strength) { switch(strength) { case 4: return "_6s8NZ _2SbBh"; break; case 3: return "_3NjYP _2SbBh"; break; case 2: return "_3VX71 _2SbBh"; break; case 1: return "gh0Vi _2SbBh"; break; } }; //creates white box on the right with info about word strength function createDivSpacedRepetition() { var parent = document.getElementsByClassName("aFqnr _1E3L7")[0]; if(!parent) { parent=document.getElementsByClassName("NYMhm _3zjVe")[0]; } parent.className = "NYMhm _3zjVe"; parent.innerHTML = "

Spaced repetition

Duolingo's algorithms figure out when you should practice words to get them into your long-term memory.

"+vocab.filter(function(v) {return v.strength_bars===4}).length+"
"+vocab.filter(function(v) {return v.strength_bars===3}).length+"
"+vocab.filter(function(v) {return v.strength_bars===2}).length+"
"+vocab.filter(function(v) {return v.strength_bars===1}).length+"
"; } //shows info about selected word in the right box function showInfo(i) { var parent = document.getElementsByClassName("NYMhm _3zjVe")[0]; var inner = ""; inner = "Back

"+vocab[i].word_string+"

Gender
" + emptyStrings(vocab[i].gender) + "
Strength
Skill
" + vocab[i].skill + "
Part of speech
" + emptyStrings(vocab[i].pos) + "
"; parent.innerHTML = inner; } //calculates time difference and returns the string to display function getTime(time) { var now = new Date().getTime(); var diff = now-time; //ms diff /= 60000; //min if(diff<60) { return "Just now"; } diff /= 60; //h if(diff<24) { switch(Math.floor(diff)) { case 1: return "1 hour ago"; break; default: return Math.floor(diff) + " hours ago"; } } diff /= 24; //day if(diff<7) { switch(Math.floor(diff)) { case 1: return "yesterday"; break; default: return Math.floor(diff) + " days ago"; } } diff /= 7; //week if(diff<4) { switch(Math.floor(diff)) { case 1: return "1 week ago"; break; default: return Math.floor(diff) + " weeks ago"; } } diff /=4; if(diff<12) { switch(Math.floor(diff)) { case 1: return "1 month ago"; break; default: return Math.floor(diff) + " months ago"; } } diff /=12; switch(Math.floor(diff)) { case 1: return "1 year ago"; break; default: return Math.floor(diff) + " years ago"; } } //(re)loads words table function createWordTable() { //get and clear table var parent = document.getElementsByTagName("tbody")[0]; parent.innerHTML=""; var child, word, type, time, strength; //add each word to the table for(var i = 0; i"+type+""+time+""; parent.append(child); } } //part of merge sort algorithm, explanation can be googled function merge(arr1, arr2, arg) { var a, b, result = []; a=0; b=0; if(arr1.length>0 && arr2.length>0) { while(a arr2[b].last_practiced_ms) {result[a+b]=Object.assign({}, arr1[a]); a++;} else {result[a+b] = Object.assign({}, arr2[b]); b++;} break; case "s": if(arr1[a].strength < arr2[b].strength) {result[a+b]=Object.assign({}, arr1[a]); a++;} else {result[a+b] = Object.assign({}, arr2[b]); b++;} break; } } } while(a"+vocab.length+" Words
WordPart of speechLast practicedStrength
"; //Create info Box on the right createDivSpacedRepetition(); //create Table var cells=document.getElementsByClassName("_3zjVe")[0].getElementsByTagName("tr")[0].getElementsByTagName("th"); for(var i=0; i0) { duo[0].setAttribute("onclick", "location.reload()");} duo = document.getElementsByClassName('uWoNt _2QyU5'); if(duo.length>0) { duo[0].setAttribute("onclick", "location.reload()");} duo = document.getElementsByClassName('_2kNgI _1qBnH'); for(var i = 0; i