Why does this code doesn't work ? (it is part of a chrome extension),
I don't understand why using this method to check if the hostname of the current page is in the array ac_websites does not work.
I am not sure what window.location.hostname returns (string or something else)
Maybe indexOf() only works with strings.
const ac_websites = ["sciencedirect.com", "ncbi.nlm.nih.gov", "pubmed.ncbi.nlm.nih.gov", "ieeexplore.ieee.org", "ci.nii.ac.jp"]
chrome.runtime.onMessage.addListener(function (request) {
const url = document.location.href
const hostname = window.location.hostname
if (ac_websites.indexOf(hostname) != 1) {
window.open("https://google.com/" + url);
} else {
alert("Not an academic website")
}
})