From 77f31047e50b48e82188277e54838d54a2a2c2d1 Mon Sep 17 00:00:00 2001 From: teramako Date: Tue, 23 Sep 2008 14:22:48 +0000 Subject: * id:... のリンク化 * post時に'\n'で改行 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@19778 d0d07461-0603-4401-acd4-de1884942a52 --- haiku.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'haiku.js') diff --git a/haiku.js b/haiku.js index 428594e..f3e71fb 100644 --- a/haiku.js +++ b/haiku.js @@ -39,13 +39,14 @@ function sayHaiku(username, password, stat){ var keyword = ''; if (stat.match(/^#([^ ].+)\s+(.*)$/)) [keyword, stat] = [RegExp.$1, RegExp.$2]; + stat = stat.split("\\n").map(function(str) encodeURIComponent(str)).join("\n"); 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=" + encodeURIComponent(stat) + '&keyword=' + encodeURIComponent(keyword)); + xhr.send("status=" + stat + '&keyword=' + encodeURIComponent(keyword)); else - xhr.send("status=" + encodeURIComponent(stat)); + xhr.send("status=" + stat); } function favHaiku(username, password, user){ var xhr = new XMLHttpRequest(); @@ -79,14 +80,17 @@ var html = .toSource() .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + statuses.map(function(status) { var text = status.text; - if (text.indexOf(status.keyword+"=") == 0) text = status.text.substr(status.keyword.length + 1); + var keyword = status.keyword; + if (text.indexOf(keyword+"=") == 0) text = status.text.substr(keyword.length + 1); text = convert(text); + keyword = convert(keyword); return <> {status.user.screen_name}.toSource() .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + sprintf(': %s
%s‬
', - status.keyword, text) + keyword, text) }).join(""); //liberator.log(html); liberator.echo(html, true); } function convert(str){ - function createHTML(url){ + function createHTML(url,userid){ var str = ''; - if (/\.(?:jpe?g|gif|png|bmp)$/.test(url)){ + if (userid){ + str = 'id:'+userid+'' + } else if (/\.(?:jpe?g|gif|png|bmp)$/.test(url)){ str = ''; } else if (/^http:\/\/www\.youtube\.com\/(?:watch\?v=|v\/)([-\w]+)$/.test(url)){ var url = "http://www.youtube.com/v/" + RegExp.$1; @@ -114,11 +120,15 @@ '' + ''; } else { - str = ''+url+''; + if (url.charAt(0) == "<") + str = url.replace(/(href|src)="\//g,'$1="http://h.hatena.ne.jp/'); + else + str = ''+url+''; } return str; } - return str.replace(/https?:\/\/[-\w!#$%&'()*+,.\/:;=?@~]+/g, createHTML); + return str.replace(/<[^>]+>|https?:\/\/[-\w!#$%&'()*+,.\/:;=?@~]+|id:([-\w]+)/g, createHTML) + .replace("\n","
","g"); } liberator.commands.addUserCommand(["haiku"], "Change Haiku status", function(arg, special){ -- cgit v1.2.3