Skip to content

Commit

Permalink
version 1.3, changelog:
Browse files Browse the repository at this point in the history
 * 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)
  • Loading branch information
binfalse committed Oct 6, 2011
1 parent 3133dfb commit 4ae56af
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion chrome/content/options.xul
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<checkbox id="askforkey" preference="yourls-shortener-askforkey"/>
</row>
<row>
<label control="maxwait" tooltiptext="How much time should we spend waiting for the API to respond? Minimum is 2 seconds." value="Max wait time (seconds)"/>
<label control="maxwait" tooltiptext="How much time should we spend waiting for the API to respond? Minimum is 2 seconds." value="Max wait time (s)"/>
<textbox id="maxwait" preference="yourls-shortener-maxwait"/>
</row>
<row>
Expand Down
36 changes: 20 additions & 16 deletions chrome/content/yourlsshortener.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -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"))
{
Expand All @@ -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");
Expand All @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>3.0</em:minVersion>
<em:maxVersion>6.*</em:maxVersion>
<em:maxVersion>9.*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
Expand Down

0 comments on commit 4ae56af

Please sign in to comment.