Added reload on SOMtonight toggle
This commit is contained in:
parent
26ba99b803
commit
40a469de0e
@ -2,52 +2,56 @@ console.log('Somtoday\'nt content script active');
|
||||
|
||||
function changeSlogan(message)
|
||||
{
|
||||
tonight = message[0];
|
||||
slogans = message[1];
|
||||
|
||||
// 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}`);
|
||||
if (message == 'reload') {
|
||||
location.reload();
|
||||
} else {
|
||||
var sloganText = "welkom bij somtodayn't";
|
||||
console.log('No slogans found')
|
||||
}
|
||||
tonight = message[0];
|
||||
slogans = message[1];
|
||||
|
||||
// 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] + " ";
|
||||
// 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')
|
||||
}
|
||||
} else {
|
||||
slogan.white = sloganArray;
|
||||
}
|
||||
|
||||
// Edit HTML
|
||||
document.getElementById('slogan').innerHTML =
|
||||
`<span class="white block">${slogan.white}</span>
|
||||
<span>${slogan.blue}</span>`
|
||||
;
|
||||
// Split the slogan into array
|
||||
var sloganArray = sloganText.split(" ");
|
||||
var slogan = {
|
||||
white: '',
|
||||
blue: ''
|
||||
};
|
||||
|
||||
// Add a little credit
|
||||
document.querySelectorAll('footer > span')[0].innerHTML = "Somtodayn't is een add-on door McArn.";
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
// 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.";
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,11 @@
|
||||
}
|
||||
},
|
||||
|
||||
"permissions": [
|
||||
"tabs",
|
||||
"storage"
|
||||
],
|
||||
|
||||
"icons": {
|
||||
"25" : "assets/icons/25.png",
|
||||
"32" : "assets/icons/32.png",
|
||||
|
@ -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 = '';
|
||||
|
Loading…
Reference in New Issue
Block a user