al3x (owner)

Forks

Revisions

gist: 7616 Download_button fork
public
Description:
Ubiquity commands for bit.ly, Instapaper, Soup.io, Google Reader, Twitter Search, Yep, and zapping CSS
Public Clone URL: git://gist.github.com/7616.git
al3x_ubiquity.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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);
  }
})