NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name Offline monitor
// @namespace userScript/spunky
// @version 0.8
// @description Logs offline state
// @author spunky
// @match *
// @grant GM_notification
// @license MIT
// ==/UserScript==
(function() {
'use strict';
console.log('offline logger started', Date());
const formPrefix = '%c';
let startTimestamp = null;
window.addEventListener('offline', () => {
startTimestamp = Date.now();
const message = `OFFLINE MONITOR -> OFFLINE ${Date()}`;
const formatting = 'background: red; color: white; font-size: x-large';
console.log(`${formPrefix}${message}`, formatting);
GM_notification('OFFLINE> Wifi disconnected', message);
});
window.addEventListener('online', () => {
const duration = Date.now() - startTimestamp;
const message = `OFFLINE MONITOR -> ONLINE || Offline duration: ${duration / 1000}sec (${duration / 1000 / 60} min)`;
const formatting = 'background: green; color: white';
console.log(`${formPrefix}${message}`, formatting);
GM_notification('ONLINE> Wifi connected', message);
});
})();