Last active
May 15, 2022 21:10
-
-
Save nateinaction/e833488d3b67637eb5176b189c52cd0e to your computer and use it in GitHub Desktop.
Add Word Strength to Duolingo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Add Word Strength to Duolingo | |
// @namespace https://gist.githubusercontent.com/nateinaction/e833488d3b67637eb5176b189c52cd0e/ | |
// @version 0.3 | |
// @description Add word strength percentages to Duolingo's words page at the tap of a button. | |
// @author Nate Gay | |
// @match https://www.duolingo.com/words | |
// @run-at document-idle | |
// @grant none | |
// @updateUrl https://gist.githubusercontent.com/nateinaction/e833488d3b67637eb5176b189c52cd0e/raw/ | |
// @downloadUrl https://gist.githubusercontent.com/nateinaction/e833488d3b67637eb5176b189c52cd0e/raw/ | |
// @supportUrl https://gist.githubusercontent.com/nateinaction/e833488d3b67637eb5176b189c52cd0e/ | |
// ==/UserScript== | |
const addStrength = () => { | |
const strong = document.querySelectorAll('span.eTLSK').length - 1; | |
const good = document.querySelectorAll('span._236Ma').length - 1; | |
const practice = document.querySelectorAll('span._2pMjT').length - 1; | |
const overdue = document.querySelectorAll('span._2BiYf').length - 1; | |
const wordGroups = [strong, good, practice, overdue]; | |
const all = wordGroups.reduce((a, b) => a + b); | |
for (var i = 0; i < wordGroups.length; i++) { | |
let div = document.getElementsByClassName('_1jxVm')[0]; | |
let percentStrength = (wordGroups[i]/all).toFixed(2) * 100; | |
let elem = document.createElement('span'); | |
elem.style.marginLeft = '20px'; | |
elem.innerHTML = wordGroups[i] + ' (' + percentStrength + '%) '; | |
div.replaceWith(elem); | |
} | |
// Total words | |
const overallStrength = ((strong * 4 + good * 3 + practice * 2 + overdue) / (all * 4)).toFixed(4) * 100; | |
document.getElementsByClassName('_1VWgO')[0].append(' (' + overallStrength + '%)'); | |
} | |
let done = false; | |
window.addEventListener('keydown', function() { | |
if (!done) { | |
addStrength(); | |
done = true; | |
} | |
}, false); | |
Author
nateinaction
commented
May 15, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment