Skip to content

Commit

Permalink
version 1.5-rc1
Browse files Browse the repository at this point in the history
* added option to not show prompt after shortening
* added option to change icons after shortening
* added option to copy to clipboard after shortening
  • Loading branch information
binfalse committed Jun 26, 2013
1 parent 11c0616 commit 0256f7f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 3 deletions.
15 changes: 15 additions & 0 deletions chrome/content/options.xul
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<preference id="yourls-shortener-signature" name="extensions.yourls-shortener.signature" type="string"/>
<preference id="yourls-shortener-usesignature" name="extensions.yourls-shortener.usesignature" type="bool"/>
<preference id="yourls-shortener-askforkey" name="extensions.yourls-shortener.askforkey" type="bool"/>
<preference id="yourls-shortener-showprompt" name="extensions.yourls-shortener.showprompt" type="bool"/>
<preference id="yourls-shortener-copyclipboard" name="extensions.yourls-shortener.copyclipboard" type="bool"/>
<preference id="yourls-shortener-changeicons" name="extensions.yourls-shortener.changeicons" type="bool"/>
<preference id="yourls-shortener-maxwait" name="extensions.yourls-shortener.maxwait" type="int"/>
</preferences>

Expand All @@ -31,6 +34,18 @@
<label control="askforkey" tooltiptext="Do you want to provide keywords?" value="Ask for a keyword?"/>
<checkbox id="askforkey" preference="yourls-shortener-askforkey"/>
</row>
<row>
<label control="showprompt" tooltiptext="Should the extension show a prompt with the shortened link?" value="Show prompt after shortening?"/>
<checkbox id="showprompt" preference="yourls-shortener-showprompt"/>
</row>
<row>
<label control="copyclipboard" tooltiptext="Should the extension copy the shortened url to your clipboard?" value="Copy result to clipboard?"/>
<checkbox id="copyclipboard" preference="yourls-shortener-copyclipboard"/>
</row>
<row>
<label control="changeicons" tooltiptext="Should the extension update the icons in statusbar/toolbar depending on success of shortening?" value="Update Icons?"/>
<checkbox id="changeicons" preference="yourls-shortener-changeicons"/>
</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 (s)"/>
<textbox id="maxwait" preference="yourls-shortener-maxwait"/>
Expand Down
43 changes: 41 additions & 2 deletions chrome/content/yourlsshortener.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,32 @@ var YOURLSshortener = function () {
}
}
},
changeButtons : function (icon) {
var btn = document.getElementById("yourls-shortener-toolbar-button");
if (btn)
btn.style.listStyleImage = 'url("chrome://yourls-shortener/skin/' + icon + '")';
var btn = document.getElementById("yourls-shortener-status-bar-icon");
if (btn)
btn.src = 'chrome://yourls-shortener/skin/' + icon;
},
failed: function () {
if (!prefManager.getBoolPref ("extensions.yourls-shortener.changeicons"))
return;
this.changeButtons ("favicon-failed.gif");
var obj = this;
setTimeout (function () {
obj.changeButtons ("favicon.gif")
},3000);
},
success : function () {
if (!prefManager.getBoolPref ("extensions.yourls-shortener.changeicons"))
return;
this.changeButtons ("favicon-success.gif");
var obj = this;
setTimeout (function () {
obj.changeButtons ("favicon.gif")
},3000);
},
run : function (long) {

if (typeof gContextMenu != 'undefined' && gContextMenu.onLink)
Expand All @@ -82,6 +108,7 @@ var YOURLSshortener = function () {
api += '/';
api += "yourls-api.php";

var me = this;
if (api && api != "http://yoursite/")
{
try
Expand Down Expand Up @@ -120,6 +147,7 @@ var YOURLSshortener = function () {
var requestTimer = setTimeout (function () {
request.abort ();
prompts.alert(null, "YOURLS shortener: failed", "Did not get an answer from server!\nTry again later or increase maximum waiting time.");
me.failed ();
return;
}, maxwait);
request.onreadystatechange = function () {
Expand All @@ -128,18 +156,25 @@ var YOURLSshortener = function () {
clearTimeout (requestTimer);
if ((request.status == 200 || request.status == 201) && request.responseText.match(/^\s*\S+\s*$/))
{
prompts.alert (null, "YOURLS shortener: short URL", long + "\n\nis shortened by:\n\n" + request.responseText);
clipboard.copyString (request.responseText);
if (prefManager.getBoolPref ("extensions.yourls-shortener.showprompt"))
prompts.alert (null, "YOURLS shortener: short URL", long + "\n\nis shortened by:\n\n" + request.responseText);

if (prefManager.getBoolPref ("extensions.yourls-shortener.copyclipboard"))
clipboard.copyString (request.responseText);

me.success ();
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!");
me.failed ();
return;
}
else
{
prompts.alert(null, "YOURLS shortener: failed", "Do not understand the response from API!\nPlease check your signature and the API-URL.");
me.failed ();
return;
}
}
Expand All @@ -149,11 +184,15 @@ var YOURLSshortener = function () {
catch (e)
{
prompts.alert(null, "YOURLS shortener: failed", "Failed to start XMLHttpRequest:\n" + e.message);
me.failed ();
}

}
else
{
prompts.alert(null, "YOURLS shortener: failed", "No API-URL specified... Check your settings!");
me.failed ();
}
}
};
} ();
5 changes: 4 additions & 1 deletion defaults/preferences/prefs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
pref("extensions.yourls-shortener.api", "http://yoursite/");
pref("extensions.yourls-shortener.signature", "123456");
pref("extensions.yourls-shortener.askforkey", false);
pref("extensions.yourls-shortener.maxwait", 4);
pref("extensions.yourls-shortener.maxwait", 4);
pref("extensions.yourls-shortener.showprompt", true);
pref("extensions.yourls-shortener.copyclipboard", true);
pref("extensions.yourls-shortener.changeicons", true);
Binary file added skin/favicon-failed.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/favicon-success.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0256f7f

Please sign in to comment.