diff options
author | teramako | 2008-10-04 06:29:01 +0000 |
---|---|---|
committer | teramako | 2008-10-04 06:29:01 +0000 |
commit | 6f309b77416e28e39058b12dba40ec238295dfa3 (patch) | |
tree | 26ee2b3aa0bc4968c0c27a1beaa62650dcbf9dfd /haiku.js | |
parent | 4fcda502d08875279e781e30ac7789928613e284 (diff) | |
download | vimperator-plugins-6f309b77416e28e39058b12dba40ec238295dfa3.tar.bz2 |
* API名の追加
* タブ補完機能の追加
* Album表示機能の追加
* キーワードのタイムライン表示機能追加
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@20676 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'haiku.js')
-rw-r--r-- | haiku.js | 56 |
1 files changed, 51 insertions, 5 deletions
@@ -14,14 +14,20 @@ // show public timeline.
// :haiku! someone
// show someone's statuses.
+// :haiku! album
+// show aubum timeline.
// :haiku!+ someone
// fav someone's last status.. mean put hatena star.
// :haiku!- someone
// un-fav someone's last status.. mean remove hatena star.
+// :haiku! #keyword
+// show the keyword timeline.
(function(){
var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
+ var CLIENT_NAME = liberator.config.name + "::plugin::haiku.js";
var evalFunc = window.eval;
+ var statuses = null;
try {
var sandbox = new Components.utils.Sandbox(window);
if (Components.utils.evalInSandbox("true", sandbox) === true) {
@@ -40,13 +46,14 @@ var keyword = '';
if (stat.match(/^#([^ ].+)\s+(.*)$/)) [keyword, stat] = [RegExp.$1, RegExp.$2];
stat = stat.split("\\n").map(function(str) encodeURIComponent(str)).join("\n");
+ var source = encodeURIComponent(CLIENT_NAME);
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://h.hatena.ne.jp/api/statuses/update.json", false, username, password);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
if (keyword)
- xhr.send("status=" + stat + '&keyword=' + encodeURIComponent(keyword));
+ xhr.send("status=" + stat + '&keyword=' + encodeURIComponent(keyword) + '&source=' + source);
else
- xhr.send("status=" + stat);
+ xhr.send("status=" + stat + '&source=' + source);
}
function favHaiku(username, password, user){
var xhr = new XMLHttpRequest();
@@ -66,17 +73,33 @@ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(null);
}
+ function getTimelineURLFromTarget(target){
+ if (target == "/"){
+ return "http://h.hatena.ne.jp/api/statuses/public_timeline.json";
+ } else if (target == "album"){
+ return "http://h.hatena.ne.jp/api/statuses/album.json";
+ } else if (/^#(.+)/.test(target)){
+ return "http://h.hatena.ne.jp/api/statuses/keyword_timeline/" +
+ encodeURIComponent(RegExp.$1) + ".json";
+ } else if (/^@?(.+)/.test(target)){
+ return "http://h.hatena.ne.jp/api/statuses/user_timeline/" + RegExp.$1 + ".json";
+ }
+ return "http://h.hatena.ne.jp/api/statuses/friends_timeline.json";
+ }
function showFollowersStatus(username, password, target){
var xhr = new XMLHttpRequest();
+ var endPoint = getTimelineURLFromTarget(target);
+ /*
var endPoint = target ?
target == "/" ?
"http://h.hatena.ne.jp/api/statuses/public_timeline.json"
: "http://h.hatena.ne.jp/api/statuses/user_timeline/" + target + ".json"
: "http://h.hatena.ne.jp/api/statuses/friends_timeline.json";
+ */
xhr.open("POST", endPoint, false, username, password);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(null);
- var statuses = evalFunc(xhr.responseText);
+ statuses = evalFunc(xhr.responseText);
var html = <style type="text/css"><![CDATA[
span.haiku.entry-title { text-decoration: underline; }
@@ -175,7 +198,30 @@ showFollowersStatus(username, password, arg)
else
sayHaiku(username, password, arg);
- },
- { });
+ }, {
+ completer: function(filter, special){
+ if (!filter || !statuses) return;
+ var matches= filter.match(/^([@#]|[-+]\s*)([^\s]*)$/);
+ if (!matches) return;
+ var list = [];
+ var [prefix, target] = [matches[1],matches[2]];
+ switch (prefix.charAt(0)){
+ case "+":
+ case "-":
+ if (!special) return;
+ case "@":
+ list = statuses.map(function(entry) [entry.user.id, entry.text]);
+ break;
+ case "#":
+ list = statuses.map(function(entry) [entry.keyword, entry.text]);
+ break;
+ }
+ if (target){
+ list = list.filter(function($_) $_[0].indexOf(target) > 0);
+ }
+ return [prefix.length, list];
+ }
+ }
+ );
})();
// vim:sw=4 ts=4 et:
|