diff --git a/background.js b/background.js index 80e6ffe3..1f204e63 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 @@ -150,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) { @@ -185,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; } 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/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..dd182e7a 100644 --- a/popup.js +++ b/popup.js @@ -1,5 +1,5 @@ var styleTemplate = document.createElement("div"); -styleTemplate.innerHTML = "
" + t('editStyleLabel') + " " + t('deleteStyleLabel') + "
"; +styleTemplate.innerHTML = "
" + t('enableStyleLabel') + " " + t('disableStyleLabel') + " " + t('editStyleLabel') + " " + t('deleteStyleLabel') + "
"; var writeStyleTemplate = document.createElement("a"); writeStyleTemplate.className = "write-style-link"; @@ -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') + "
"; @@ -78,6 +79,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; 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); - }); + } }