Created
February 8, 2011 01:22
-
-
Save wlt/815658 to your computer and use it in GitHub Desktop.
Limechatスクリプト:チャンネルログに現れるURLを開くコマンドを提供する
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
/* 書式: /u [Number] | |
* チャンネルログに現れる下からNumber番目のURLを開く | |
* Numberを省略すると1とみなす | |
*/ | |
(function() { | |
var MAX = 10; | |
var urlsInChannels = {}; | |
function getUrls(channelName) | |
{ | |
return urlsInChannels[channelName] || (urlsInChannels[channelName] = []); | |
} | |
function event::onChannelText(prefix, channel, text) | |
{ | |
var matchUrls; | |
var u; | |
var urls = getUrls(channel); | |
// JScriptはエスケープシーケンス使わないとだめぽ | |
if (matchUrls = text.match(/https?:\/\/[^\s\u3000]+/g)) { | |
while (u = matchUrls.pop()) { | |
urls.unshift(u); | |
} | |
} | |
urls.length = MAX; | |
} | |
function event::onSendingCommand(command, param, context) | |
{ | |
if (command == 'U') { | |
context.handled = true; | |
var urls = getUrls(selectedChannel.name); | |
var i = parseInt(param); | |
i = isNaN(i) ? 1 : i; | |
i = i >= MAX ? MAX : i; | |
i--; // 1オリジンで指定できるように | |
i = i < 0 ? 0 : i; | |
browseUrl(urls[i]); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment