no-sleep-app
Version:
NoSleepApp is a lightweight JavaScript library that prevents devices from going to sleep during critical activities. It uses the Screen Wake Lock API or a fallback video playback method to keep the screen active, ensuring uninterrupted user experiences ac
57 lines (53 loc) • 1.56 kB
HTML
<html>
<head>
<title>NoSleep.js - Simple Test Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 20px;
}
.enabled {
background-color: green;
color: white;
}
.disabled {
background-color: red;
color: white;
}
#wakeLockButton {
padding: 10px 20px;
font-size: 16px;
border: none;
cursor: pointer;
}
</style>
</head>
<body>
<h1>No-Sleep-App Test Page</h1>
<input type="button" id="wakeLockButton" class="disabled" value="Wake Lock is Disabled" />
<script src="../src/index.js"></script>
<script>
const noSleep = new NoSleepApp();
let isWakeLockEnabled = false;
const wakeLockButton = document.querySelector("#wakeLockButton");
wakeLockButton.addEventListener("click", function () {
if (!isWakeLockEnabled) {
noSleep.enable();
isWakeLockEnabled = true;
wakeLockButton.value = "Wake Lock is Enabled";
wakeLockButton.classList.remove("disabled");
wakeLockButton.classList.add("enabled");
} else {
noSleep.disable();
isWakeLockEnabled = false;
wakeLockButton.value = "Wake Lock is Disabled";
wakeLockButton.classList.remove("enabled");
wakeLockButton.classList.add("disabled");
}
});
</script>
</body>
</html>