console.log('Somtoday\'nt content script active'); function changeSlogan(message) { // 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(`Slogan changed to: ${sloganText}`); } else { var sloganText = "welkom bij somtodayn't"; console.log('No slogans found') } // Split the slogan into array var sloganArray = sloganText.split(" "); var slogan = { white: '', blue: '' }; // Set the last word in the array to be blue if (sloganArray.length > 1) { slogan.blue = sloganArray.pop(); for (let index = 0; index < sloganArray.length; index++) { slogan.white = slogan.white + sloganArray[index] + " "; } } else { slogan.white = sloganArray; } // Edit HTML document.getElementById('slogan').innerHTML = `${slogan.white} ${slogan.blue}` ; // Add a little credit document.querySelectorAll('footer > span')[0].innerHTML = "Somtodayn't is een add-on door McArn."; } // Send request to background script browser.runtime.sendMessage({ type: "get"}); // Receive response from background script browser.runtime.onMessage.addListener(changeSlogan);