From 6f309b77416e28e39058b12dba40ec238295dfa3 Mon Sep 17 00:00:00 2001 From: teramako Date: Sat, 4 Oct 2008 06:29:01 +0000 Subject: * API名の追加 * タブ補完機能の追加 * Album表示機能の追加 * キーワードのタイムライン表示機能追加 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@20676 d0d07461-0603-4401-acd4-de1884942a52 --- haiku.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 5 deletions(-) (limited to 'haiku.js') diff --git a/haiku.js b/haiku.js index 033459b..67d3120 100644 --- a/haiku.js +++ b/haiku.js @@ -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 =