Created
January 29, 2009 11:38
-
-
Save soh335/54509 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
// ==UserScript== | |
// @name amazonPlusHatenaLink | |
// @namespace d.hatena.ne.jp/sugarbabe335/ | |
// @description add HatenaAsinLink for amazon page | |
// @include http://www.amazon.co.jp/* | |
// ==/UserScript== | |
location.href.match(/(product|dp|ASIN)\/(.{10})\/?/i); | |
var string = "http://d.hatena.ne.jp/asin/"+RegExp.$2; | |
var node = xpath("//div[@class='buying']/*[last()]"); | |
if(node[2] != undefined){ | |
var div = document.createElement('span'); | |
var a = document.createElement('a'); | |
a.href=string; | |
var text = document.createTextNode("はてな"); | |
a.appendChild(text); | |
div.appendChild(a); | |
node[2].parentNode.insertBefore(div, node[2]); | |
} | |
//http://yamanoue.sakura.ne.jp/blog/coding/68 | |
function xpath(query) { | |
var results = document.evaluate(query, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); | |
var nodes = new Array(); | |
for(var i=0; i<results.snapshotLength; i++){ | |
nodes.push(results.snapshotItem(i)); | |
} | |
return nodes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment