download raw data

This commit is contained in:
Ponj 2024-07-27 10:26:46 +02:00
parent b6eb5720c9
commit d69011ddb6
Signed by: p6nj
GPG key ID: CEAB625B75A836B2

View file

@ -8,12 +8,26 @@
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css"> <link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
</head> </head>
<script>
const download = (content, filename, contentType) => {
if (!contentType) contentType = 'application/octet-stream';
var a = document.createElement('a');
a.setAttribute('visibility', 'hidden');
var blob = new Blob([content], { 'type': contentType });
a.href = URL.createObjectURL(blob);
a.download = filename;
a.click();
}
const name = () => { return document.getElementById("name").value; };
</script>
<script type="module"> <script type="module">
import init, { greet } from "./pkg/bent.js"; import init, { greet } from "./pkg/bent.js";
init().then(() => { init().then(() => {
document.getElementById("greet-button").onclick = () => { document.getElementById("greet-button").onclick = () => {
const name = document.getElementById("name").value; greet(name());
greet(name); };
document.getElementById("download").onclick = () => {
download(name(), "name.txt", "text/plain");
}; };
}); });
</script> </script>
@ -31,6 +45,9 @@
<button id="greet-button">Greet</button> <button id="greet-button">Greet</button>
<button type="reset">Reset</button> <button type="reset">Reset</button>
</form> </form>
<p>
<button id="download">Download</button>
</p>
</body> </body>
</html> </html>