Skip to content

Instantly share code, notes, and snippets.

@whiteleaf7
Last active August 29, 2015 14:07
Show Gist options
  • Save whiteleaf7/5140cd957a3338732332 to your computer and use it in GitHub Desktop.
Save whiteleaf7/5140cd957a3338732332 to your computer and use it in GitHub Desktop.
var amazon_url_regexp = /(http:\/\/www\.amazon\.(?:com|co\.jp))\/(.+)/;
var shell = new ActiveXObject("WScript.Shell");
function short_amazon_link(text) {
if (!text.split(/%3F|\?/i)[0].match(amazon_url_regexp)) return null;
var matches = [RegExp.$1];
var elements = RegExp.$2.split("/");
for (var i = 0; i < elements.length; i++) {
if (elements[i].match(/^\w+$/)) {
matches.push(elements[i]);
}
}
// without search query
if (matches[1] != "s") {
return matches.join("/");
}
return null;
}
function event::onSendingCommand(command, param, context) {
if (command == "/") {
var text = short_amazon_link(clipboard.text || "");
if (text) {
clipboard.text = text;
shell.SendKeys("^v~");
}
else {
print("AmazonLinkじゃないっぽい");
}
context.handled = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment