Skip to content

Commit

Permalink
Add local storage loop test page.
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHeaps committed Oct 25, 2024
1 parent d3b4fd1 commit cef7d8f
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions shred/test-local-storage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<body>

<div style="text-align:center;">
<p id="storage" style="font-size:40px;></p>
<button onclick="startLoop()" style="height:200px;width:200px;font-size:30px;">Start Writing to Local Storage</button>

<button onclick="stopLoop()" style="height:200px;width:200px;font-size:30px;">Stop</button>

</div>

<script>

const addToStorage = () => {
let count = localStorage.getItem("count");
count = +count + +1;
localStorage.setItem("count", count);

document.getElementById("storage").innerHTML = "Storage: " + count;
}

var timerId;

const stopLoop = () => {
clearInterval(timerId);
}

const startLoop = () => {
if (typeof(Storage) !== "undefined") {
localStorage.clear();
clearInterval(timerId);
timerId = window.setInterval(addToStorage, 50);
} else {
document.getElementById("storage").innerHTML = "Storage unavailable";
}
}

const onload = () => {
let count = localStorage.getItem("count");
if count !== "undefined" {
document.getElementById("storage").innerHTML = "Storage: " + count;
} else {
document.getElementById("storage").innerHTML = "No storage found";
}
}

window.onload = onload;

</script>

</body>
</html>

0 comments on commit cef7d8f

Please sign in to comment.