44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
|
console.log('SOMtodayn\'t background script loaded')
|
||
|
|
||
|
// Read array from local storage
|
||
|
function getSlogans() {
|
||
|
var slogans;
|
||
|
if (localStorage.getItem('SOMtodayntSlogans') != null) {
|
||
|
slogans = JSON.parse(localStorage.getItem('SOMtodayntSlogans'));
|
||
|
} else {
|
||
|
var slogans = [ "Welkom bij SOMtodayn't" ]
|
||
|
localStorage.setItem('SOMtodayntSlogans', JSON.stringify(slogans));
|
||
|
}
|
||
|
return slogans;
|
||
|
}
|
||
|
|
||
|
// Update array in local storage
|
||
|
function setSlogans(array) {
|
||
|
localStorage.setItem('SOMtodayntSlogans', JSON.stringify(array));
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
// Handle requests
|
||
|
function handleMessage(request, sender, sendResponse) {
|
||
|
var response;
|
||
|
// DEBUG // console.log(sender);
|
||
|
// DEBUG // console.log("Request: " + request.type)
|
||
|
switch (request.type) {
|
||
|
case 'get':
|
||
|
response = getSlogans();
|
||
|
break;
|
||
|
|
||
|
case 'set':
|
||
|
response = setSlogans(request.value);
|
||
|
break;
|
||
|
}
|
||
|
// Send response to either the content script or popup
|
||
|
if (sender.tab) {
|
||
|
browser.tabs.sendMessage(sender.tab.id, response);
|
||
|
} else {
|
||
|
sendResponse({response: response});
|
||
|
}
|
||
|
// DEBUG // console.log("Response: " + response)
|
||
|
}
|
||
|
|
||
|
browser.runtime.onMessage.addListener(handleMessage);
|