# HG changeset patch # User Yoshiki Yazawa # Date 1218454619 -32400 # Node ID bebb38edfc612cc3dd2eebcc1fefcefaefc019a3 # Parent c14d52a3b2fe7505742412e6a6b53425e4cb6b37 removed dangling spaces. diff -r c14d52a3b2fe -r bebb38edfc61 chrome/content/tinyurl.js --- a/chrome/content/tinyurl.js Mon Aug 11 20:34:21 2008 +0900 +++ b/chrome/content/tinyurl.js Mon Aug 11 20:36:59 2008 +0900 @@ -10,10 +10,10 @@ 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; @@ -24,7 +24,7 @@ } } }, true); - + tinyurl_loaded = true; } } @@ -37,21 +37,21 @@ 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"); @@ -72,29 +72,29 @@ */ 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){ @@ -106,23 +106,23 @@ 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)){ +function tinyurl_createFromAnchor(){ + if(gContextMenu != null && (gContextMenu.getLinkURL || gContextMenu.linkURL)){ var url = (gContextMenu.getLinkURL) ? gContextMenu.getLinkURL() : gContextMenu.linkURL var tiny = new TinyUrl(url, null); @@ -134,14 +134,14 @@ 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"); } } @@ -161,7 +161,7 @@ //Copy var oClipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper); oClipboard.copyString(str); - + }catch(err){ throw err } } @@ -181,7 +181,7 @@ function tinyurl_gotoTinyUrl(){ opener.focus(); self.focus(); - + if(opener.gBrowser.addTab) opener.gBrowser.selectedTab = opener.gBrowser.addTab("http://tinyurl.com"); else @@ -194,54 +194,54 @@ * @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, "%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); @@ -251,25 +251,25 @@ 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); @@ -279,18 +279,18 @@ } } }; - + // Handle Error this.request.onerror = { handleEvent : function(e){ callback.error(obj); } } - + // Start Request this.request.send(""); } - + /** * Abort TinyUrl shrink request */ @@ -299,39 +299,39 @@ 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){ + onStopRequest : function(request, context, statusCode){ var location = request.getResponseHeader("Location"); anchor.setAttribute("title", location); }, - onDataAvailable : function(request, context, inputStream, offset, count){} + onDataAvailable : function(request, context, inputStream, offset, count){} }, null); - + } catch(e){ e = e; } - + } -} \ No newline at end of file +}