-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_pinboard.js
57 lines (52 loc) · 1.9 KB
/
model_pinboard.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
Models.register({
name: 'Pinboard',
ICON: 'http://pinboard.in/favicon.ico',
LINK: 'http://pinboard.in/',
getCurrentUser : function(defaultUser) {
if (defaultUser) {
return succeed(defaultUser);
} else if(this.currentUser) {
return succeed(this.currentUser);
} else {
var self = this;
return request("http://pinboard.in/").addCallback(function(res) {
var doc = createHTML(res.responseText);
var match = res.responseText.match(/\<div id="title"\>Pinboard - \((.+)\)<\/div>/);
if (match) {
var user = match[1];
self.currentUser = user;
alert(user);
return user;
} else {
throw new Error(chrome.i18n.getMessage('error_notLoggedin', self.name));
}
});
}
},
check : function(ps) {
return /photo|quote|link|conversation|video/.test(ps.type) && !ps.file;
},
post : function(ps) {
var self = this;
return request('https://pinboard.in/add', {
queryString: {
title: ps.item,
url: ps.itemUrl
}
}).addCallback(function(res) {
var doc = createHTML(res.responseText);
var elmForm = doc.getElementsByTagName('form')[0];
if (!elmForm)
throw new Error(chrome.i18n.getMessage('error_notLoggedin', self.name));
return request('https://pinboard.in/add', {
sendContent: update(formContents(elmForm), {
title: ps.item,
description: ps.description,
tags: ps.tags? ps.tags.join(' ') : '',
share: ps.private? 'no' : 'yes'
})
});
});
}
});
Models.copyTo(this);