diff --git a/messaging.js b/messaging.js index 1e7cc94e..0d356256 100644 --- a/messaging.js +++ b/messaging.js @@ -1,12 +1,15 @@ // keep message channel open for sendResponse in chrome.runtime.onMessage listener const KEEP_CHANNEL_OPEN = true; +const OWN_ORIGIN = chrome.runtime.getURL(''); function notifyAllTabs(request) { - chrome.windows.getAll({populate: true}, function(windows) { - windows.forEach(function(win) { - win.tabs.forEach(function(tab) { - chrome.tabs.sendMessage(tab.id, request); - updateIcon(tab); + chrome.windows.getAll({populate: true}, windows => { + windows.forEach(win => { + win.tabs.forEach(tab => { + if (request.codeIsUpdated !== false || tab.url.startsWith(OWN_ORIGIN)) { + chrome.tabs.sendMessage(tab.id, request); + updateIcon(tab); + } }); }); }); diff --git a/storage.js b/storage.js index 1a0a1fce..776c71d3 100644 --- a/storage.js +++ b/storage.js @@ -105,11 +105,13 @@ function saveStyle(style, {notify = true} = {}) { if (style.id) { style.id = Number(style.id); os.get(style.id).onsuccess = eventGet => { - style = Object.assign({}, eventGet.target.result, style); + const oldStyle = Object.assign({}, eventGet.target.result); + const codeIsUpdated = !styleSectionsEqual(style, oldStyle); + style = Object.assign(oldStyle, style); os.put(style).onsuccess = eventPut => { style.id = style.id || eventPut.target.result; if (notify) { - notifyAllTabs({method: 'styleUpdated', style}); + notifyAllTabs({method: 'styleUpdated', style, codeIsUpdated}); } invalidateCache(notify); resolve(style); @@ -576,6 +578,9 @@ function getSync() { } function styleSectionsEqual(styleA, styleB) { + if (!styleA.sections || !styleB.sections) { + return undefined; + } if (styleA.sections.length != styleB.sections.length) { return false; }