Added reload on SOMtonight toggle

This commit is contained in:
Arne van Iterson 2019-11-22 16:01:09 +01:00
parent 26ba99b803
commit 40a469de0e
3 changed files with 69 additions and 42 deletions

View File

@ -2,6 +2,9 @@ console.log('Somtoday\'nt content script active');
function changeSlogan(message)
{
if (message == 'reload') {
location.reload();
} else {
tonight = message[0];
slogans = message[1];
@ -50,6 +53,7 @@ function changeSlogan(message)
document.body.innerHTML += cssTag;
}
}
}
// Send request to background script
browser.runtime.sendMessage({ type: "get"});

View File

@ -13,6 +13,11 @@
}
},
"permissions": [
"tabs",
"storage"
],
"icons": {
"25" : "assets/icons/25.png",
"32" : "assets/icons/32.png",

View File

@ -49,12 +49,30 @@ request.then(function(message) {
checkbox.checked = true;
}
checkbox.addEventListener('click', function(event) {
// Update value in local storage
request = browser.runtime.sendMessage({
type: "setTonight",
value: checkbox.checked
});
// Reload all SOMtoday tabs
var reload = browser.tabs.query({});
reload.then(logTabs, onError);
});
// Find id of somtoday.nl tab
function logTabs(tabs) {
for (let tab of tabs) {
// Match only tabs with url somtoday.nl
if (tab.url.includes('somtoday.nl')) {
browser.tabs.sendMessage(tab.id, 'reload');
}
}
}
// Handle query errors
function onError(error) {
console.log(`Error: ${error}`);
}
// Add existing slogans to list items in the popup
var sloganList = '';