I'm creating a Google Extension and I'm on the step to set the options page from my extension.
I've create a toggle switch using this website which uses a css styled checkbox. Since I'm early stages of programming and extension development, I struggled a bit but was able to attached some jquery commands to the checkbox switch to set a var to either 1 when it's on and 0 when it's off, and the code works just fine, as bellow:
$("input:checkbox[name=onoffswitch]").change(function() {
if ($(this).is(':checked')) {
chrome.storage.sync.set({'varMenuSwitch': '1'}, function(toggleOn){
console.log('Switch is ON - Var set to 1');
});
} else {
chrome.storage.sync.set({'varMenuSwitch': '0'}, function(toggleOff){
console.log('Switch is OFF - Var set to 0');
});
}
});
Now I just need to 'save' and persist the current state of the checkbox switch (on or off) along with the VAR, which right now is always ON when the page loads. I don't have any idea how to accomplish that. Any directions?
Here is the HTML:
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>