diff --git a/_locales/en/messages.json b/_locales/en/messages.json index f5890926..2cf4d1d7 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -227,6 +227,10 @@ } } }, + "stylishUnavailableForURL": { + "message": "(Stylish does not work on pages like this.)", + "description": "Note in the toolbar pop-up when on a URL Stylish can't affect" + }, "updateCheckFailBadResponseCode": { "message": "Update failed - server responded with code $code$.", "description": "Text that displays when an update check failed because the response code indicates an error", @@ -247,5 +251,13 @@ "updateCompleted": { "message": "Update completed.", "description": "Text that displays when an update completed" + }, + "writeStyleFor": { + "message": "Write style for: ", + "description": "Label for toolbar pop-up that precedes the links to write a new style" + }, + "writeStyleForURL": { + "message": "this URL", + "description": "Text for link in toolbar pop-up to write a new style for the current URL" } } diff --git a/background.js b/background.js index 637d07db..27d0f35e 100644 --- a/background.js +++ b/background.js @@ -295,18 +295,5 @@ function saveFromJSONStyleReloaded(updateType, style, callback) { } } -function getDomains(url) { - if (url.indexOf("file:") == 0) { - return []; - } - var d = /.*?:\/*([^\/]+)/.exec(url)[1]; - var domains = [d]; - while (d.indexOf(".") != -1) { - d = d.substring(d.indexOf(".") + 1); - domains.push(d); - } - return domains; -} - // Get the DB so that any first run actions will be performed immediately when the background page loads. getDatabase(function() {}, reportError); diff --git a/edit.js b/edit.js index 259bce7e..7b94add5 100644 --- a/edit.js +++ b/edit.js @@ -125,10 +125,16 @@ window.addEventListener("load", init, false); function init() { tE("sections-help", "helpAlt", "alt"); - var idMatch = /[&\?]id=([0-9]+)/.exec(location.href) - if (idMatch == null || idMatch.length != 2) { // match should be 2 - one for the whole thing, one for the parentheses + var params = getParams(); + if (!params.id) { // match should be 2 - one for the whole thing, one for the parentheses // This is an add - addSection(); + var section = {code: ""} + if (params.domain) { + section.domains = [params.domain]; + } else if (params.url) { + section.urls = [params.url]; + } + addSection(section); // default to enabled document.getElementById("enabled").checked = true document.title = t("addStyleTitle"); @@ -136,8 +142,7 @@ function init() { return; } // This is an edit - var id = idMatch[1]; - chrome.extension.sendMessage({method: "getStyles", id: id}, function(styles) { + chrome.extension.sendMessage({method: "getStyles", id: params.id}, function(styles) { var style = styles[0]; styleId = style.id; initWithStyle(style); @@ -304,6 +309,19 @@ function showHelp(text) { alert(text); } +function getParams() { + var params = {}; + var urlParts = location.href.split("?", 2); + if (urlParts.length == 1) { + return params; + } + urlParts[1].split("&").forEach(function(keyValue) { + var splitKeyValue = keyValue.split("=", 2); + params[decodeURIComponent(splitKeyValue[0])] = decodeURIComponent(splitKeyValue[1]); + }); + return params; +} + chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { var installed = document.getElementById("installed"); switch(request.name) { diff --git a/manifest.json b/manifest.json index 7eef12fb..1badcda6 100644 --- a/manifest.json +++ b/manifest.json @@ -11,6 +11,7 @@ }, "permissions": [ "tabs", + "webNavigation", "http://userstyles.org/", "https://userstyles.org/" ], diff --git a/popup.html b/popup.html index 6bd79b0a..ebac3416 100644 --- a/popup.html +++ b/popup.html @@ -26,11 +26,14 @@ margin-bottom: 0.5em; border-bottom: 1px solid black; } - #find-styles, #manage-styles { + #find-styles, #write-style, #manage-styles { font-size: smaller; } - #find-styles { - margin-bottom: 0.5em; + #find-styles, #write-style, #unavailable { + margin-bottom: 0.75em; + } + #unavailable { + display: none; } @@ -41,9 +44,12 @@
+ + +