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 d6881a7
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions shred/test-local-storage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<body>

<div>
<p id="storage" style="font-size:40px;text-align:center;"></p>

<button onclick="startLoop()" style="height:200px;width:100%;font-size:30px;display:block;text-align:center;">Start Writing to Local Storage</button>
<button onclick="stopLoop()" style="height:200px;width:100%;font-size:30px;display:block;text-align:center;">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" && count !== "null") {
document.getElementById("storage").innerHTML = "Storage: " + count;
} else {
document.getElementById("storage").innerHTML = "No storage found";
}
}

window.onload = onload;

</script>

</body>
</html>

0 comments on commit d6881a7

Please sign in to comment.