Skip to content

Instantly share code, notes, and snippets.

@superMDguy
Last active January 31, 2018 01:24
Show Gist options
  • Select an option

  • Save superMDguy/4135b139ced6bec7b41e46bb754f19f7 to your computer and use it in GitHub Desktop.

Select an option

Save superMDguy/4135b139ced6bec7b41e46bb754f19f7 to your computer and use it in GitHub Desktop.
Progress report generator bookmarklet for Khan Academy courses

How to use

Create a bookmarklet with this as the URL:

javascript:(function(){const progress=Array.from(document.querySelectorAll('p[class^="progressNumbers"]')).map(e=>e.innerText).map(e=>{let o=e.match(/(\d+) of (\d+) complete/);return{done:parseInt(o[1]),total:parseInt(o[2])}}),done=progress.map(e=>e.done).reduce((e,o)=>e+o),total=progress.map(e=>e.total).reduce((e,o)=>e+o);alert(`\nProgress Report:\nPercent Complete- ${(done/total*100).toFixed(2)}%\n\nSections done- ${done}\nTotal sections- ${total}\n`);})()

Next, go to a page like this, and click on the bookmarklet to display your progress report.

const progress = Array.from(
document.querySelectorAll('p[class^="progressNumbers"]')
)
.map(x => x.innerText)
.map(txt => {
let parsed = txt.match(/(\d+) of (\d+) complete/);
return { done: parseInt(parsed[1]), total: parseInt(parsed[2]) };
});
const done = progress.map(unit => unit.done).reduce((acc, val) => acc + val);
const total = progress.map(unit => unit.total).reduce((acc, val) => acc + val);
alert(`
Progress Report:
Percent Complete- ${(done / total * 100).toFixed(2)}%
Sections done- ${done}
Total sections- ${total}
`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment