Created
February 20, 2023 22:52
-
-
Save sartak/04ccf0312cb0cbfd8d28ecd4440575f0 to your computer and use it in GitHub Desktop.
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 Monkeytype results | |
// @version 0.1 | |
// @description Monkeytype results | |
// @author You | |
// @match https://monkeytype.com/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
const url = 'fill me in'; | |
setTimeout(() => { | |
const btn = document.querySelector("#result .stats .tags .editTagsButton"); | |
let lastResult; | |
const observer = new MutationObserver(function (_mutations) { | |
const gotResult = btn.getAttribute("result-id"); | |
if (gotResult === "") { | |
return; | |
} | |
if (gotResult === lastResult) { | |
alert( | |
`gotResult(${gotResult}) === lastResult(${lastResult}), skipping` | |
); | |
return; | |
} | |
lastResult = gotResult; | |
const replayStr = replay(); | |
const statsObj = stats(); | |
const body = JSON.stringify({ | |
stats: statsObj, | |
id: gotResult, | |
replay: replayStr, | |
}); | |
fetch(url, { | |
method: "POST", | |
headers: { "Content-Type": "application/json" }, | |
body, | |
}) | |
.then((res) => { | |
return res.json(); | |
}) | |
.then((json) => { | |
if (json.error) { | |
console.error(json); | |
alert(`Error saving result: ${json.error}`); | |
} else { | |
console.log(json); | |
} | |
}) | |
.catch((err) => { | |
alert(`Error saving result: ${err}`); | |
}); | |
}); | |
observer.observe(btn, { | |
attributes: true, | |
attributeFilter: ["result-id"], | |
}); | |
console.log("Waiting for results"); | |
}, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment