Mercurial > tinyurl_creator
changeset 0:c14d52a3b2fe
initial import
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,14 @@ +app=tinyurl +vers=_2_0_0 + +all: + cd chrome; zip -r $(app).jar content + zip -r $(app)$(vers).xpi chrome/$(app).jar install.rdf + +clean: + rm -f $(app)$(vers).xpi + rm -f chrome/$(app).jar + +mostlyclean: clean + find . -name "*~" -exec rm {} ';' + find . -name "#*#" -exec rm {} ';'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/contents.rdf Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,45 @@ +<?xml version="1.0"?> + +<RDF:RDF xmlns:chrome="http://www.mozilla.org/rdf/chrome#" + xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> + + <RDF:Seq about="urn:mozilla:package:root"> + <RDF:li resource="urn:mozilla:package:tinyurl"/> + </RDF:Seq> + + <RDF:Description about="urn:mozilla:package:tinyurl" + chrome:author="Jeremy Gillick" + chrome:authorURL="http://mozmonkey.com/" + chrome:description="TinyUrl brings the http://tinyurl.com functionality into your browser. It takes a long URL as input, and gives you a short URL to use in it's place." + chrome:displayName="TinyUrl Creator 1.0.5" + chrome:extension="true" + chrome:name="tinyurl" + chrome:settingsURL="chrome://tinyurl/content/dialogs/options.xul"> + <chrome:uninstallInfo> + <RDF:Seq> + <RDF:li>UChrm:tinyurl.rdf</RDF:li> + </RDF:Seq> + </chrome:uninstallInfo> + </RDF:Description> + + <RDF:Seq about="urn:mozilla:overlays"> + <RDF:li resource="chrome://browser/content/browser.xul"/> + <RDF:li resource="chrome://navigator/content/navigatorOverlay.xul"/> + <RDF:li resource="chrome://navigator/content/navigator.xul"/> + </RDF:Seq> + + <!-- Firefox --> + <RDF:Seq about="chrome://browser/content/browser.xul"> + <RDF:li>chrome://tinyurl/content/tinyurl_overlay.xul</RDF:li> + </RDF:Seq> + <RDF:Seq about="chrome://navigator/content/navigatorOverlay.xul"> + <RDF:li>chrome://tinyurl/content/tinyurl_overlay.xul</RDF:li> + </RDF:Seq> + + <!-- Mozilla --> + <RDF:Seq about="chrome://navigator/content/navigator.xul"> + <RDF:li>chrome://tinyurl/content/tinyurl_overlay.xul</RDF:li> + </RDF:Seq> + + +</RDF:RDF>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/contents.rdf.in Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,45 @@ +<?xml version="1.0"?> + +<RDF:RDF xmlns:chrome="http://www.mozilla.org/rdf/chrome#" + xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> + + <RDF:Seq about="urn:mozilla:package:root"> + <RDF:li resource="urn:mozilla:package:tinyurl"/> + </RDF:Seq> + + <RDF:Description about="urn:mozilla:package:tinyurl" + chrome:author="Jeremy Gillick" + chrome:authorURL="http://mozmonkey.com/" + chrome:description="TinyUrl brings the http://tinyurl.com functionality into your browser. It takes a long URL as input, and gives you a short URL to use in it's place." + chrome:displayName="TinyUrl Creator __VERSION__" + chrome:extension="true" + chrome:name="tinyurl" + chrome:settingsURL="chrome://tinyurl/content/dialogs/options.xul"> + <chrome:uninstallInfo> + <RDF:Seq> + <RDF:li>UChrm:tinyurl.rdf</RDF:li> + </RDF:Seq> + </chrome:uninstallInfo> + </RDF:Description> + + <RDF:Seq about="urn:mozilla:overlays"> + <RDF:li resource="chrome://browser/content/browser.xul"/> + <RDF:li resource="chrome://navigator/content/navigatorOverlay.xul"/> + <RDF:li resource="chrome://navigator/content/navigator.xul"/> + </RDF:Seq> + + <!-- Firefox --> + <RDF:Seq about="chrome://browser/content/browser.xul"> + <RDF:li>chrome://tinyurl/content/tinyurl_overlay.xul</RDF:li> + </RDF:Seq> + <RDF:Seq about="chrome://navigator/content/navigatorOverlay.xul"> + <RDF:li>chrome://tinyurl/content/tinyurl_overlay.xul</RDF:li> + </RDF:Seq> + + <!-- Mozilla --> + <RDF:Seq about="chrome://navigator/content/navigator.xul"> + <RDF:li>chrome://tinyurl/content/tinyurl_overlay.xul</RDF:li> + </RDF:Seq> + + +</RDF:RDF> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/create.js Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,89 @@ +var tiny = null; + +/** +* Create a TinyUrl from the current url +*/ +function tinyurl_create_load(){ + window.removeEventListener("load", tinyurl_create_load, true); + + if(window.arguments.length > 0 && tiny == null){ + tiny = window.arguments[0]; + + document.getElementById("cancel-btn").focus(); + + var loaded = { + done : function(oTiny){ + try{ + // Set values + document.getElementById("tinyurl-label").appendChild(document.createTextNode(oTiny.tiny)); + document.getElementById("loading-steps").selectedIndex = 1; + document.getElementById("cancel-btn").setAttribute("default", false); + document.getElementById("close1-btn").setAttribute("default", true); + document.getElementById("close1-btn").focus(); + + // Copy text + var clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper); + clipboard.copyString(oTiny.tiny); + + // Auto-hide the window + var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(""); + if(oPrefs.prefHasUserValue("tinyurl.confirmation.hide") && oPrefs.getBoolPref("tinyurl.confirmation.hide")){ + self.close(); + } + else{ + window.focus(); + } + }catch(e){ } + }, + + error : function(oTiny){ + document.getElementById("loading-steps").selectedIndex = 2; + document.getElementById("close2-btn").setAttribute("default", true); + document.getElementById("close2-btn").focus(); + } + } + + tiny.shrink(loaded); + } +} + +/** +* Cancel url shrinking +*/ +function tinyrl_create_cancel(){ + try{ + tiny.abort(); + }catch(e){ } + self.close(); +} + +/** +* Open save dialog +*/ +function tinyurl_create_openSave(){ + try{ + if(tinyurl_saved_add(tiny.tiny, tiny.original, tiny.title) == true){ + self.close(); + } + }catch(e){ + alert(e); + } +} + +/** +* Goto the url +*/ +function tinyurl_create_goto(){ + if(tiny.tiny == null){ + alert("An error occurred"); + } + + if(opener){ + opener.gBrowser.selectedTab = opener.gBrowser.addTab(tiny.tiny); + } + else{ + window.open(tiny.tiny); + } + + self.close(); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/create.xul Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,46 @@ +<?xml version="1.0"?> + +<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?> + + +<window id="tinyurl-create" title="Create TinyUrl" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + + + <script type="application/x-javascript" src="chrome://tinyurl/content/tinyurl.js"></script> + <script type="application/x-javascript" src="chrome://tinyurl/content/saved.js"></script> + <script type="application/x-javascript" src="chrome://tinyurl/content/create.js" /> + <script type="application/x-javascript"> + window.addEventListener("load", tinyurl_create_load, true); + </script> + + <keyset> + <key id="close-key" key="w" modifiers="accel" oncommand="self.close();" /> + </keyset> + + <deck id="loading-steps" style="background: #FFC; padding: 20px;" flex="1"> + <vbox pack="center" align="center"> + <label value="Loading...." /> + <spacer height="10" /> + <button id="cancel-btn" label="Cancel" oncommand="tinyrl_create_cancel()" default="true" /> + </vbox> + <vbox style="font-weight: bold; padding: 10px text-align: center;" flex="1" align="center" pack="center"> + <description id="tinyurl-label"></description> + <description style="font-weight: normal;">has been copied to your clipboard.</description> + <spacer height="7" /> + <hbox> + <button label="Close" id="close1-btn" oncommand="self.close()" /> + <button label="Goto" oncommand="tinyurl_create_goto();" style="font-weight: normal;" /> + <button label="Save" oncommand="tinyurl_create_openSave()" style="font-weight: normal;" /> + </hbox> + <spacer height="7" /> + </vbox> + <vbox pack="center" align="center"> + <description style="color: #F00;"> + An error occurred. Is your internet connection available? + </description> + <spacer height="10" /> + <button label="Close" id="close2-btn" oncommand="self.close()" /> + </vbox> + </deck> +</window> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/dialogs/options.js Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,27 @@ + +function tinyurl_initOptions(){ + try{ + var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(""); + + if(oPrefs.prefHasUserValue("tinyurl.update.notify")) + document.getElementById("tinyurl.update.notify").checked = oPrefs.getBoolPref("tinyurl.update.notify"); + if(oPrefs.prefHasUserValue("tinyurl.confirmation.hide")) + document.getElementById("tinyurl.confirmation.hide").checked = oPrefs.getBoolPref("tinyurl.confirmation.hide"); + + }catch(err){ alert("An unknown error occurred\n"+ err); } +} + +function tinyurl_saveOptions(){ + + try{ + + //Save + var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(""); + + oPrefs.setBoolPref("tinyurl.update.notify", document.getElementById("tinyurl.update.notify").checked); + oPrefs.setBoolPref("tinyurl.confirmation.hide", document.getElementById("tinyurl.confirmation.hide").checked); + + }catch(err){ alert("An unknown error occurred\n"+ err); } + + return true; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/dialogs/options.xul Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,23 @@ +<?xml version="1.0"?> + +<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?> + +<dialog buttons="accept,cancel" + id="tinyurl-options-dialog" + ondialogaccept="return tinyurl_saveOptions();" + ondialogcancel="return true;" + onload="tinyurl_initOptions()" + title="TinyUrl Options" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + + <script type="application/x-javascript" src="chrome://tinyurl/content/dialogs/options.js"></script> + + <groupbox style="width: 250px;"> + <caption label="General"/> + <checkbox id="tinyurl.update.notify" label="Notify me of updates" checked="true" /> + </groupbox> + <groupbox> + <caption label="Confirmation" /> + <checkbox id="tinyurl.confirmation.hide" label="Do not show confirmation dialog apon TinyUrl creation." /> + </groupbox> +</dialog> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/dialogs/update.js Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,33 @@ + +function tinyurl_update_notifyToggle(){ + + try{ + var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(""); + oPrefs.setBoolPref("tinyurl.update.notify", !document.getElementById("tinyurl.update.notify").checked); + }catch(err){} + + return true; +} + +function tinyurl_update_install(){ + try{ + //Window Argument is update XPI + if(window.arguments.length > 0 && typeof(window.arguments[0]) != 'undefined'){ + + var aInstall = new Array(); + aInstall["TinUrl"] = window.arguments[0]; + + InstallTrigger.install(aInstall, null); + } + //If no update XPI, redirect to download site + else{ + window.open(gTinyUrl_DownloadSite).focus(); + + if(opener != null) + opener.close(); + self.close(); + } + }catch(err){alert("An unknown error ocurred.\nCould not upgrade.")} + + return true; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/dialogs/update.xul Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,22 @@ +<?xml version="1.0"?> + +<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?> + +<!DOCTYPE dialog SYSTEM "chrome://switchproxy/locale/locale.dtd"> + +<dialog buttons="accept, cancel" + id="tinyUrlUpdate" + ondialogaccept="tinyurl_update_notifyToggle(); tinyurl_update_install(); return true;" + ondialogcancel="return tinyurl_update_notifyToggle();" + title="Upgrade TinyUrl Creator" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + + <script type="application/x-javascript" src="chrome://tinyurl/content/dialogs/update.js"></script> + + <vbox style="width: 250px;"> + <description> + A new version of the TinyUrl Creator is available. Would you like to install it now? + </description> + <checkbox label="Don't show this dialog again" id="tinyurl.update.notify" checked="false" /> + </vbox> +</dialog> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/done.xul Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,68 @@ +<?xml version="1.0"?> + +<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?> + +<dialog buttons="accept" id="tinyurl-done-window" + title="TinyUrl Done" + onload="tinyurl_done_load();" + onblur="tinyurl_autohide()" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + style="background: #FFC;"> + <script> + <![CDATA[ + var args = null; + + function tinyurl_done_load(){ + if(window.arguments.length > 0){ + args = new Array(); + args['tinyUrl'] = window.arguments[0]; + args['realUrl'] = window.arguments[1]; + args['title'] = (window.arguments.length > 2) ? window.arguments[2] : null; + + document.getElementById("tinyurl-label").appendChild(document.createTextNode(args['tinyUrl'])); + + window.focus(); + } + } + + function tinyurl_done_openSave(){ + if(opener != null && args != null){ + opener.tinyurl_saved_add(args['tinyUrl'], args['realUrl'], args['title']); + } + } + + function tinyurl_done_goto(){ + if(args['tinyUrl'] == null){ + alert("An error occurred"); + } + + if(opener){ + opener.gBrowser.selectedTab = opener.gBrowser.addTab(args['tinyUrl']); + } + else{ + window.open(args['tinyUrl']); + } + + self.close(); + } + + function tinyurl_autohide(){ + var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(""); + + if(oPrefs.prefHasUserValue("tinyurl.confirmation.hide") && oPrefs.getBoolPref("tinyurl.confirmation.hide")) + setTimeout("self.close()", 100); + } + ]]> + </script> + <vbox style="font-weight: bold; padding: 10px text-align: center;" flex="1" align="center" pack="center"> + <description id="tinyurl-label"></description> + <description style="font-weight: normal;">has been copied to your clipboard.</description> + <spacer height="7" /> + <hbox> + <button label="Close" oncommand="self.close()" tabindex="0" dlgtype="accept" /> + <button label="Goto" oncommand="tinyurl_done_goto();" tabindex="1" style="font-size: x-small; font-weight: normal;" /> + <button label="Save" tabindex="2" oncommand="tinyurl_done_openSave()" style="font-size: x-small; font-weight: normal;" /> + </hbox> + <spacer height="7" /> + </vbox> +</dialog> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/edit.js Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,72 @@ + +var sUri = null; +var oTitle = null; +var oTiny = null; + +// Load Data +function tinyurl_edit_load(){ + var aProps = new Array(); + + if(window.arguments.length > 0) + sUri = window.arguments[0]; + else + return; + + aProps = opener.tinyurl_saved_getEntry(sUri); + oTitle = document.getElementById("title-field"); + oTitle.value = aProps["title"]; + + oTiny = document.getElementById("tinyurl-label") + oTiny.value = aProps["tinyurl"]; + + document.getElementById("real-field").value = aProps["realurl"]; + + var sIcon = opener.tinyurl_saved_getFavIcon(aProps["realurl"]); + if(sIcon != "") + document.getElementById("icon-image").setAttribute("src", sIcon); + +} + +// Save New Title +function tinyurl_edit_save(){ + + try{ + // Verify not empty + if(oTitle.value == ""){ + alert("You must enter a title."); + oTitle.focus(); + return false; + } + + // Verify not duplicate + var sTitleUri = opener.tinyurl_saved_getUriForTitle(oTitle.value); + if(sTitleUri != null && sTitleUri != sUri){ + alert("A TinyUrl entry already exists with that title."); + oTitle.focus(); + return false; + } + + // Update + opener.tinyurl_saved_changeTitle(sUri, oTitle.value); + opener.tinyurl_saved_read(); + + }catch(err){ alert("Could not update this entry due to an unknown error.\n"+ err); return false; } + + return true; +} + +// Open TinyUrl +function tinyurl_edit_open(){ + + if(oTiny.value == "") + return; + + if(opener && opener.opener){ + opener.opener.gBrowser.selectedTab = opener.opener.gBrowser.addTab(oTiny.value); + } + else{ + window.open(oTiny.value); + } + + setTimeout("self.focus()", 100); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/options.js Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,25 @@ + +function tinyurl_options_init(){ + try{ + + var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(""); + + // Prefill + if(oPrefs.prefHasUserValue("tinyurl.confirmation.hide")) + document.getElementById("confirm-hide").checked = oPrefs.getBoolPref("tinyurl.confirmation.hide"); + + }catch(e){ alert("Could not load preferences.\n"+ e); } +} + +function tinyurl_options_save(){ + try{ + + var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(""); + + // Save + oPrefs.setBoolPref("tinyurl.confirmation.hide", document.getElementById("confirm-hide").checked); + + }catch(e){ alert("Could not save preferences.\n"+ e); return false; } + + return true; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/options.xul Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,19 @@ +<?xml version="1.0"?> +<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?> + +<dialog id="TinyUrlOptions" + buttons="accept,cancel" + title="TinyUrl Creator Options" + ondialogaccept="return tinyurl_options_save();" + ondialogcancel="return true;" + onload="copyplaintext_options_init();" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + + <script type="application/x-javascript" src="chrome://tinyurl/content/options.js"></script> + <groupbox> + <caption label="Confirmation" /> + + <checkbox id="confirm-hide" label="Make confirmation box automatically hide when it looses focus" /> + </groupbox> + +</dialog> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/saved.js Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,384 @@ + +var oProps = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties); +var sUserChrome = (oProps.get("UChrm", Components.interfaces.nsIFile)).path; +var sPathSeperator = "\\"; +if(sUserChrome[0].indexOf("/") > -1) sPathSeperator = "/"; + +var sTinyRdfName = "tinyurl.rdf"; +var sTinyRdfPath = sUserChrome + sPathSeperator + sTinyRdfName; + +// RDF Vars +var gTinyRdf = null; +var gTinyDs = null; +var gTinyRdfUtil = null; +var gTinyRdfC = null; +var gTinyRdfRoot = "http://jgillick.nettripper.com/tinyurl"; + +// Create RDF File if it does not exist +function tinyurl_saved_rdfCreate(){ + try{ + + var oFileLocal = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); + oFileLocal.initWithPath(sTinyRdfPath); + + // Doesn't Exist? + if(!oFileLocal.exists()){ + + // Read RDF + var oRequest = new XMLHttpRequest(); + oRequest.open("GET", "chrome://tinyurl/content/"+ sTinyRdfName, false); + oRequest.send(""); + var sContent = oRequest.responseText; + + // Write + oFileLocal.create(0x00, 0666); + var oFileOut = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream); + oFileOut.init(oFileLocal, 0x20 | 0x02, 00666, null); + oFileOut.write(sContent, sContent.length); + oFileOut.flush(); + oFileOut.close(); + } + + }catch(err){ } + +} + +// Enable Buttons +function tinyurl_saved_disable(dis){ + document.getElementById('go-saved-button').disabled = dis; + document.getElementById('copy-saved-button').disabled = dis; + document.getElementById('edit-saved-button').disabled = dis; + document.getElementById('remove-saved-button').disabled = dis; + + if(dis){ + document.getElementById('go-saved-button').image = "chrome://tinyurl/content/icons/go_off.png"; + document.getElementById('copy-saved-button').image = "chrome://tinyurl/content/icons/copy_off.png"; + document.getElementById('edit-saved-button').image = "chrome://tinyurl/content/icons/edit_off.png"; + document.getElementById('remove-saved-button').image = "chrome://tinyurl/content/icons/remove_off.png"; + } + else{ + document.getElementById('go-saved-button').image = "chrome://tinyurl/content/icons/go.png"; + document.getElementById('copy-saved-button').image = "chrome://tinyurl/content/icons/copy.png"; + document.getElementById('edit-saved-button').image = "chrome://tinyurl/content/icons/edit.png"; + document.getElementById('remove-saved-button').image = "chrome://tinyurl/content/icons/remove.png"; + } +} + +// Goto Saved Url +function tinyurl_saved_go(){ + var sUri = oSavedTree.contentView.getItemAtIndex(oSavedTree.currentIndex).getAttribute("uri"); + + // Get Real Url + try{ + var aProps = tinyurl_saved_getEntry(sUri); + + if(opener){ + opener.gBrowser.selectedTab = opener.gBrowser.addTab(aProps["realurl"]); + } + else{ + window.open(aProps["realurl"]); + } + + setTimeout("self.focus()", 100); + + }catch(err) { alert("Error: 560\n Could not access that URL\n"+ err); } +} + +// Copy TinyUrl +function tinyurl_saved_copy(){ + if(oSavedTree.currentIndex > -1){ + var sUri = oSavedTree.contentView.getItemAtIndex(oSavedTree.currentIndex).getAttribute("uri"); + try{ + var aProps = tinyurl_saved_getEntry(sUri); + tinyurl_copyText(aProps["tinyurl"]); + }catch(err){ alert("Error: 580\n Could not copy that URL\n"+ err); } + } +} + +// Open Edit Dialog +function tinyurl_saved_openEdit(){ + var sUri = oSavedTree.contentView.getItemAtIndex(oSavedTree.currentIndex).getAttribute("uri"); + + if(sUri != null && sUri != "") + window.openDialog('chrome://tinyurl/content/tinyurl_edit.xul','TinyUrlEditDialog','centerscreen, chrome, modal, resizable', sUri).focus() +} + +// Read RDF Entries +function tinyurl_saved_read(){ + if(oSavedTreeItems == null) + return; + + try{ + tinyurl_saved_initRdf(); + + // Remove All Existing + while(oSavedTreeItems.childNodes.length > 0) + oSavedTreeItems.removeChild(oSavedTreeItems.firstChild); + + // Read From RDF + var aProps = null; + var oTrgt = null; + var oTreeItem = null; + var oTreeRow = null; + var oTreeCell = null; + var aElements = gTinyRdfC.GetElements(); + while(aElements.hasMoreElements()){ + try{ + var oRes = aElements.getNext(); + oRes = oRes.QueryInterface(Components.interfaces.nsIRDFResource); + + oTreeItem = document.createElement("treeitem"); + oTreeItem.setAttribute("uri", oRes.Value); + oTreeRow = oTreeItem.appendChild(document.createElement("treerow")); + + aProps = tinyurl_saved_getEntry(oRes.Value); + + // Title + oTreeRow.appendChild(document.createElement("treecell")).setAttribute("label", aProps["title"]) + // TinyUrl + oTreeRow.appendChild(document.createElement("treecell")).setAttribute("label", aProps["tinyurl"]) + // Real Url + oTreeRow.appendChild(document.createElement("treecell")).setAttribute("label", aProps["realurl"]) + + oSavedTreeItems.appendChild(oTreeItem); + + }catch(err){ } + } + + tinyurl_saved_disable(true); + + }catch(err) { alert("Error 500\nAn unknown error occurred loading saved data\n"+ err); } +} + +// Remvoe RDF Entry +function tinyurl_saved_remove(){ + + var sUri = oSavedTree.contentView.getItemAtIndex(oSavedTree.currentIndex).getAttribute("uri"); + var iSelect = oSavedTree.currentIndex; + + if(sUri != null && sUri != "" && confirm("Are you SURE you want to remove this entry?")){ + try{ + tinyurl_saved_initRdf(); + + var oRes = gTinyRdf.GetResource(sUri); + + // Remove All Archs + var aArchs = null; + var hasArchs = true; + while(hasArchs){ + aArchs = gTinyDs.ArcLabelsOut(oRes); + hasArchs = aArchs.hasMoreElements(); + while(aArchs.hasMoreElements()){ + oArch = aArchs.getNext().QueryInterface(Components.interfaces.nsIRDFResource); + + //Remove + gTinyDs.Unassert(oRes, oArch, gTinyDs.GetTarget(oRes, oArch, true)); + } + } + + // Remove Element + gTinyRdfC.RemoveElement(oRes, true); + + // Rewrite Tree + tinyurl_saved_read() + + // Select Row + if(iSelect > oSavedTree.view.rowCount - 1){ + oSavedTree.view.selection.select(oSavedTree.view.rowCount - 1); + } + else{ + oSavedTree.view.selection.select(iSelect); + } + + }catch(err){ alert("Error 520\nCould not remove that entry.\n"+ err); } + } +} + +// Add RDF Entry +function tinyurl_saved_add(tinyUrl, realUrl, title){ + var sTitle = ""; + var sTimestamp = (new Date()).getTime(); + var sTiny = tinyUrl; + var sReal = realUrl; + var sPageTitle = (title == null) ? "" : title; + var sUri = "http://jgillick.nettripper.com/tinyurl/"; + var oRes = null; + + tinyurl_saved_rdfCreate(); + + // Get Uri + if(sTiny.length > "http://tinyurl.com/".length){ + sUri += sTiny.substring(("http://tinyurl.com/".length)); + } + else{ sUri = null; } + + // Is this TinyUrl already saved? + try{ + tinyurl_saved_initRdf(); + oRes = gTinyRdf.GetResource(sUri); + + if(gTinyRdfC.IndexOf(oRes) > -1){ + alert("You have already saved a TinyUrl entry for that URL.") + return false; + } + }catch(err){ } + + if(!sTiny || !sReal) + return; + + // Check Uri + if(sUri == null){ + alert("Error 540\nCould not save that TinyUrl.\n"+ tinyUrl); + return false; + } + + // Get Title + while(true){ + sTitle = prompt("Title to save it under:", sPageTitle); + + // Empty + if(sTitle == ""){ + alert("You must enter a title."); + } + // null (cancel) + else if(sTitle == null){ + break; + } + // Duplicate + else if(tinyurl_saved_getUriForTitle(sTitle) != null){ + alert("A saved TinyUrl entry already exists with that title."); + sTitle + } + else{ + break; + } + } + + if(sTitle != null){ + try{ + tinyurl_saved_initRdf() + var oRes = gTinyRdf.GetResource(sUri); + gTinyRdfC.AppendElement(oRes); + gTinyDs.Assert(oRes, gTinyRdf.GetResource("http://jgillick.nettripper.com/tinyurl/rdf#title"), gTinyRdf.GetLiteral(sTitle), true); + gTinyDs.Assert(oRes, gTinyRdf.GetResource("http://jgillick.nettripper.com/tinyurl/rdf#tinyurl"), gTinyRdf.GetLiteral(sTiny), true); + gTinyDs.Assert(oRes, gTinyRdf.GetResource("http://jgillick.nettripper.com/tinyurl/rdf#realurl"), gTinyRdf.GetLiteral(sReal), true); + gTinyDs.Assert(oRes, gTinyRdf.GetResource("http://jgillick.nettripper.com/tinyurl/rdf#created"), gTinyRdf.GetLiteral(sTimestamp), true); + + + // Rewrite Tree + tinyurl_saved_read(); + + return true; + }catch(err){ + alert("Error 541\nCould not save that TinyUrl.\n"+ err); + } + } + + return false; +} + +// Get favicon.ico for url +function tinyurl_saved_getFavIcon(sUrl){ + if(opener){ + + // Get Url for favicon.ico + var oUri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI); + oUri.spec = sUrl; + var sFavUri = opener.gBrowser.buildFavIconString(oUri); + + // Verify Exists + try{ + var oRequest = new XMLHttpRequest(); + oRequest.open("GET", sFavUri, false); + oRequest.send(""); + + if(oRequest.status == 200) + return sFavUri; + + }catch(err) { } + } + + return ""; +} + + +// Get Data From Entry +function tinyurl_saved_getEntry(sUri){ + var aProps = new Array(); + + try{ + tinyurl_saved_initRdf(); + + var oRes = gTinyRdf.GetResource(sUri); + + // Get Resources + aProps["title"] = gTinyDs.GetTarget(oRes, gTinyRdf.GetResource("http://jgillick.nettripper.com/tinyurl/rdf#title"), true); + aProps["tinyurl"] = gTinyDs.GetTarget(oRes, gTinyRdf.GetResource("http://jgillick.nettripper.com/tinyurl/rdf#tinyurl"), true); + aProps["realurl"] = gTinyDs.GetTarget(oRes, gTinyRdf.GetResource("http://jgillick.nettripper.com/tinyurl/rdf#realurl"), true); + aProps["created"] = gTinyDs.GetTarget(oRes, gTinyRdf.GetResource("http://jgillick.nettripper.com/tinyurl/rdf#created"), true); + + // Get Values + (aProps["title"] instanceof Components.interfaces.nsIRDFLiteral) ? aProps["title"] = aProps["title"].Value : aProps["title"] = ""; + (aProps["tinyurl"] instanceof Components.interfaces.nsIRDFLiteral) ? aProps["tinyurl"] = aProps["tinyurl"].Value : aProps["tinyurl"] = ""; + (aProps["realurl"] instanceof Components.interfaces.nsIRDFLiteral) ? aProps["realurl"] = aProps["realurl"].Value : aProps["realurl"] = ""; + (aProps["created"] instanceof Components.interfaces.nsIRDFLiteral) ? aProps["created"] = aProps["created"].Value : aProps["created"] = ""; + + }catch(err){ throw err; } + + return aProps; +} + +// Get Uri for title +function tinyurl_saved_getUriForTitle(sTitle){ + try{ + tinyurl_saved_initRdf(); + + var oSubject = gTinyDs.GetSource(gTinyRdf.GetResource("http://jgillick.nettripper.com/tinyurl/rdf#title"), gTinyRdf.GetLiteral(sTitle), true); + if(oSubject instanceof Components.interfaces.nsIRDFResource) + return oSubject.Value + + }catch(err) { throw err; } + + return null; +} + +// Change Title to sTitle for sUri +function tinyurl_saved_changeTitle(sUri, sTitle){ + try{ + tinyurl_saved_initRdf(); + + var oRes = gTinyRdf.GetResource(sUri); + var oProp = gTinyRdf.GetResource("http://jgillick.nettripper.com/tinyurl/rdf#title"); + var sOld = gTinyDs.GetTarget(oRes, oProp, true); // Old Value + + //Change + gTinyDs.Change(oRes, oProp, sOld, gTinyRdf.GetLiteral(sTitle)); + + }catch(err) { throw err; } + + return null; +} + + +// Init RDF Objects +function tinyurl_saved_initRdf(){ + try{ + if(gTinyRdf == null) + gTinyRdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService); + if(gTinyDs == null) + gTinyDs = gTinyRdf.GetDataSourceBlocking("file:///"+ sTinyRdfPath); + if(gTinyRdfUtil == null) + gTinyRdfUtil = Components.classes["@mozilla.org/rdf/container-utils;1"].getService(Components.interfaces.nsIRDFContainerUtils); + if(gTinyRdfC == null){ + gTinyRdfC = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer); + + //Get or Add Sequence + if(gTinyRdfUtil.IsSeq(gTinyDs, gTinyRdf.GetResource(gTinyRdfRoot))){ + gTinyRdfC.Init(gTinyDs, gTinyRdf.GetResource(gTinyRdfRoot)); + }else{ + gTinyRdfC = gTinyRdfUtil.MakeSeq(gTinyDs, gTinyRdf.GetResource(gTinyRdfRoot)); //Create + } + } + + }catch(err){throw err} +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/tinyurl.js Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,337 @@ + +var oLongUrlField = null; +var oTabBox = null; +var oSavedTree = null; +var oSavedTreeItems = null; +var tinyurl_loaded = false; + +function tinyurl_overlayInit(){ + try{ + var oContext = document.getElementById("contentAreaContextMenu"); + oContext.setAttribute("onpopupshowing", "tinyurl_contextShowing(event); "+ oContext.getAttribute("onpopupshowing")); + } catch(err) { alert(err); } + + // Update all links with preview title attribute + if(gBrowser && !tinyurl_loaded){ + + gBrowser.addEventListener("load", function(){ + var tiny = new TinyUrl(); + var doc = gBrowser.selectedBrowser.contentDocument; + var anchors = doc.getElementsByTagName("a"); + for(var i = 0; i < anchors.length; i++){ + if(anchors[i].href.indexOf("http://tinyurl.com/") == 0){ + tiny.addPreview(anchors[i]); + } + } + }, true); + + tinyurl_loaded = true; + } +} + +/** +* Load TinyUrl dialog +*/ +function tinyurl_load(){ + oLongUrlField = document.getElementById("longurl-field"); + oTabBox = document.getElementById("tinyurl-tabs"); + oSavedTree = document.getElementById("saved-tree"); + oSavedTreeItems = document.getElementById("saved-items"); + + // Cancel button + document.getElementById('tinyurlDialog').getButton('cancel').setAttribute("label", "Close"); + + // Is RDF Present + tinyurl_saved_rdfCreate(); + + // Load Saved Data + tinyurl_saved_read(); + + // Preload Field + if(opener.gBrowser && opener.gBrowser.currentURI){ + oLongUrlField.value = opener.gBrowser.currentURI.spec; + } + + // Goto Save Tab + if(window.arguments.length > 0 && window.arguments[0] == "saved"){ + oTabBox.selectedTab = document.getElementById("tinyurl-saved-tab"); + oTabBox.selectedPanel = document.getElementById("tinyurl-saved-tabpanel"); + } +} + +/** +* Create TinyUrl from current page +*/ +function tinyurl_createFromCurrent(){ + var tiny = new TinyUrl(gBrowser.currentURI.spec, window._content.document.title); + window.openDialog('chrome://tinyurl/content/create.xul','TinyUrlCreate','chrome, centerscreen, resizable', tiny); +} + +/** +* Creat new Tiny Url from dialog +*/ +function tinyurl_createNew(){ + try{ + + // If not in main tab + if(oTabBox.selectedTab.id != "tinyurl-create-tab"){ + return; + } + + // Validate + if(oLongUrlField == null || oLongUrlField.value == ""){ + alert("You have not entered a long url"); + return; + } + + document.getElementById("tinyurl-field").value = "Loading..."; + + // Title + var sTitle = ""; + if(opener && oLongUrlField.value == opener.gBrowser.currentURI.spec){ + sTitle = opener.window._content.document.title; + } + + // Get TinyUrl + var tiny = new TinyUrl(oLongUrlField.value, sTitle); + + // Output + var loaded = { + done : function(oTiny){ + if(oTiny.tiny != null){ + document.getElementById("tinyurl-field").value = oTiny.tiny; + document.getElementById("copy-button").disabled = false; + document.getElementById("save-button").setAttribute("oncommand", "tinyurl_saved_add('"+ oTiny.tiny +"', '"+ oTiny.original +"');"); + document.getElementById("save-button").disabled = false; + document.getElementById('tinyurlDialogMain').style.cursor = "default"; + } + }, + + error : function(oTiny){ + document.getElementById("tinyurl-field").value = ""; + alert("An error occurred.\nIs your internet connection available?"); + } + } + + tiny.shrink(loaded); + + }catch(err){ alert("Error 120\nAn unknown error occurred\n"+ err); } +} + +/** +* Create TinyUrl from anchor on page +*/ +function tinyurl_createFromAnchor(){ + if(gContextMenu != null && (gContextMenu.getLinkURL || gContextMenu.linkURL)){ + var url = (gContextMenu.getLinkURL) ? gContextMenu.getLinkURL() : gContextMenu.linkURL + var tiny = new TinyUrl(url, null); + + window.openDialog('chrome://tinyurl/content/create.xul','TinyUrlCreate','chrome, centerscreen, resizable', tiny); + } +} + +//Send text to tinyurl_copyText() +function tinyurl_copy(){ + try{ + var oField = document.getElementById("tinyurl-field"); + + if(oField == null || oField.value == ""){ + return; + } + + //Copy + tinyurl_copyText(oField.value); + + }catch(err){ alert("Error 140\nCouldn't copy to clipboard"); } +} + +// Comand from key stroke +function tinyurl_copy_command(){ + if(oTabBox.selectedTab.id == "tinyurl-create-tab"){ + tinyurl_copy(); + } + else if(oTabBox.selectedTab.id == "tinyurl-saved-tab"){ + tinyurl_saved_copy(); + } +} + +//Copies str to clipboard +function tinyurl_copyText(str){ + try{ + //Copy + var oClipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper); + oClipboard.copyString(str); + + }catch(err){ throw err } +} + +// Context Showing +function tinyurl_contextShowing(event){ + try{ + if(document.popupNode.nodeName.toUpperCase() == "A"){ + document.getElementById("tinyurl-context-link-menu").setAttribute("collapsed", false); + } + else { + document.getElementById("tinyurl-context-link-menu").setAttribute("collapsed", true); + } + } catch(e) {} +} + +//Opens http://tinyurl.com +function tinyurl_gotoTinyUrl(){ + opener.focus(); + self.focus(); + + if(opener.gBrowser.addTab) + opener.gBrowser.selectedTab = opener.gBrowser.addTab("http://tinyurl.com"); + else + window.open("http://tinyurl.com"); +} + + + +/** +* @constructor +*/ +function TinyUrl(url, title){ + + /** + * Original url + * @type string + */ + this.original = url; + + /** + * Shunken url + * @type string + */ + this.tiny = null; + + /** + * Title of the page from the original url. + * Used for when the user selects to save the tiny url. + * @type string + */ + this.title = title; + + /** + * @type XMLHttpRequest + */ + this.request = null; + + + /** + * Make the long url tiny + */ + this.shrink = function(callback){ + + // No need to shrink + if(this.tiny != null){ + return; + } + + // Abort current request + if(this.request != null){ + this.request.abort(); + } + + // Encode URL (can't use encodeURIComponent, because TinyUrl.com will choke) + var url = this.original; + url = url.replace(/\+/g, "%2B"); + url = url.replace(/\?/g, '%3F'); + url = url.replace(/&/g, '%26'); + url = url.replace(/=/g, '%3D'); + + // Setup Request + this.request = new XMLHttpRequest(); + this.request.open("GET", "http://tinyurl.com/api-create.php?url="+ url, true); + this.request.setRequestHeader("User-Agent", navigator.userAgent); + this.request.setRequestHeader("Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1"); + this.request.setRequestHeader("Accept-Language", navigator.language); + this.request.setRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); + this.request.setRequestHeader("Referer", "http://tinyurl.com/"); + this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + + var obj = this; + + // Handle request + this.request.onload = { + handleEvent : function(e){ + + // If already aborted + if(obj.request == null){ + return; + } + + //Parse Response + obj.tiny = null; + var url = obj.request.responseText; + if(url.length < 200){ // must have returned more than the URL if more than 200 + obj.tiny = url; + } + + // Notify callback function + if(obj.tiny == null){ + callback.error(obj); + } + else{ + callback.done(obj); + } + } + }; + + // Handle Error + this.request.onerror = { + handleEvent : function(e){ + callback.error(obj); + } + } + + // Start Request + this.request.send(""); + } + + /** + * Abort TinyUrl shrink request + */ + this.abort = function(){ + try{ + this.request.abort(); + }catch(e){ } + } + + /** + * Add a the full URL to an link with a TinyURL + * @param {Anchor} anchor The anchor tag with a TinyURL + */ + this.addPreview = function(anchor){ + + // Find where it redirects to + try{ + + // Setup request objects + var io = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService); + var uri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI); + uri.spec = anchor.href; + var request = io.newChannelFromURI(uri).QueryInterface(Components.interfaces.nsIHttpChannel); + + request.redirectionLimit = 0; + request.requestMethod = "HEAD"; + + // Start request and find redirect location + request.asyncOpen({ + onStartRequest : function(request, context){ }, + onStopRequest : function(request, context, statusCode){ + var location = request.getResponseHeader("Location"); + anchor.setAttribute("title", location); + }, + onDataAvailable : function(request, context, inputStream, offset, count){} + }, null); + + } catch(e){ + e = e; + } + + + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/tinyurl.rdf Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,15 @@ +<?xml version="1.0"?> +<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:TINYURL="http://jgillick.nettripper.com/tinyurl/rdf#"> + + <RDF:Seq about="http://jgillick.nettripper.com/tinyurl"> + <RDF:li> + <RDF:Description about="http://jgillick.nettripper.com/tinyurl/28jt3"> + <TINYURL:title>Free Mozilla Extensions</TINYURL:title> + <TINYURL:tinyurl>http://tinyurl.com/6owxl</TINYURL:tinyurl> + <TINYURL:realurl>http://mozmonkey.com/</TINYURL:realurl> + <TINYURL:created>1146780543620</TINYURL:created> + </RDF:Description> + </RDF:li> + </RDF:Seq> +</RDF:RDF> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/tinyurl_dialog.xul Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,87 @@ +<?xml version="1.0"?> +<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?> + +<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + id="tinyurlDialog" title="TinyUrl Creator" + buttons="cancel, accept" + onload="tinyurl_load();" + ondialogaccept="document.getElementById('tinyurlDialogMain').style.cursor = 'wait'; tinyurl_createNew(); return false;" + ondialogcancel="if(opener != null)opener.focus(); return true;" + persist="width height" style="padding: 1px; margin: 0;" + buttonpack="center" buttonalign="center"> + <script type="application/x-javascript" src="chrome://tinyurl/content/tinyurl.js"></script> + <script type="application/x-javascript" src="chrome://tinyurl/content/saved.js"></script> + + <keyset> + <key id="copy-key" key="c" modifiers="control" oncommand="tinyurl_copy_command();" /> + <key id="close-key" key="w" modifiers="accel" oncommand="self.close();" /> + </keyset> + + <vbox flex="1" style="overflow: auto; padding: 7px;"> + <tabbox id="tinyurl-tabs" flex="1"> + <tabs> + <tab label="Create" id="tinyurl-create-tab" /> + <tab label="Saved" id="tinyurl-saved-tab" /> + </tabs> + <tabpanels flex="1"> + + <!-- Create TinyUrl --> + <tabpanel id="tinyurl-create-tab" orient="vertical" flex="1" align="center"> + <grid flex="1" id="tinyurlDialogMain"> + <rows> + <row align="center"> + <label value="Long URL:" style="font-weight: bold;"/> + <textbox id="longurl-field" value="" flex="1" /> + <button id="create-button" label="Get Tiny Url" dlgtype="accept" /> + </row> + <row align="center"> + <label value="Tiny URL:" style="font-weight: bold;" /> + <textbox id="tinyurl-field" value="" flex="1" readonly="true" /> + <button id="copy-button" label="Copy" oncommand="tinyurl_copy()" disabled="true" /> + <button id="save-button" label="Save" oncommand="" disabled="true" /> + </row> + </rows> + </grid> + </tabpanel> + + <!-- Veiw Saved TinyUrl's --> + <tabpanel id="tinyurl-saved-tabpanel" orient="vertical" flex="1"> + <tree id="saved-tree" flex="2" rows="5" seltype="single" onselect="tinyurl_saved_disable(false)" hidecolumnpicker="false" stlye="overflow: auto;"> + <treecols> + <treecol label="Title" id="title-col" flex="3" fixed="false" persist="width ordinal hidden" /> + <splitter class="tree-splitter" /> + <treecol label="Tiny Url" id="tiny-col" flex="2" fixed="false" persist="width ordinal hidden" /> + <splitter class="tree-splitter" /> + <treecol label="Real Url" id="real-col" flex="3" fixed="false" hidden="true" persist="width ordinal hidden" /> + </treecols> + <treechildren id="saved-items"> + <!-- + <treeitem container="true" open="true"> + <treerow> + <treecell label="Test1"/> + </treerow> + </treeitem> + --> + </treechildren> + </tree> + <spacer height="5" width="1" /> + <hbox pack="center" align="center"> + <button id="go-saved-button" label="Go" disabled="true" oncommand="tinyurl_saved_go();" image="chrome://tinyurl/content/icons/go_off.png" /> + <button id="copy-saved-button" label="Copy" disabled="true" oncommand="tinyurl_saved_copy()" image="chrome://tinyurl/content/icons/copy_off.png" /> + <button id="edit-saved-button" label="View / Edit" disabled="true" oncommand="tinyurl_saved_openEdit();" image="chrome://tinyurl/content/icons/edit_off.png" /> + <button id="remove-saved-button" label="Remove" disabled="true" oncommand="tinyurl_saved_remove();" image="chrome://tinyurl/content/icons/remove_off.png" /> + </hbox> + </tabpanel> + </tabpanels> + </tabbox> + </vbox> + + <hbox> + <hbox pack="center" align="center" flex="2"> + <label id="disclaimer_1" value="This extension uses" style="color: #666; font-size: xx-small;" /> + <label id="disclaimer_2" value="http://tinyurl.com" style="color: #00F; font-size: xx-small; margin-left: 0; text-decoration: underline; cursor: pointer;" onclick="tinyurl_gotoTinyUrl();" /> + <label id="disclaimer_3" value="to generate URLs" style="color: #666; font-size: xx-small; margin-left: 0;" /> + </hbox> + <resizer id="windowResizer" dir="bottomright" /> + </hbox> +</dialog> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/tinyurl_edit.xul Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,35 @@ +<?xml version="1.0"?> +<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?> + +<dialog buttons="cancel, accept" + id="tinyurlEditDialog" + ondialogaccept="return tinyurl_edit_save();" + ondialogcancel="return true;" + onload="tinyurl_edit_load();" + title="TinyUrl - Edit" height="300" width="300" persist="height width" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" style="padding: 1px; margin: 0;"> + + <script type="application/x-javascript" src="chrome://tinyurl/content/edit.js"></script> + + <vbox flex="1" style="overflow: auto; padding: 7px;"> + <textbox id="title-field" value="" /> + + <hbox style="margin: 10px 3px;"> + <image id="icon-image" src="chrome://tinyurl/content/icons/document.png" /> + <label id="tinyurl-label" value="" style="color: #00F; text-decoration: underline; cursor: pointer;" onclick="tinyurl_edit_open()" /> + </hbox> + + <textbox id="real-field" value="" readonly="true" multiline="true" rows="3" wrap="true" /> + + <spacer height="50" width="1" /> + </vbox> + + <hbox> + <hbox pack="center" align="center" flex="2"> + <spacer height="1" width="20" /> + <button value="Apply" dlgtype="accept" /> + <button value="Cancel" dlgtype="cancel" /> + </hbox> + <resizer id="windowResizer" dir="bottomright" /> + </hbox> +</dialog> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/tinyurl_overlay.xul Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,85 @@ +<?xml version="1.0"?> + +<overlay id="tinyurl" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + + <script type="application/x-javascript" src="chrome://tinyurl/content/tinyurl.js"></script> + <script type="application/x-javascript" src="chrome://tinyurl/content/saved.js"></script> + <script language="JavaScript"> + //Window Event Handers + try{window.addEventListener("load", tinyurl_overlayInit, true);}catch(e){} + </script> + + + <!-- Firefox Toolbar Icon --> + <toolbarpalette id="BrowserToolbarPalette"> + <toolbarbutton type="menu" label="TinyUrl" + id="tinyurl-button" tooltiptext="Tiny Url Creator" + image="chrome://tinyurl/content/icons/button.png"> + <menupopup> + <menuitem label="New..." + oncommand="window.openDialog('chrome://tinyurl/content/tinyurl_dialog.xul','TinyUrlDialog','centerscreen, chrome, resizable').focus();" + accesskey="N" + style="font-weight: bold;" /> + <menuitem label="From Current URL" + oncommand="tinyurl_createFromCurrent();" + accesskey="C" /> + <menuitem label="View Saved" + oncommand="window.openDialog('chrome://tinyurl/content/tinyurl_dialog.xul','TinyUrlDialog','centerscreen, chrome, resizable', 'saved').focus();" + accesskey="S" /> + <menuitem label="Options..." + oncommand="window.openDialog('chrome://tinyurl/content/dialogs/options.xul','TinyUrlOptions','centerscreen, chrome, resizable').focus();" + accesskey="O" /> + </menupopup> + </toolbarbutton> + </toolbarpalette> + + <!-- Firefox Tools File Menu --> + <menupopup id="menu_ToolsPopup"> + <menu id="tinyurl-tools-menu" label="TinyUrl Creator" + accesskey="T" class="menuitem-iconic" + insertafter="devToolsSeparator"> + <menupopup> + <menuitem label="New..." + oncommand="window.openDialog('chrome://tinyurl/content/tinyurl_dialog.xul','TinyUrlDialog','centerscreen, chrome, resizable').focus();" + accesskey="N" /> + <menuitem label="From Current URL" + oncommand="tinyurl_createFromCurrent();" + accesskey="C" /> + <menuitem label="View Saved" + oncommand="window.openDialog('chrome://tinyurl/content/tinyurl_dialog.xul','TinyUrlDialog','centerscreen, chrome, resizable', 'saved').focus();" + accesskey="S" /> + <menuitem label="Options..." + oncommand="window.openDialog('chrome://tinyurl/content/dialogs/options.xul','TinyUrlOptions','centerscreen, chrome, resizable').focus();" + accesskey="O" /> + </menupopup> + </menu> + </menupopup> + + <!-- Mozilla Tools File Menu --> + <menupopup id="taskPopup"> + <menu id="tinyurl-moz-menu" label="TinyURL Creator" accesskey="T" insertafter="devToolsSeparator"> + <menupopup> + <menuitem label="New..." + oncommand="window.openDialog('chrome://tinyurl/content/tinyurl_dialog.xul','TinyUrlDialog','centerscreen, chrome, resizable').focus();" + accesskey="N" /> + <menuitem label="From Current URL" + oncommand="tinyurl_createFromCurrent();" + accesskey="C" /> + <menuitem label="View Saved" + oncommand="window.openDialog('chrome://tinyurl/content/tinyurl_dialog.xul','TinyUrlDialog','centerscreen, chrome, resizable', 'saved').focus();" + accesskey="S" /> + <menuitem label="Options..." + oncommand="window.openDialog('chrome://tinyurl/content/dialogs/options.xul','TinyUrlOptions','centerscreen, chrome, resizable').focus();" + accesskey="O" /> + </menupopup> + </menu> + </menupopup> + + + <!-- Context Menu --> + <popup id="contentAreaContextMenu"> + <menuitem id="tinyurl-context-link-menu" label="Create TinyUrl for this Link" oncommand="tinyurl_createFromAnchor(this);" insertafter="context-openlinkintab" collapsed="false" /> + <menuitem id="tinyurl-context-page-menu" label="Create TinyUrl for this Page" oncommand="tinyurl_createFromCurrent();" insertafter="tinyurl-context-link-menu, context-savepage" /> + </popup> +</overlay> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/install.js Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,54 @@ + +const gName = "TinyUrl Creator"; +const gAuthor = "Jeremy Gillick"; +const gRegKey = "/JeremyGillick/TinyUrl"; +const gVersion = "1.0.5"; +const gJar = "tinyurl.jar"; +const gFolderName = "tinyurl"; + +var error = null; +var oFolder = getFolder("Current User", "chrome"); +var iContentFlag = CONTENT | PROFILE_CHROME; + +// Install in App or Profile? +var existsInApplication = File.exists(getFolder(getFolder("chrome"), gJar)); +var existsInProfile = File.exists(getFolder(oFolder, gJar)); +if(existsInApplication || (!existsInProfile && !confirm("Do you want to install the extension into your profile folder?\n(Cancel will install into the application folder)"))) +{ + iContentFlag = CONTENT | DELAYED_CHROME; + oFolder = getFolder("chrome"); +} + +// Uninstall Current +if(existsInApplication || existsInProfile) + uninstall(gRegKey); + +// Init +initInstall(gName, gRegKey, gVersion); +setPackageFolder(oFolder); +error = addFile(gAuthor, gVersion, "chrome/"+ gJar, oFolder, null); + +// Register +if(error == SUCCESS){ + registerChrome(iContentFlag, getFolder(oFolder, gJar), "content/"); + + error = performInstall(); //Install + + if(error != SUCCESS && error != 999){ + switch(error){ + case -215: + alert("The installation of the extension failed.\nOne of the files being overwritten is read-only."); + break; + case -235: + alert("The installation of the extension failed.\nThere is insufficient disk space."); + break; + default: + alert("The installation of the extension failed.\nThe error code is: " + error); + } + cancelInstall(error); + } +} +else{ + alert("The installation failed.\n" + error); + cancelInstall(error); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/install.rdf Mon Aug 11 20:34:21 2008 +0900 @@ -0,0 +1,27 @@ +<?xml version="1.0"?> +<RDF:RDF xmlns:em="http://www.mozilla.org/2004/em-rdf#" + xmlns:NC="http://home.netscape.com/NC-rdf#" + xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> + <RDF:Description RDF:about="rdf:#$i2FEE3" + em:id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}" + em:minVersion="1.5" + em:maxVersion="3.0.*" /> + <RDF:Description RDF:about="urn:mozilla:extension:file:tinyurl.jar" + em:package="content/" /> + <RDF:Description RDF:about="rdf:#$n2FEE3" + em:id="{86c18b42-e466-45a9-ae7a-9b95ba6f5640}" + em:minVersion="1.6" + em:maxVersion="1.8" /> + <RDF:Description RDF:about="urn:mozilla:install-manifest" + em:id="{89736E8E-4B14-4042-8C75-AD00B6BD3900}" + em:name="TinyUrl Creator" + em:version="1.0.5" + em:description="Convenient tool to create small url redirects from longer ones." + em:creator="Jeremy Gillick" + em:homepageURL="http://mozmonkey.com/" + em:optionsURL="chrome://tinyurl/content/dialogs/options.xul"> + <em:file RDF:resource="urn:mozilla:extension:file:tinyurl.jar"/> + <em:targetApplication RDF:resource="rdf:#$i2FEE3"/> + <em:targetApplication RDF:resource="rdf:#$n2FEE3"/> + </RDF:Description> +</RDF:RDF>