From 7015eb1dc8ee06e79761329c84dec9884b7df65a Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 16 Mar 2016 21:44:17 -0500 Subject: [PATCH] Handle saving styles with undefined applies tos #167 --- edit.js | 4 ++-- storage.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/edit.js b/edit.js index 230586d9..d05e43a7 100644 --- a/edit.js +++ b/edit.js @@ -1265,7 +1265,7 @@ function getSectionsHashes() { } function getMeta(e) { - var meta = {}; + var meta = {urls: [], urlPrefixes: [], domains: [], regexps: []}; e.querySelector(".applies-to-list").childNodes.forEach(function(li) { if (li.className == template.appliesToEverything.className) { return; @@ -1274,7 +1274,7 @@ function getMeta(e) { var value = li.querySelector("[name=applies-value]").value; if (type && value) { var property = CssToProperty[type]; - meta[property] ? meta[property].push(value) : meta[property] = [value]; + meta[property].push(value); } }); return meta; diff --git a/storage.js b/storage.js index 03f4154e..5cd345ee 100644 --- a/storage.js +++ b/storage.js @@ -105,6 +105,14 @@ function saveStyle(o, callback) { }).forEach(function(att) { 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 if (!("enabled" in o)) { o.enabled = true;