Skip to content

Instantly share code, notes, and snippets.

@wilyJ80
Created September 20, 2024 22:03
Show Gist options
  • Save wilyJ80/71fe599ca6aa2e9d7ad1a17990039bba to your computer and use it in GitHub Desktop.
Save wilyJ80/71fe599ca6aa2e9d7ad1a17990039bba to your computer and use it in GitHub Desktop.
Poke download
<html>
<body>
<h1>Try poking!</h1>
<button>POKE</button>
<p>Pokes: 0</p>
<a href="#">Download poke count</a>
<script src="./script.js"></script>
</body>
</html>
'use strict';
let pokes = 0;
let blob;
const button = document.querySelector('button');
const pokesEl = document.querySelector('p');
button.addEventListener('click', ()=> {
pokes++;
pokesEl.textContent = `Pokes: ${pokes}`;
blob = new Blob([pokes.toString()]);
});
const anchor = document.querySelector("a");
anchor.addEventListener('click', ()=> {
let url = URL.createObjectURL(blob);
anchor.href = url;
anchor.download = 'pokes.txt';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment