Created
November 30, 2009 09:27
-
-
Save anekos/245355 to your computer and use it in GitHub Desktop.
LimeChat2 でチャンネルの発言を翻訳する
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
// 動作させるチャンネル名のパターン | |
var channelPattern = /#(vimperator|anekos)@.*/; | |
// 色々置換したりする | |
function textFilter (s) { | |
return s; | |
} | |
function event::onLoad(){ | |
log('onLoad - google translator'); | |
} | |
function event::onChannelText(prefix, channelName, text){ | |
if (!channelName.match(channelPattern)) | |
return; | |
var url = 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0' + | |
'&q=' + encodeURIComponent(textFilter(text)) + | |
'&langpair=en|ja'; | |
var request = new ActiveXObject('Msxml2.ServerXMLHTTP.6.0'); | |
var timeout = 5000; | |
request.setTimeouts(timeout, timeout, timeout, timeout); | |
request.onreadystatechange = function() { | |
if (request.readyState == 4 && request.responseText.length) { | |
var channel = findChannel(channelName); | |
var resp = '(' + request.responseText.toString() + ');'; | |
//channel.print(resp); | |
var result = eval(resp); | |
channel.print(' => ' + result.responseData.translatedText); | |
} | |
}; | |
request.open("GET", url, true); | |
request.setRequestHeader('Referer', 'http://gist.github.com/245355'); | |
request.send(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment