From e6df389f595f93850b2bc089f47ef3447a56b3d8 Mon Sep 17 00:00:00 2001 From: Jason Barnabe Date: Tue, 17 Feb 2015 12:52:32 -0600 Subject: [PATCH 1/5] Explain why we 'Only push styles to the top-level document' #27 --- background.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/background.js b/background.js index 80e6ffe3..fe4f77b2 100644 --- a/background.js +++ b/background.js @@ -1,7 +1,13 @@ // This happens right away, sometimes so fast that the content script isn't even ready. That's // why the content script also asks for this stuff. chrome.webNavigation.onCommitted.addListener(function(data) { - if (data.frameId !== 0) return; + // Until Chrome 41, we can't target a frame with a message + // (https://developer.chrome.com/extensions/tabs#method-sendMessage) + // so a style affecting a page with an iframe will affect the main page as well. + // Skip doing this for frames for now, which can result in flicker. + if (data.frameId != 0) { + return; + } getStyles({matchUrl: data.url, enabled: true, asHash: true}, function(styleHash) { chrome.tabs.sendMessage(data.tabId, {method: "styleApply", styles: styleHash}); // Don't show the badge for frames From bd83d65da6e07aa3ab94a7267eda4b44a8552754 Mon Sep 17 00:00:00 2001 From: Jason Barnabe Date: Tue, 17 Feb 2015 13:01:15 -0600 Subject: [PATCH 2/5] Add enable/disable links back as hidden #17 --- popup.html | 4 ++++ popup.js | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/popup.html b/popup.html index 062a8fcd..a66d0de4 100644 --- a/popup.html +++ b/popup.html @@ -35,6 +35,10 @@ #unavailable { display: none; } + /* Never shown, but can be enabled with a style */ + .enable, .disable { + display: none; + } diff --git a/popup.js b/popup.js index e278788e..3d71e765 100644 --- a/popup.js +++ b/popup.js @@ -1,5 +1,5 @@ var styleTemplate = document.createElement("div"); -styleTemplate.innerHTML = "
"; +styleTemplate.innerHTML = "
"; var writeStyleTemplate = document.createElement("a"); writeStyleTemplate.className = "write-style-link"; @@ -78,6 +78,8 @@ function createStyleElement(style) { styleName.addEventListener("click", function() { enable(event, !event.target.previousSibling.checked); }, false); // clicking the checkbox will toggle it, and this will run after that happens checkbox.addEventListener("click", function() { enable(event, event.target.checked); }, false); + e.querySelector(".enable").addEventListener("click", function() { enable(event, true); }, false); + e.querySelector(".disable").addEventListener("click", function() { enable(event, false); }, false); e.querySelector(".delete").addEventListener("click", function() { doDelete(event, false); }, false); return e; From 4dca2e8e333b9a79ce4616b69ccf70d3da81fd88 Mon Sep 17 00:00:00 2001 From: Jason Barnabe Date: Tue, 17 Feb 2015 13:05:30 -0600 Subject: [PATCH 3/5] Sort styles in pop-up by name --- popup.js | 1 + 1 file changed, 1 insertion(+) diff --git a/popup.js b/popup.js index 3d71e765..dd182e7a 100644 --- a/popup.js +++ b/popup.js @@ -52,6 +52,7 @@ chrome.tabs.getSelected(null, function(tab) { }); function showStyles(styles) { + styles.sort(function(a, b) { return a.name.localeCompare(b.name)}); var installed = document.getElementById("installed"); if (styles.length == 0) { installed.innerHTML = "
" + t('noStylesForSite') + "
"; From a6616e5637b74941194ade558a692edf847f7fc9 Mon Sep 17 00:00:00 2001 From: Jason Barnabe Date: Tue, 17 Feb 2015 13:50:51 -0600 Subject: [PATCH 4/5] Fix defaulting of prefs --- edit.js | 4 ++-- manage.js | 2 +- storage.js | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/edit.js b/edit.js index d6324f1c..a2ea306f 100644 --- a/edit.js +++ b/edit.js @@ -19,7 +19,7 @@ function setupCodeMirror(textarea) { mode: 'css', lineNumbers: true, lineWrapping: true, - smartIndent: localStorage["smart-indent"] == null || localStorage["smart-indent"] == "true" + smartIndent: (typeof localStorage["smart-indent"] == "undefined") || localStorage["smart-indent"] == "true" }); editors.push(cm); } @@ -125,7 +125,7 @@ window.addEventListener("load", init, false); function init() { tE("sections-help", "helpAlt", "alt"); - loadPrefs(["smart-indent"]); + loadPrefs({"smart-indent": "true"}); var params = getParams(); if (!params.id) { // match should be 2 - one for the whole thing, one for the parentheses // This is an add diff --git a/manage.js b/manage.js index 3d34c009..8551e408 100644 --- a/manage.js +++ b/manage.js @@ -15,7 +15,7 @@ function showStyles(styles) { styles.map(createStyleElement).forEach(function(e) { installed.appendChild(e); }); - loadPrefs(["show-badge"]); + loadPrefs({"show-badge": "true"}); } function createStyleElement(style) { diff --git a/storage.js b/storage.js index 7a3e3604..da7eb75e 100644 --- a/storage.js +++ b/storage.js @@ -153,9 +153,10 @@ function changePref(event) { notifyAllTabs({method: "prefChanged", prefName: el.id, value: value}); } -function loadPrefs(prefNames) { - prefNames.forEach(function(id) { - var value = localStorage[id]; +// Accepts a hash of pref name to default value +function loadPrefs(prefs) { + for (var id in prefs) { + var value = typeof localStorage[id] == "undefined" ? prefs[id] : localStorage[id]; var el = document.getElementById(id); if (isCheckbox(el)) { if (value == "true") { @@ -165,5 +166,5 @@ function loadPrefs(prefNames) { el.value = value; } el.addEventListener("change", changePref); - }); + } } From adb54a4a884ab481f626039e36a14e7477b87389 Mon Sep 17 00:00:00 2001 From: Jason Barnabe Date: Tue, 17 Feb 2015 13:57:17 -0600 Subject: [PATCH 5/5] Disable logging of style applies logic --- background.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/background.js b/background.js index fe4f77b2..1f204e63 100644 --- a/background.js +++ b/background.js @@ -156,23 +156,23 @@ function sectionAppliesToUrl(section, url) { return false; } if (!section.urls && !section.domains && !section.urlPrefixes && !section.regexps) { - console.log(section.id + " is global"); + //console.log(section.id + " is global"); return true; } if (section.urls && section.urls.indexOf(url) != -1) { - console.log(section.id + " applies to " + url + " due to URL rules"); + //console.log(section.id + " applies to " + url + " due to URL rules"); return true; } if (section.urlPrefixes && section.urlPrefixes.some(function(prefix) { return url.indexOf(prefix) == 0; })) { - console.log(section.id + " applies to " + url + " due to URL prefix rules"); + //console.log(section.id + " applies to " + url + " due to URL prefix rules"); return true; } if (section.domains && getDomains(url).some(function(domain) { return section.domains.indexOf(domain) != -1; })) { - console.log(section.id + " applies due to " + url + " due to domain rules"); + //console.log(section.id + " applies due to " + url + " due to domain rules"); return true; } if (section.regexps && section.regexps.some(function(regexp) { @@ -191,10 +191,10 @@ function sectionAppliesToUrl(section, url) { } return (re).test(url); })) { - console.log(section.id + " applies to " + url + " due to regexp rules"); + //console.log(section.id + " applies to " + url + " due to regexp rules"); return true; } - console.log(section.id + " does not apply due to " + url); + //console.log(section.id + " does not apply due to " + url); return false; }