My default checkbox is checked, when i click the to uncheck it, is not working, just set the button off but is not working and after i close the popup and when i see again the buton is still on so is checked, how i can fix this problem? do i have some error on this script?
popup.html
<html>
<head>>
<link rel='stylesheet' href="css/popup.css"/>
<script type="text/javascript" src="js/popup.js"></script>
</head>
<body>
<div style="padding: 10px;">
<div style="float:left;"> Players </div>
<div class="flipswitch">
<input type="checkbox" name="flipswitch" class="flipswitch-cb cbox" id="fs" checked>
<label class="flipswitch-label" for="fs">
<div class="flipswitch-inner"></div>
<div class="flipswitch-switch"></div>
</label>
</div>
</div>
</body>
</html>
popup.js
window.onload = function() {
if (window.location.href.match('chrome-extension://')) {
load();
}
}
$("body").on("change", ".cbox", function() {
var status = "";
$(".cbox").each(function() {
status = status + ($(this).is(":checked")) + ",";
});
save_option(status);
});
function save_option(option) {
var save = {};
save[option] = null;
chrome.storage.sync.set({
option : option
}, function() {
console.log(option + "saved");
});
}
function load() {
chrome.storage.sync.get(null, function(obj) {
console.log(obj);
if (obj.hasOwnProperty("option")) {
tab = obj.option.split(",");
console.log(tab);
var l = 0;
$(".cbox").each(function() {
$(".cbox:eq(" + l + ")").attr("checked", parseBoolean(tab[l]));
l++;
});
} else {
save_option("true");
}
});
}
function parseBoolean(str) {
return /true/i.test(str);
}
manifest.json
"name":"test",
"description":"test",
"version":"1.1.1",
"manifest_version":2,
"icons": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
},
"browser_action": {
"default_title": "name",
"default_popup": "popup.html",
"default_icon": "icons/icon128.png"
},
"background": {
"scripts": ["js/background.js"],
"persistent": true
},
"content_scripts": [
{
"js": ["js/content.js", "js/jquery.js"],
"matches": ["<all_urls>"],
"run_at": "document_end",
"all_frames": true
}
],
"applications": {
"gecko": {
"id": "{3b5e61ae-bda1-46c5-89bb-5085cc5ee9c}",
"strict_min_version": "57.0"
}
},
"content_security_policy": "script-src 'self'",
"permissions": [
"webRequestBlocking",
"unlimitedStorage",
"webNavigation",
"<all_urls>",
"webRequest",
"activeTab",
"downloads",
"topSites",
"storage",
"cookies",
"tabs"
]
}
Aucun commentaire:
Enregistrer un commentaire