Created
August 28, 2008 00:03
-
-
Save al3x/7616 to your computer and use it in GitHub Desktop.
Ubiquity commands for bit.ly, Instapaper, Soup.io, Google Reader, Twitter Search, Yep, and zapping CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CmdUtils.CreateCommand({ | |
name: "bitly", | |
takes: {"url to shorten": noun_arb_text}, | |
preview: "Replaces the selected URL with a bit.ly-shortened URL.", | |
description: "Replaces the selected URL with a bit.ly-shortened URL.", | |
icon: "http://bit.ly/favicon.png", | |
homepage: "http://static.al3x.net/ubiquity.html", | |
author: { name: "Alex Payne", email: "al3x@al3x.net"}, | |
license: "WTFPL", | |
execute: function( urlToShorten ) { | |
var baseUrl = "http://bit.ly/api"; | |
var params = {url: urlToShorten.text}; | |
jQuery.get(baseUrl, params, function(shortenedUrl) { | |
CmdUtils.setSelection(shortenedUrl); | |
}) | |
} | |
}) | |
CmdUtils.CreateCommand({ | |
name: "instapaper", | |
description: "Adds the current page to your Instapaper for later reading.", | |
icon: "http://instapaper.com/favicon.png", | |
homepage: "http://static.al3x.net/ubiquity.html", | |
author: { name: "Alex Payne", email: "al3x@al3x.net"}, | |
license: "WTFPL", | |
execute: function() { | |
var d = Application.activeWindow.activeTab.document, | |
w = window, | |
s = context.focusedWindow.getSelection(), | |
l = d.location, | |
e = encodeURIComponent, | |
f = 'http://www.instapaper.com/b', | |
p = '?v=4&k=RBWVcIihOybO&u=' + e(l.href) + '&t=' + e(d.title) + '&s=' + e(s), | |
u = f + p; | |
CmdUtils.getHiddenWindow().open(u, 't', 'toolbar=0,resizable=0,status=1,width=250,height=150'); | |
} | |
}) | |
CmdUtils.CreateCommand({ | |
name: "soup", | |
description: "Posts content from the current page to the Soup.io tumbleogging service.", | |
icon: "http://static.soup.io/images/favicon.png", | |
homepage: "http://static.al3x.net/ubiquity.html", | |
author: { name: "Alex Payne", email: "al3x@al3x.net"}, | |
license: "WTFPL", | |
execute: function() { | |
var d = Application.activeWindow.activeTab.document; | |
var w = context.focusedWindow; | |
var di = d.images; | |
var dom = d.location.href.match(/(.*\/\/[^\/]*)\/.*/)[1]; | |
var sel = w.getSelection(); | |
var e = encodeURIComponent; | |
var i=''; | |
for (var n=0; n < di.length; n++) { | |
if (di[n].offsetWidth * di[n].offsetHeight > 70 * 70) { | |
i = di[n].src.replace(dom, '@@') + '|' + di[n].offsetWidth + '|' + di[n].offsetHeight + ','; | |
} | |
} | |
var url = 'http://www.soup.io/bookmarklet?v=4&u=' + e(d.location.href) + '&t=' + e(d.title) + '&s=' + e(sel) + '&dom=' + e(dom) + '&i=' + e(i); | |
CmdUtils.getHiddenWindow().open(url, 'soup', 'toolbar = 0, resizable = 1, scrollbars = yes, status = 1, width = 450, height = 400'); | |
} | |
}) | |
CmdUtils.CreateCommand({ | |
name: "subscribe", | |
description: "Subscribes to the current site's feed in Google Reader.", | |
icon: "http://www.google.com/reader/ui/573007822-app-icon-32.png", | |
homepage: "http://static.al3x.net/ubiquity.html", | |
author: { name: "Alex Payne", email: "al3x@al3x.net"}, | |
license: "WTFPL", | |
execute: function() { | |
var doc = Application.activeWindow.activeTab.document; | |
Utils.openUrlInBrowser('http://www.google.com/reader/view/feed/'+encodeURIComponent(doc.location.href)); | |
} | |
}) | |
makeSearchCommand({ | |
name: "tsearch", | |
url: "http://search.twitter.com/search?q={QUERY}", | |
icon: "http://twitter.com/favicon.ico", | |
description: "Searches Twitter for your words.", | |
homepage: "http://static.al3x.net/ubiquity.html", | |
author: { name: "Alex Payne", email: "al3x@al3x.net"}, | |
license: "WTFPL", | |
preview: function(pblock, directObject) { | |
var searchTerm = directObject.text; | |
var pTemplate = "Searches Twitter for <b>${query}</b>"; | |
var pData = {query: searchTerm}; | |
pblock.innerHTML = CmdUtils.renderTemplate(pTemplate, pData); | |
var url = "http://search.twitter.com/search.json"; | |
var params = { q: searchTerm }; | |
jQuery.get( url, params, function(data) { | |
var results = data.results.splice( 0, 5 ); | |
var previewTemplate = "{for result in results}"; | |
previewTemplate += '<div style="clear: both; margin: 20px 0 30px 0;"><img src="${result.profile_image_url}" style="float: left; margin-right: 5px;" /><span>${result.from_user}: ${result.text}</span></div>'; | |
previewTemplate += "{/for}"; | |
var previewData = { | |
results: results | |
}; | |
if (!results) { | |
pblock.innerHTML = "<p>Unable to retrieve preview.</p>"; | |
} else { | |
pblock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData); | |
} | |
}, "json"); | |
} | |
}); | |
CmdUtils.CreateCommand({ | |
name: "yep", | |
description: "Imports the current page as PDF in Yep.", | |
homepage: "http://static.al3x.net/ubiquity.html", | |
author: { name: "Alex Payne", email: "al3x@al3x.net"}, | |
license: "WTFPL", | |
execute: function() { | |
var doc = Application.activeWindow.activeTab.document; | |
var sel = context.focusedWindow.getSelection(); | |
var url = 'yep:url='+encodeURIComponent(doc.location.href)+'&title='+encodeURIComponent(doc.title)+'&tags='+encodeURIComponent(sel); | |
openUrl(url); | |
} | |
}) | |
CmdUtils.CreateCommand({ | |
name: "zap", | |
description: "Discards the current page's stylesheets.", | |
homepage: "http://static.al3x.net/ubiquity.html", | |
author: { name: "Alex Payne", email: "al3x@al3x.net"}, | |
license: "WTFPL", | |
execute: function() { | |
var doc = Application.activeWindow.activeTab.document; | |
var newSS, styles='* { background: white ! important; color: black !important } :link, :link * { color: #0000EE !important } :visited, :visited * { color: #551A8B !important }'; | |
newSS = doc.createElement('link'); | |
newSS.rel = 'stylesheet'; | |
newSS.href = 'data:text/css,' + escape(styles); | |
doc.getElementsByTagName("head")[0].appendChild(newSS); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment