Skip to content

Instantly share code, notes, and snippets.

@wlt wlt/openURL.js
Created Feb 8, 2011

Embed
What would you like to do?
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
You can’t perform that action at this time.