garyhodgson (owner)

Revisions

gist: 38677 Download_button fork
public
Description:
Ubiquity command for interacting with Tumblr
Public Clone URL: git://gist.github.com/38677.git
Embed All Files: show embed
ubiquity-tumblr.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
Tumblr = {
addUsername : function(username) { Application.prefs.setValue("tumblr_user_username", username);},
getUsername : function() { return Application.prefs.get("tumblr_user_username").value;},
addGroup : function(group) { Application.prefs.setValue("tumblr_group", group);},
getGroup : function() { return Application.prefs.get("tumblr_group").value;},
addPassword : function(password) { Application.prefs.setValue("tumblr_user_password", password); },
getPassword : function() { return Application.prefs.get("tumblr_user_password").value; },
everythingIsOK : function() {
return Application.prefs.has("tumblr_user_username")
&& Application.prefs.has("tumblr_user_password")
&& Application.prefs.has("tumblr_group");
}
   };
 
CmdUtils.CreateCommand( {
 name : "t-text",
 homepage : "http://www.tumblr.com",
 icon: "http://www.google.com/s2/favicons?domain=www.tumblr.com",
 author : { name : "Chuck Masucci", homepage : "http://www.pokenewyork.com/"},
 description : "Create Tumblog entry. <span id='credit'>By <a href='http://www.pokenewyork.com/'>Chuck Masucci</a></span>",
 help : "E.g. tumblr-text <i>hello world</i> title <i>my title</i>",
 license : "MPL",
 takes : {"tumbl" : noun_arb_text},
 modifiers : {"title" : noun_arb_text},
 
 preview : function(pblock, tumbl) {
  pblock.innerHTML = "Will create a new Tumblr Text post<br>";
 },
  
 execute : function(tumbl, mods) {
  var username = Tumblr.getUsername();
  var password = Tumblr.getPassword();
  var myGroup = Tumblr.getGroup();
  var myTumbl = tumbl.text;
  var myTitle = mods.title.text || "";
  
  if (!Tumblr.everythingIsOK()) {
    displayMessage("Your email and password hasn't been set. Please use the 'tumblr-setup' command to set your email and password.");
    return;
  }
 
  jQuery.post("http://www.tumblr.com/api/write",
   { email : username,
   password : password,
   type : "regular",
generator : "Tumblr Ubiquity",
group : myGroup,
title : myTitle,
body : myTumbl
}, function(data) { displayMessage("Regular post completed!"); });
 }
})
 
CmdUtils.CreateCommand( {
  name : "t-link",
  homepage : "http://www.tumblr.com",
  author : { name : "Chuck Masucci", homepage : "http://www.pokenewyork.com/"},
  icon: "http://www.google.com/s2/favicons?domain=www.tumblr.com",
  description : "Create Tumblog link entry. <span id='credit'>By <a href='http://www.pokenewyork.com/'>Chuck Masucci</a></span>",
  help : "E.g. tumblr-link <i>http://www.google.com</i> name <i>Google</i> description <i>Search Here!</i>",
  license : "MPL",
  takes : {"tumbl" : noun_arb_text},
  modifiers : {"name" : noun_arb_text, "description" : noun_arb_text},
  
  preview : function(pblock, tumbl) {
   pblock.innerHTML = "Will create a new Tumblr Link post<br>";
  },
  
  execute : function(tumbl, mods) {
    var username = Tumblr.getUsername();
    var password = Tumblr.getPassword();
    var group = Tumblr.getGroup();
    var myTumbl = tumbl.text;
    var myName = mods.name.text || "";
    var myDescription = mods.description.text || "";
    
    if (!Tumblr.everythingIsOK()) {
      displayMessage("Your email and password hasn't been set. Please use the 'tumblr-setup' command to set your email and password.");
      return;
    }
 
    jQuery.post("http://www.tumblr.com/api/write",
     { email : username,
     password : password,
     type : "link",
     generator : "Tumblr Ubiquity",
     group : group,
     name : myName,
     description : myDescription,
     url : myTumbl
}, function(data) { displayMessage("Link post completed!"); });
  }
})
 
CmdUtils.CreateCommand( {
  name : "t-quote",
  homepage : "http://www.tumblr.com",
  author : { name : "Chuck Masucci", homepage : "http://www.pokenewyork.com/"},
  icon: "http://www.google.com/s2/favicons?domain=www.tumblr.com",
  description : "Add quote to your Tumblog. <span id='credit'>By <a href='http://www.pokenewyork.com/'>Chuck Masucci</a></span>",
  help : "E.g. tumblr-quote <i>this is a quote</i> title <i>johan</i>",
  license : "MPL",
  takes : { "tumbl" : noun_arb_text},
  modifiers : { "source" : noun_arb_text},
  
  preview : function(pblock, tumbl) {
   pblock.innerHTML = "Will create a new Tumblr Quote post<br>";
  },
  
  execute : function(tumbl, mods) {
    var username = Tumblr.getUsername();
    var password = Tumblr.getPassword();
    var group = Tumblr.getGroup();
    var myTumbl = tumbl.text;
    var mySource = mods.source.text || "";
    
    if (!Tumblr.everythingIsOK()) {
       displayMessage("Your email and password hasn't been set. Please use the 'tumblr-setup' command to set your email and password.");
       return;
    }
      
    jQuery.post("http://www.tumblr.com/api/write",
     { email : username,
     password : password,
     type : "quote",
     generator : "Tumblr Ubiquity",
     group : group,
     source : mySource,
     quote : myTumbl
}, function(data) { displayMessage("Quote post completed!"); });
 
  }
})
 
 
CmdUtils.CreateCommand( {
  name : "t-photo",
  homepage : "http://www.tumblr.com",
  icon: "http://www.google.com/s2/favicons?domain=www.tumblr.com",
  author : { name : "Chuck Masucci", homepage : "http://www.pokenewyork.com/"},
  description : "Add a photo to your Tumblog. <span id='credit'>By <a href='http://www.pokenewyork.com/'>Chuck Masucci</a></span>",
  help : "E.g. tumblr-photo <i>photo url</i> caption <i>my caption</i> click-through-url <i>http://www.flickr.com</i>",
  license : "MPL",
  takes : { "tumbl" : noun_arb_text},
  modifiers : { "caption" : noun_arb_text},
  
  preview : function(pblock, tumbl) {
   pblock.innerHTML = "Will create a new Tumblr Photo post<br>";
  },
  
  execute : function(tumbl, mods) {
   var doc = Application.activeWindow.activeTab.document;
   var username = Tumblr.getUsername();
   var password = Tumblr.getPassword();
   var group = Tumblr.getGroup();
   var myTumbl = tumbl.text;
   var myCaption = mods.caption.text || "";
  
   if (!Tumblr.everythingIsOK()) {
   displayMessage("Your email and password hasn't been set. Please use the 'tumblr-setup' command to set your email and password.");
   return;
}
 
jQuery.post("http://www.tumblr.com/api/write",
{ email : username,
password : password,
type : "photo",
generator : "Tumblr Ubiquity",
group : group,
caption : myCaption,
source : myTumbl
}, function(data) { displayMessage("Photo post complete!"); }
);
 
   }
})
 
CmdUtils.CreateCommand( {
name : "t-video",
homepage : "http://www.tumblr.com",
icon: "http://www.google.com/s2/favicons?domain=www.tumblr.com",
author : { name : "Chuck Masucci", homepage : "http://www.pokenewyork.com/"},
description : "Add a video to your Tumblog. <span id='credit'>By <a href='http://www.pokenewyork.com/'>Chuck Masucci</a></span>",
help : "E.g. tumblr-video <i>video url</i> caption <i>my caption</i><br> or if on a YouTube or Vimeo page, just issue: tumblr-video",
license : "MPL",
takes : { "tumbl" : noun_arb_text},
modifiers : {"caption" : noun_arb_text},
 
preview : function(pblock, tumbl) {
pblock.innerHTML = "Will create a new Tumblr Video post<br>";
pblock.innerHTML += "Try it out: issue \"tumblr-video <i>video url</i> caption <i>my caption</i>\"<br> or if on a YouTube or Vimeo page, issue: \"tumblr-video\"";
},
 
execute : function(tumbl, mods) {
var doc = Application.activeWindow.activeTab.document;
var username = Tumblr.getUsername();
var password = Tumblr.getPassword();
var group = Tumblr.getGroup();
var myTumbl; var myCaption = mods.caption.text || "";
 
if(myTumbl == "" || myTumbl == undefined) {
myTumbl = doc.location.href;
}
 
if(myCaption == "" || myTumbl == undefined) {
myCaption = "";
}
 
if (!Tumblr.everythingIsOK()) {
displayMessage("Your email and password hasn't been set. Please use the 'tumblr-setup' command to set your email and password.");
return;
}
 
jQuery.post("http://www.tumblr.com/api/write",
{ email : username,
password : password,
type : "video",
generator : "Tumblr Ubiquity by Chuck v0.1",
group : group,
caption : myCaption,
embed : myTumbl
}, function(data) {displayMessage("Video post complete!"); }
);
 
   }
})
 
CmdUtils.CreateCommand( {
name : "t-setup",
homepage : "http://www.tumblr.com",
author : { name : "Chuck Masucci", homepage : "http://www.pokenewyork.com/"},
icon: "http://www.google.com/s2/favicons?domain=www.tumblr.com",
description : "Set your Tumblr email, password. For use with the 'tumblr' command. <span id='credit'>By <a href='http://www.pokenewyork.com/'>Chuck Masucci</a></span>",
help : "E.g. tumblr-setup <i>username</i> pass <i>password</i>",
license : "MPL",
takes : { username : noun_arb_text},
modifiers : {"pass" : noun_arb_text},
 
preview : function(pblock, tumbl) {
pblock.innerHTML = "Will set your Tumblr email, password.";
},
 
execute : function(data, mods) {
var username = data.text;
var password = mods.pass.text;
 
if(username.length < 1) {
displayMessage("This command requires a Tumblr email."); return; }
  else if(password.length < 1) {
         displayMessage("This command requires a Tumblr password."); return; }
       Tumblr.addUsername(username);
       Tumblr.addPassword(password);
       if(Tumblr.everythingIsOK()) displayMessage("Your email, password have been set.");
     }
})