im trying to make a chrome extension and i have this code in background.js that gets the url of the website that im on:
console.log("service worker: running")
let urls = []
let interval = setInterval(getUrl, 1000)
function getUrl(){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
urls.push(tabs[0].url)
//console.log(urls)
let urlToBeParsed = urls[0]
let finalUrl = urlToBeParsed.toString()
urls = []
console.log(finalUrl)
});
}
how do i check if a statement is true or false, and if its true launch index.html
const keyWords = ["red", "green", "blue"]
// FYI when the keyword is not in the string you are looking for it returns -1
if (finalUrl.indexOf(keyWords[0]) !== -1 || finalUrl.indexOf(keyWords[1]) !== -1 || finalUrl.indexOf(keyWords[2]) !== -1 ) {
// open index.html
} else {
console.log("keywords not in url")
}
thank you in advance!