-
-
Save koshinishiki397/27ad60db679ce175cd1a to your computer and use it in GitHub Desktop.
Taberareloo 用 Diigo Model
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
Models.register({ | |
name: 'Diigo', | |
ICON : 'http://www.diigo.com/favicon.ico', | |
LOGIN_URL : 'https://secure.diigo.com/sign-in', | |
TAGS_URL : 'http://www.diigo.com/tag_mana2/load_user_tags', | |
//TAGS_URL : 'http://www.diigo.com/tag_mana2/load_user_tags?u_name=username', | |
//↑ユーザー名を指定しない場合、自分の垢のタグがデフォ | |
RECOMMENDED_URL : 'http://toolbar3.diigo.com/chappai/pv=13/ct=tb/cv=1.6.2.7/user=', | |
DUPLICATED_URL : 'http://toolbar3.diigo.com/chappai/pv=13/ct=tb/cv=1.6.2.7/user=', | |
//API_URL : 'https://secure.diigo.com/api/v2', | |
getUserTags: function(user) { | |
user = user ? user : ""; | |
var self = this; | |
var tags = self.tags; | |
if(tags) { | |
return succeed(tags); | |
} else { | |
return self.getCurrentUser(user).addCallback(function(user) { | |
return succeed().addCallback(function() { | |
return request(self.TAGS_URL + "?u_name=" + user).addCallback(function(res) { | |
var tags = JSON.parse(res.responseText); | |
return self.tags = tags.map(function(tag) { | |
return { | |
name: tag.tName, | |
frequency: tag.count | |
}; | |
}); | |
}); | |
}); | |
}); | |
} | |
}, | |
getRecommendedTags: function(user) { | |
var self = this; | |
user = user ? user : ""; | |
return getSelected().addCallback(function(tab) { | |
return request(self.RECOMMENDED_URL + user + "cmd=bm_loadRecommendedTags/", { | |
queryString: { | |
cmd: "bm_loadRecommendedTags", | |
v: "13", | |
ct: "tb", | |
cv: "1.6.2.7", | |
json: JSON.stringify({ | |
url: tab.url, | |
title: tab.title | |
}), | |
user: user, | |
transId: "2" | |
} | |
}).addCallback(function(res) { | |
return JSON.parse(res.responseText).result.tags; | |
}); | |
}); | |
}, | |
isDuplicated: function(user) { | |
var self = this; | |
return getSelected().addCallback(function(tab) { | |
return request(self.DUPLICATED_URL + user + "cmd=bm_loadBookmark/", { | |
queryString: { | |
cmd: "bm_loadBookmark", | |
v: "13", | |
ct: "tb", | |
cv: "1.6.2.7", | |
json: JSON.stringify({ | |
url: tab.url, | |
title: tab.title | |
}), | |
user: user, | |
transId: 0 | |
} | |
}).addCallback(function(res) { | |
return JSON.parse(res.responseText).result.saved; | |
}); | |
}); | |
}, | |
getSuggestions: function(url) { | |
var self = this; | |
return self.getCurrentUser().addCallback(function(user) { | |
return DeferredHash({ | |
tags: self.getUserTags(user), | |
duplicated: self.isDuplicated(user), | |
recommended: self.getRecommendedTags(user) | |
}); | |
}).addCallback(function(results) { | |
var | |
tags = results.tags, | |
duplicated = results.duplicated, | |
recommended = results.recommended; | |
if(!tags[0] || !duplicated[0] || !recommended[0]) { | |
throw new Error(chrome.i18n.getMessage('error_notLoggedin', self.name)); | |
} | |
var ret = { | |
duplicated: duplicated[1], | |
tags: tags[1], | |
recommended: recommended[1] | |
}; | |
return ret; | |
}); | |
}, | |
getCurrentUser: function(defaultUser) { | |
if(defaultUser) { | |
return succeed(defaultUser); | |
} else if(this.currentUser) { | |
return succeed(this.currentUser); | |
} else { | |
var self = this; | |
return request("http://www.diigo.com/post").addCallback(function(res) { | |
var doc = createHTML(res.responseText); | |
var match = res.responseText.match(/_GLOBAL_VAR\['my_name'\] = \"([^\"]+)\";/); | |
if(match) { | |
var user = match[1]; | |
self.currentUser = 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("http://www.diigo.com/post").addCallback(function(res) { | |
var doc = createHTML(res.responseText); | |
var elmForm = doc.getElementById("newBookmarkForm"); | |
if(!elmForm) | |
throw new Error(chrome.i18n.getMessage('error_notLoggedin', self.name)); | |
return request("http://www.diigo.com" + $X("id('newBookmarkForm')/@action", doc)[0], { | |
sendContent: update(formContents(elmForm), { | |
url: ps.itemUrl, | |
title: ps.item, | |
description: joinText([ps.body, ps.description], " ", true), | |
tags: ps.tags? ps.tags.join(" ") : "", | |
private: ps.private? "no" : "" | |
}) | |
}); | |
}); | |
} | |
}); | |
Models.copyTo(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment