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 fdf2d99
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions shred/test-local-storage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!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 = () => {
if (typeof(Storage) !== "undefined") {
let count = localStorage.getItem("count");
if (count !== "undefined" && count !== null) {
document.getElementById("storage").innerHTML = "Storage: " + count;
} else {
document.getElementById("storage").innerHTML = "No storage found";
}
} else {
document.getElementById("storage").innerHTML = "Storage unavailable";
}
}

window.onload = onload;

</script>

</body>
</html>

0 comments on commit fdf2d99

Please sign in to comment.