Last active
August 29, 2015 14:07
-
-
Save whiteleaf7/5140cd957a3338732332 to your computer and use it in GitHub Desktop.
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 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