Adding source

This commit is contained in:
Logic Kenzie 2023-09-25 07:50:25 -05:00
parent 9368954e82
commit d2adb1cefd
2 changed files with 42 additions and 2 deletions

View file

@ -1,3 +1,8 @@
# speedtest
# Speedtest
A simple Javascript speed test.
`Hosted at https://logically.cc/speedtest`
A simple Javascript speed test.
**Note that this source is uncoupled from the components required to run it standalone**
## Use Project Standalone
You'll want to run `npx create-astro` to use this project standalone. Then, you can clone this project into the `src/pages` directory and then run `npx astro build` to have the finished product we release on logically.cc

35
index.astro Normal file
View file

@ -0,0 +1,35 @@
---
import Layout from "../layouts/primary.astro"
---
<Layout>
<button id="tester">Test my speed!</button>
<div id="download"></div>
<div id="upload"></div>
<script>
const downloadP = document.getElementById("download")
const uploadP = document.getElementById("upload")
document.getElementById("tester").onclick = async (_event: MouseEvent) => {
const programStart = new Date().getTime()
let totalTransmitted = 0;
const getRuntime = ()=>parseInt(((new Date().getTime() - programStart)/1000).toPrecision(2))
const updateInterval = setInterval(()=>{
downloadP.innerText = `Your download speed is ${(totalTransmitted/getRuntime()).toPrecision(2)} megabytes per second.\nTransferred ${totalTransmitted} megabytes in ${getRuntime()} seconds.`
}, 1)
while (getRuntime() <= 30) {
if (getRuntime() >= 30) break;
(await fetch("https://raw.githubusercontent.com/yourkin/fileupload-fastapi/main/tests/data/test-10mb.bin")).body;
totalTransmitted += 10;
if (getRuntime() >= 30) break;
(await fetch("https://raw.githubusercontent.com/yourkin/fileupload-fastapi/main/tests/data/test-5mb.bin")).body;
totalTransmitted += 5;
if (getRuntime() >= 30) break;
}
clearInterval(updateInterval)
}
</script>
</Layout>