Handle saving styles with undefined applies tos #167

This commit is contained in:
Jason 2016-03-16 21:44:17 -05:00
parent f4d30838f9
commit 7015eb1dc8
2 changed files with 10 additions and 2 deletions

View File

@ -1265,7 +1265,7 @@ function getSectionsHashes() {
} }
function getMeta(e) { function getMeta(e) {
var meta = {}; var meta = {urls: [], urlPrefixes: [], domains: [], regexps: []};
e.querySelector(".applies-to-list").childNodes.forEach(function(li) { e.querySelector(".applies-to-list").childNodes.forEach(function(li) {
if (li.className == template.appliesToEverything.className) { if (li.className == template.appliesToEverything.className) {
return; return;
@ -1274,7 +1274,7 @@ function getMeta(e) {
var value = li.querySelector("[name=applies-value]").value; var value = li.querySelector("[name=applies-value]").value;
if (type && value) { if (type && value) {
var property = CssToProperty[type]; var property = CssToProperty[type];
meta[property] ? meta[property].push(value) : meta[property] = [value]; meta[property].push(value);
} }
}); });
return meta; return meta;

View File

@ -105,6 +105,14 @@ function saveStyle(o, callback) {
}).forEach(function(att) { }).forEach(function(att) {
o[att] = null; o[att] = null;
}); });
// Set other optional things to empty array if they're undefined
o.sections.forEach(function(section) {
["urls", "urlPrefixes", "domains", "regexps"].forEach(function(property) {
if (!section[property]) {
section[property] = [];
}
});
});
// Set to enabled if not set // Set to enabled if not set
if (!("enabled" in o)) { if (!("enabled" in o)) {
o.enabled = true; o.enabled = true;