I'm trying to create a button for my chrome extension that will toggle on/off the function of the extension. It's a simple AdBlock-style extension.
Currently, I have 4 scripts popup.js, popup.html, mainfest.json & background.js
For some reason I can't get this function if work, I've looked online at how other people have done this but couldn't get any of that to work either.
Any help would be great, either modifying my method or if there's a better way I'm unaware of!
Thanks!
Popup.js
var background = chrome.extension.getBackgroundPage();
var theButton = document.querySelector("button");
function updateButton(onOrOff){
theButton.innerHTML = onOrOff ? "Disable" : "Enable";
theButton.className = onOrOff ? "buttonOFF" : "buttonON";
}
function toggleButton(){
background.isExtensionOn = !background.isExtensionOn;
updateButton(background.isExtensionOn);
}
chrome.runtime.getBackgroundPage(function(backgroundpage) {
background = backgroundpage;
updateButton(backgroundpage.isExtensionOn);
theButton.onclick = toggleButton;
if (background.isExtensionOn == true){
alert("on");
}
if (background.isExtensionOn == false){
alert("off");
}
});
Background.js
var isExtensionOn = true;
popup.html
<button type="button1" class="button1" id="disableButton">Toggle</button>
<script src="popup.js"></script>
TIA!