Skip to content

Instantly share code, notes, and snippets.

@takuya
Created Feb 21, 2014
Embed
What would you like to do?
u = location.href;
t = "takuya-hateblo-22";
a = (function(url, tag) {
asin = (function(url) {
if (r = url.match(/gp\/product\/([^\/]+)/)) {
return r[1];
} else if (r = url.match(/dp\/([^\/]+)/)) {
return r[1];
} else {
return;
}
})(url);
if(asin){
return "http://amazon.jp/dp/" + asin + "/?tag=" + tag;
}else{
u = new URL(url)
ret = u.search.replace("?","").split(/&/)
ret.unshift(("tag="+tag));
u.search = ret.join("&")
u.hostname = "amazon.jp"
return u.toString();
}
})(u, t);
prompt("", a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment