Skip to content

Instantly share code, notes, and snippets.

@SilentImp
Created December 10, 2024 09:35
Show Gist options
  • Save SilentImp/6f0c1ad9750a23d5a29ac978d0551fc4 to your computer and use it in GitHub Desktop.
Save SilentImp/6f0c1ad9750a23d5a29ac978d0551fc4 to your computer and use it in GitHub Desktop.
<article id="article-1">
<p>Some text</p>
<p>Some text</p>
<menu>
<button commandfor="article-1" command="--record-like">like</button>
</menu>
</article>
<script>
document.body.addEventListener("command", ({ action, target }) => {
switch(action) {
case "--record-like":
navigator.sendBeacon(BuildArticleLikeURL(target.getAttribute('id')));
optimisticLike(target.getAttribute('id'))
break;
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment