sajaniemi_variable_dataset_large / pool /shard010 /JavaScript /0062740_offline-detection.js
Pendigard's picture
Upload folder using huggingface_hub (part 113)
1abfaca verified
Raw History Blame Contribute Delete
692 Bytes
/**
* A basic example of how to use event listeners to detect a change of online/offline status and
* to give the user some sort of feedback, in this case by adding the `offline` class to the body
* to allow styling.
*/
(function () {
'use strict';
let updateOnlineStatus = function () {
let state = navigator.onLine ? 'online' : 'offline';
document.body.className = state;
};
console.info('2. Offline detection running');
window.addEventListener('load', () => {
window.addEventListener('online', updateOnlineStatus);
window.addEventListener('offline', updateOnlineStatus);
updateOnlineStatus();
});
}());