2020-12-10 10:14:29 +01:00
|
|
|
console.log('Somtoday\'nt content script active')
|
2019-11-18 19:51:56 +01:00
|
|
|
|
2020-12-10 10:14:29 +01:00
|
|
|
function changeSlogan (message) {
|
|
|
|
if (message === 'reload') {
|
|
|
|
location.reload()
|
|
|
|
} else {
|
|
|
|
const tonight = message[0]
|
|
|
|
const slogans = message[1]
|
|
|
|
|
|
|
|
// Set theme
|
|
|
|
console.log(tonight)
|
|
|
|
if (tonight) {
|
|
|
|
const cssUrl = browser.runtime.getURL('content/css/index.css')
|
|
|
|
const cssTag = `<link rel='stylesheet' href='${cssUrl}'>`
|
|
|
|
document.head.innerHTML += cssTag
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select random slogan
|
|
|
|
console.log(`Loaded ${slogans.length} slogans`)
|
|
|
|
let sloganText
|
|
|
|
|
|
|
|
if (slogans.length >= 1) {
|
|
|
|
const random = Math.floor(Math.random() * slogans.length)
|
|
|
|
sloganText = slogans[random].toLowerCase()
|
|
|
|
console.log(`Slogan changed to: ${sloganText}`)
|
2019-11-18 19:51:56 +01:00
|
|
|
} else {
|
2020-12-10 10:14:29 +01:00
|
|
|
sloganText = "welkom bij somtodayn't"
|
|
|
|
console.log('No slogans found')
|
|
|
|
}
|
|
|
|
|
|
|
|
// Split the slogan into array
|
|
|
|
const sloganArray = sloganText.split(' ')
|
|
|
|
const slogan = {
|
|
|
|
white: '',
|
|
|
|
blue: ''
|
2019-11-22 14:29:27 +01:00
|
|
|
}
|
2020-12-10 10:14:29 +01:00
|
|
|
|
|
|
|
// 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>`
|
|
|
|
|
|
|
|
// Add a little credit
|
|
|
|
document.querySelectorAll('footer > span')[0].innerHTML = "Somtodayn't is een add-on door McArn."
|
|
|
|
}
|
2019-11-18 19:51:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send request to background script
|
2020-12-10 10:14:29 +01:00
|
|
|
browser.runtime.sendMessage({
|
|
|
|
type: 'get'
|
|
|
|
})
|
2019-11-18 19:51:56 +01:00
|
|
|
|
|
|
|
// Receive response from background script
|
2020-12-10 10:14:29 +01:00
|
|
|
browser.runtime.onMessage.addListener(changeSlogan)
|