Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wlt
Created February 8, 2011 01:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wlt/815658 to your computer and use it in GitHub Desktop.
Save wlt/815658 to your computer and use it in GitHub Desktop.
Limechatスクリプト:チャンネルログに現れるURLを開くコマンドを提供する
/* 書式: /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