-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbackground-script.js
48 lines (46 loc) · 1.8 KB
/
background-script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
if (typeof browser === 'undefined') { var browser = chrome; }
import { getWeatherAppData, getDelijnAppData } from './data-background-script.js';
import { fetchWeatherData, fetchDelijnData } from './api-background-script.js';
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
(async () => {
// Background image
if (message.action === 'saveBackgroundImage') {
await browser.storage.local.set({ backgroundImage: message.data });
sendResponse({ succes: true });
console.log('Background image saved.');
}
// Weather
if (message.action === 'setWeatherAppData') {
await browser.storage.local.set({ weatherAppData: message.data });
sendResponse({ succes: true });
console.log('Weather appdata saved.');
}
if (message.action === 'getWeatherAppData') {
const weatherAppData = await getWeatherAppData(message.location);
sendResponse(weatherAppData);
console.log('Weather appdata sent.');
}
if (message.action === 'fetchWeatherData') {
const weatherData = await fetchWeatherData(message.location);
sendResponse(weatherData);
console.log('Weather data fetched and sent.');
}
// Delijn
if (message.action === 'setDelijnAppData') {
await browser.storage.local.set({ delijnAppData: message.data });
sendResponse({ succes: true });
console.log('Delijn data set and sent.');
}
if (message.action === 'getDelijnAppData') {
const delijnAppData = await getDelijnAppData();
sendResponse(delijnAppData);
console.log('Delijn appdata sent.');
}
if (message.action === 'fetchDelijnData') {
const delijnData = await fetchDelijnData(message.url);
sendResponse(delijnData);
console.log('Delijn data fetched and sent.');
}
})();
return true;
});