Skip to content

Instantly share code, notes, and snippets.

@wlib
Last active January 23, 2020 20:35
Show Gist options
  • Save wlib/7fe6657510e6b8fbab01fe9c25f0f610 to your computer and use it in GitHub Desktop.
Save wlib/7fe6657510e6b8fbab01fe9c25f0f610 to your computer and use it in GitHub Desktop.
const data = [...document.querySelectorAll("#scoreTable > tbody tr")]
.filter(a => a.cells.length > 1)
.map(a => {
const score = a.cells[10].innerText
const [earned, possible] = score.split("/").map(n => parseFloat(n))
return {
category: a.cells[1].innerText,
earned, possible
}
})
.reduce((acc, a) => {
if (!acc[a.category])
acc[a.category] = { earned: 0, possible: 0 }
acc[a.category].earned += a.earned
acc[a.category].possible += a.possible
return acc
}, {})
open(`https://example.com/#${encodeURIComponent(JSON.stringify(data))}`)
<html>
<head>
</head>
<body>
<a href="javascript:(function()%7Bopen('http%3A%2F%2Flocalhost%3A8000%2F%23' %2B encodeURIComponent(JSON.stringify(Array.from(document.querySelectorAll('%23scoreTable > tbody tr')).filter(function (a) %7B return a.cells.length > 1%3B %7D).map(function (a) %7Bvar score %3D a.cells%5B10%5D.innerText%3Bvar _a %3D score.split('%2F').map(function (n) %7B return parseFloat(n)%3B %7D)%2C earned %3D _a%5B0%5D%2C possible %3D _a%5B1%5D%3Breturn %7Bcategory%3A a.cells%5B1%5D.innerText%2Cearned%3A earned%2C possible%3A possible%7D%3B%7D).reduce(function (acc%2C a) %7Bif (!acc%5Ba.category%5D)acc%5Ba.category%5D %3D %7B earned%3A 0%2C possible%3A 0 %7D%3Bacc%5Ba.category%5D.earned %2B%3D a.earned%3Bacc%5Ba.category%5D.possible %2B%3D a.possible%3Breturn acc%3B%7D%2C %7B%7D))))%7D)()">Competencies Bookmarklet</a>
</body>
<script src="index.js"></script>
</html>
const data = JSON.parse( decodeURIComponent( location.hash.substring(1) ) )
console.log(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment