From 4ae56af683412111b8545491ece460dea14e6ecf Mon Sep 17 00:00:00 2001 From: Martin Scharm Date: Thu, 6 Oct 2011 15:06:18 +0200 Subject: [PATCH] version 1.3, changelog: * added support till ff 9.* * using prompts of nsIPromptService * uri's are encoded using encodeURIComponent * shortened url is imediately copied to clipboard * existing keywords are recognized * some debugging stuff was deleted * cancel now also cancels ;-) thanks a lot to RD! (http://binfalse.de/software/yourls-firefox-extension/comment-page-1/#comment-203) --- chrome/content/options.xul | 2 +- chrome/content/yourlsshortener.js | 36 +++++++++++++++++-------------- install.rdf | 2 +- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/chrome/content/options.xul b/chrome/content/options.xul index 6a45b43..be5bef5 100644 --- a/chrome/content/options.xul +++ b/chrome/content/options.xul @@ -32,7 +32,7 @@ - diff --git a/chrome/content/yourlsshortener.js b/chrome/content/yourlsshortener.js index 1ae6385..c6cf50a 100644 --- a/chrome/content/yourlsshortener.js +++ b/chrome/content/yourlsshortener.js @@ -1,6 +1,7 @@ var YOURLSshortener = function () { var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService (Components.interfaces.nsIPrefBranch); var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); + var clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper); return { gohome : function () { var api = prefManager.getCharPref ("extensions.yourls-shortener.api"); @@ -33,8 +34,8 @@ var YOURLSshortener = function () { return; } - alert (askforkey.value); - alert (maxwait.value); + //alert (askforkey.value); + //alert (maxwait.value); prefManager.setCharPref ("extensions.yourls-shortener.api", api.value); prefManager.setCharPref ("extensions.yourls-shortener.signature", signature.value); prefManager.setBoolPref ("extensions.yourls-shortener.askforkey", askforkey.checked); @@ -59,7 +60,7 @@ var YOURLSshortener = function () { { try { - var params = "action=shorturl&format=simple&url=" + long + "&signature=" + prefManager.getCharPref ("extensions.yourls-shortener.signature"); + var params = "action=shorturl&format=simple&url=" + encodeURIComponent (long) + "&signature=" + encodeURIComponent (prefManager.getCharPref ("extensions.yourls-shortener.signature")); if (prefManager.getBoolPref ("extensions.yourls-shortener.askforkey")) { @@ -70,9 +71,14 @@ var YOURLSshortener = function () { } catch (e) {} - var key = prompt ("Type your keyword here (leave empty to generate)", sel.toLowerCase ()); - if (key) - params += "&keyword=" + key; + var key = {value: sel}; + if (prompts.prompt (null, "YOURLS shortener: Keyword", "Type your keyword here (leave empty to generate)", key, null, {value: false})) + { + if (key.value) + params += "&keyword=" + encodeURIComponent (key.value); + } + else + return; } var maxwait = 1000 * prefManager.getIntPref ("extensions.yourls-shortener.maxwait"); @@ -96,16 +102,14 @@ var YOURLSshortener = function () { clearTimeout (requestTimer); if ((request.status == 200 || request.status == 201) && request.responseText.match(/^\s*\S+\s*$/)) { - if (request.responseText) - { - prompts.alert(null, "YOURLS shortener: short URL", long + "\n\nis shortened by:\n\n" + request.responseText); - return; - } - else - { - prompts.alert(null, "YOURLS shortener: failed", "Shortening failed.. Maybe invalid key!?"); - return; - } + prompts.alert (null, "YOURLS shortener: short URL", long + "\n\nis shortened by:\n\n" + request.responseText); + clipboard.copyString (request.responseText); + return; + } + else if ((request.status == 200 || request.status == 201) && request.responseText.match(/^\s*$/)) + { + prompts.alert(null, "YOURLS shortener: failed", "Shortening failed.. Maybe chosen key already in use!?\nTry again!"); + return; } else { diff --git a/install.rdf b/install.rdf index 6fab861..82e1156 100644 --- a/install.rdf +++ b/install.rdf @@ -14,7 +14,7 @@ {ec8030f7-c20a-464f-9b0e-13a3a9e97384} 3.0 - 6.* + 9.*