Skip to content

Instantly share code, notes, and snippets.

@ytsuboi
Created November 8, 2011 11:15
Show Gist options
  • Save ytsuboi/1347522 to your computer and use it in GitHub Desktop.
Save ytsuboi/1347522 to your computer and use it in GitHub Desktop.
iPhoneのSafariからAmazonのアフィリリンクをTweetbotに投げるブックマークレット
javascript:tracking_id = "yoshisweb-22";
twitter_id="ytsuboi";
pf = "http://www.amazon.co.jp/exec/obidos/ASIN/";
d = document;
u = d.location.href;
re = new RegExp("^http://www.amazon.co.jp/gp/aw/d/([0-9A-Z]{10})");
res = u.match(re);
if (res) {
asin = res[1];
afurl = pf + asin + "/" + tracking_id + "/ref=nosim/";
tmp = d.evaluate('//div[@class="dpProductTitle"]', d, null, 7, null).snapshotItem(0);
if (tmp) {
n = tmp.textContent;
}
tmp = d.evaluate('//div[@class="title"]', d, null, 7, null).snapshotItem(0);
if (tmp) {
n = tmp.textContent;
}
n = n.replace(/\s+$/, "");
n = n.replace(/^\s+/, "");
b = "";
tmp = d.evaluate('//div[@class="dpByInfoLine"]', d, null, 7, null).snapshotItem(0);
if (tmp) {
b = tmp.textContent;
}
tmp = d.evaluate('id("right")/a[1]', d, null, 7, null).snapshotItem(0);
if (tmp) {
b = tmp.textContent;
}
b = b.replace(/\s+$/, "");
b = b.replace(/^\s+/, "");
mes = encodeURIComponent("\"" + n + " / " + b + "\" " + afurl);
window.location="tweetbot://" + twitter_id + "/post?text= " + mes;
} else {
alert("想定しないURL/異常終了します");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment