Per the question asked, is it possible for me to target the element of a specific website instead of my popup.html using JavaScript? The link in the manifest has been removed from this question.
My JS file
function myAlert(){
alert('You have activated dark mode!');
// Create new link Element
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'css/dark-mode.css';
document.getElementsByTagName('HEAD')[0].appendChild(link);
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('darkMode').addEventListener('click', myAlert);
});
My manifest file
{
"manifest_version": 3,
"name": "Dark Mode Extension",
"version": "1.0",
"action": {
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["*://*.WEBSITEHERE.com/*"],
"js": ["js/dark-mode.js"]
}
],
"permissions": ["tabs", "activeTab", "storage", "notifications"]
}
The stylesheet is added to the popup.html and not the website when the button is pressed