mirror of
https://github.com/S2-/ping.git
synced 2025-08-04 13:10:09 +02:00
initial draft
This commit is contained in:
34
src/background-pinger.js
Normal file
34
src/background-pinger.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import { loadOptions } from './utils.js';
|
||||
|
||||
let options = {};
|
||||
|
||||
function ping(server) {
|
||||
console.log('pinging ' + server);
|
||||
}
|
||||
|
||||
function reloadConfig() {
|
||||
loadOptions().then((savedOptions) => {
|
||||
options.server = savedOptions.server;
|
||||
options.interval = savedOptions.interval;
|
||||
|
||||
if (options.server && options.interval >= 1) {
|
||||
ping(options.server);
|
||||
|
||||
if (options.pinger) {
|
||||
clearInterval(options.pinger);
|
||||
}
|
||||
options.pinger = setInterval(function() {
|
||||
ping(options.server);
|
||||
}, options.interval * 1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
browser.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
||||
if (request === 'configChanged') {
|
||||
reloadConfig();
|
||||
}
|
||||
});
|
||||
|
||||
//startup
|
||||
reloadConfig();
|
Reference in New Issue
Block a user