Mercurial > my-ubiquity-commands
view chromeless-browsing/chromeless.js @ 16:426e9c04c6f9
Executing the 'where-am-i' command now copies the current URL to your clipboard.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Wed, 01 Apr 2009 12:25:48 -0700 |
parents | 8e00d50976d9 |
children |
line wrap: on
line source
CmdUtils.CreateCommand( {name: "go", takes: {"search terms": /.*/}, preview: function(pblock, dobj) { if (dobj.text.length == 0) { pblock.innerHTML = "<b>Please enter a search term.</b>"; return; } var history = Cc["@mozilla.org/autocomplete/search;1?name=history"] .createInstance(Ci.nsIAutoCompleteSearch); var observer = { onSearchResult: function onSearchResult(search, result) { if (result.searchResult == result.RESULT_NOMATCH) { pblock.innerHTML = "<b>No matches were found.</b>"; } else if (result.searchResult == result.RESULT_NOMATCH_ONGOING) { pblock.innerHTML = "<b>Please wait...</b>"; } else if (result.searchResult == result.RESULT_SUCCESS || result.searchResult == result.RESULT_SUCCESS_ONGOING) { var html = ""; for (var i = 0; i < result.matchCount; i++) { var image = result.getImageAt(i); var title = result.getCommentAt(i); var url = result.getValueAt(i); if (!title) title = url; if (image.indexOf("moz-anno:favicon:") == 0) image = image.slice("moz-anno:favicon:".length); else image = ""; html += '<div class="gresult">'; if (image) html += ('<img src="' + Utils.escapeHtml(image) + '"/> '); html += ('<a href="' + Utils.escapeHtml(url) + '">' + Utils.escapeHtml(title) + "</a>"); html += ('<div class="gresult-url">' + Utils.escapeHtml(url) + '</div'); html += "</div>"; } pblock.innerHTML = html; } } }; history.startSearch( dobj.text, "", null, observer ); pblock.addEventListener( "preview-change", function onPreviewChange() { pblock.removeEventListener("preview-change", onPreviewChange, false); history.stopSearch(); }, false); }, execute: function(dobj) { if (dobj.text) Utils.openUrlInBrowser(dobj.text); else displayMessage("No URL was provided."); }} ); function cmd_show_tabs() { var content = context.chromeWindow.document.getElementById("appcontent"); var browser = content.firstChild; var tabs = browser.tabContainer; tabs.style.height = "25px"; tabs.style.marginTop = "0px"; } function cmd_hide_tabs() { var content = context.chromeWindow.document.getElementById("appcontent"); var browser = content.firstChild; var tabs = browser.tabContainer; tabs.style.height = "0px"; tabs.style.marginTop = "-500px"; } CmdUtils.CreateCommand({ name: "where-am-i", preview: function(pblock, dobj) { var loc = CmdUtils.getWindow().location; pblock.innerHTML = ("Your current URL is <tt>" + Utils.escapeHtml(loc.href) + "</tt>." + "<p>Press enter to copy this URL to " + "your clipboard.</p>"); }, execute: function() { var loc = CmdUtils.getWindow().location; var clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"]. getService(Ci.nsIClipboardHelper); clipboard.copyString(loc.href); } });