diff --git a/background/js/index.js b/background/js/index.js index bf88359..7316268 100644 --- a/background/js/index.js +++ b/background/js/index.js @@ -5,11 +5,17 @@ function getSlogans() { var slogans; if (localStorage.getItem('SOMtodayntSlogans') != null) { slogans = JSON.parse(localStorage.getItem('SOMtodayntSlogans')); + tonight = JSON.parse(localStorage.getItem('SOMtonight')); } else { - var slogans = [ "Welkom bij SOMtodayn't" ] + var slogans = [ "Welkom bij SOMtodayn't" ]; + var tonight = true; localStorage.setItem('SOMtodayntSlogans', JSON.stringify(slogans)); + localStorage.setItem('SOMtonight', JSON.stringify(tonight)); } - return slogans; + return [ + tonight, + slogans + ]; } // Update array in local storage @@ -18,6 +24,11 @@ function setSlogans(array) { return true; } +function setTonight(value) { + localStorage.setItem('SOMtonight', JSON.stringify(value)); + return; +} + // Handle requests function handleMessage(request, sender, sendResponse) { var response; @@ -28,9 +39,13 @@ function handleMessage(request, sender, sendResponse) { response = getSlogans(); break; - case 'set': + case 'setSlogans': response = setSlogans(request.value); break; + + case 'setTonight': + response = setTonight(request.value); + break; } // Send response to either the content script or popup if (sender.tab) { diff --git a/content/js/index.js b/content/js/index.js index 0f46d90..20a2bb4 100644 --- a/content/js/index.js +++ b/content/js/index.js @@ -2,11 +2,14 @@ console.log('Somtoday\'nt content script active'); function changeSlogan(message) { + tonight = message[0]; + slogans = message[1]; + // Select random slogan - console.log(`Loaded ${message.length} slogans`); - if (message.length >= 1) { - var random = Math.floor(Math.random() * message.length); - var sloganText = message[random].toLowerCase(); + console.log(`Loaded ${slogans.length} slogans`); + if (slogans.length >= 1) { + var random = Math.floor(Math.random() * slogans.length); + var sloganText = slogans[random].toLowerCase(); console.log(`Slogan changed to: ${sloganText}`); } else { var sloganText = "welkom bij somtodayn't"; @@ -38,6 +41,14 @@ function changeSlogan(message) // Add a little credit document.querySelectorAll('footer > span')[0].innerHTML = "Somtodayn't is een add-on door McArn."; + + // Set theme + console.log(tonight); + if (tonight) { + var cssUrl = browser.runtime.getURL("content/css/index.css"); + var cssTag = ``; + document.body.innerHTML += cssTag; + } } // Send request to background script diff --git a/manifest.json b/manifest.json index dceca4a..e78fc8f 100644 --- a/manifest.json +++ b/manifest.json @@ -36,14 +36,17 @@ "default_popup": "popup/html/index.html" }, + "web_accessible_resources": [ + "content/css/index.css" + ], + "content_scripts": [ { "matches": ["*://*.somtoday.nl/*"], "js": [ "vendor/browser-polyfill.js", "content/js/index.js" - ], - "css": [ "content/css/index.css" ] + ] } ] diff --git a/popup/html/index.html b/popup/html/index.html index 76fbc5b..47d18cd 100644 --- a/popup/html/index.html +++ b/popup/html/index.html @@ -10,16 +10,24 @@