From 4ca3ee635c6624add6514b2b8a5675ef61c67813 Mon Sep 17 00:00:00 2001 From: teramako Date: Wed, 15 Oct 2008 14:54:10 +0000 Subject: E4X化 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@21393 d0d07461-0603-4401-acd4-de1884942a52 --- haiku.js | 125 +++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 73 insertions(+), 52 deletions(-) (limited to 'haiku.js') diff --git a/haiku.js b/haiku.js index 8fb60c7..e9145fd 100644 --- a/haiku.js +++ b/haiku.js @@ -25,7 +25,7 @@ (function(){ var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); - var CLIENT_NAME = encodeURIComponent(liberator.config.name + "::plugin::haiku.js"); + var CLIENT_NAME = encodeURIComponent(config.name + "::plugin::haiku.js"); var evalFunc = window.eval; var statuses = null; try { @@ -103,48 +103,64 @@ } 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); - statuses = evalFunc(xhr.responseText); - + function statusToXML(statuses){ var html = .toSource() - .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + - statuses.map(function(status) { - var text = status.text; - var keyword = status.keyword; - var star = status.favorited > 0 ? 'x' + status.favorited + '' : ''; - if (text.indexOf(keyword+"=") == 0) text = status.text.substr(keyword.length + 1); - text = convert(text); - keyword = convert(keyword); - return <> + ]]>; + + statuses.forEach(function(status) { + var text = status.text; + var keyword = status.keyword; + var star = status.favorited > 0 ? <>{'x' + status.favorited} : <>; + var replies = <>; + + if (text.indexOf(keyword+"=") == 0) text = status.text.substr(keyword.length + 1); + text = convert(text); + keyword = convert(keyword); + + if (status.replies.length > 0){ + replies =
; + status.replies.forEach(function(rep){ + replies.* += <> +
+ {rep.user.screen_name} + {rep.user_name} +
+
{rep.text.substr(keyword.length+1)}
+ ; + }); + } + html += <> +
{status.user.screen_name} {status.user.name}‬ - .toSource() - .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + - star + - sprintf(': %s
%s‬
', - keyword, text) - }).join(""); + {star} + : + {keyword}
+ {text} +
+ {replies} +
+ ; + }); + return html; + } + function showFollowersStatus(username, password, target){ + var xhr = new XMLHttpRequest(); + var endPoint = getTimelineURLFromTarget(target); + xhr.open("POST", endPoint, false, username, password); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send(null); + statuses = evalFunc(xhr.responseText); + var html = statusToXML(statuses); //liberator.log(html); liberator.echo(html, true); } @@ -152,31 +168,35 @@ function createHTML(all){ var str = ''; if (all.indexOf("id:") == 0){ - str = '' + all + '' + str = {all}; } else if (/\.(?:jpe?g|gif|png|bmp)$/.test(all)){ - str = ''; + str = ; } else if (/^http:\/\/(?:[^.]+\.)?youtube\.com\/(?:watch\?(?:[^&]+&)*v=|v\/)([^&=#?;\/]+)/.test(all)){ var url = "http://www.youtube.com/v/" + RegExp.$1 + "&fs=1"; - str = '' + url + '\n' + - '
' + - '' + - '' + - '
'; + str = <> + {url} +
+ + + + +
+ ; } else if (/^http:\/\/www\.nicovideo\.jp\/watch\/([-\w]+)$/.test(all)){ - str = ''; + str = ; } else { if (all.charAt(0) == "<") - str = all.replace(/(?:href|src)="(?=\/)/g,'$&http://h.hatena.ne.jp'); + str = new XMLList(all.replace(/(?:href|src)="(?=\/)/g,'$&http://h.hatena.ne.jp')); else - str = '' + all + ''; + str = {all}; } return str; } - return str.replace(/<[^>]+>|https?:\/\/[-\w!#$%&'()*+,.\/:;=?@~]+|id:[a-zA-Z][-\w]{1,30}[a-zA-Z\d]/g, createHTML) - .replace("\n","
","g"); + return str.replace(/<[^>]+>|https?:\/\/[-\w!#$%&'()*+,.\/:;=?@~]+|id:[a-zA-Z][-\w]{1,30}[a-zA-Z\d]/g, createHTML); } - liberator.commands.addUserCommand(["haiku"], "Change Haiku status", + commands.addUserCommand(["haiku"], "Change Haiku status", function(arg, special){ var password; var username; @@ -204,8 +224,8 @@ liberator.echoerr(ex); } - arg = arg.replace(/%URL%/g, liberator.buffer.URL) - .replace(/%TITLE%/g, liberator.buffer.title); + arg = arg.replace(/%URL%/g, buffer.URL) + .replace(/%TITLE%/g, buffer.title); if (special && arg.match(/^\+\s*(.*)/)) favHaiku(username, password, RegExp.$1) @@ -218,6 +238,8 @@ else sayHaiku(username, password, arg); }, { + bang: true, + hereDoc: true, completer: function(filter, special){ if (!filter || !statuses) return [0,[]]; var matches= filter.match(/^([@#]|[-+]\s*)([^\s]*)$/); @@ -242,8 +264,7 @@ list = list.filter(function($_) $_[0].indexOf(target) >= 0); } return [prefix.length, list]; - }, - bang: true + } } ); })(); -- cgit v1.2.3