2019-11-18 19:51:56 +01:00
|
|
|
console.log('Somtoday\'nt content script active');
|
|
|
|
|
|
|
|
function changeSlogan(message)
|
|
|
|
{
|
2019-11-22 16:01:09 +01:00
|
|
|
if (message == 'reload') {
|
|
|
|
location.reload();
|
2019-11-18 19:51:56 +01:00
|
|
|
} else {
|
2019-11-22 16:01:09 +01:00
|
|
|
tonight = message[0];
|
|
|
|
slogans = message[1];
|
2019-11-18 19:51:56 +01:00
|
|
|
|
2019-11-22 16:01:09 +01:00
|
|
|
// Select random slogan
|
|
|
|
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";
|
|
|
|
console.log('No slogans found')
|
2019-11-18 19:51:56 +01:00
|
|
|
}
|
2019-11-22 16:01:09 +01:00
|
|
|
|
|
|
|
// 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 =
|
|
|
|
`<span class="white block">${slogan.white}</span>
|
|
|
|
<span>${slogan.blue}</span>`
|
|
|
|
;
|
2019-11-18 19:51:56 +01:00
|
|
|
|
2019-11-22 16:01:09 +01:00
|
|
|
// 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 = `<link rel='stylesheet' href='${cssUrl}'>`;
|
|
|
|
document.body.innerHTML += cssTag;
|
|
|
|
}
|
2019-11-22 14:29:27 +01:00
|
|
|
}
|
2019-11-18 19:51:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send request to background script
|
|
|
|
browser.runtime.sendMessage({ type: "get"});
|
|
|
|
|
|
|
|
// Receive response from background script
|
|
|
|
browser.runtime.onMessage.addListener(changeSlogan);
|