Skip to content

Instantly share code, notes, and snippets.

@masaakif
Created March 22, 2012 05:11
Show Gist options
  • Select an option

  • Save masaakif/2156262 to your computer and use it in GitHub Desktop.

Select an option

Save masaakif/2156262 to your computer and use it in GitHub Desktop.
Add Calil link on Amazon page
// ==UserScript==
// @name Amazon Calil
// @namespace http://gist.github.com/2156262
// @description Show calil page from Amazon book listing
// @include http://*.amazon.*
// ==/UserScript==
var DEBUG=true;
showCalil();
function showCalil() {
var val = document.getElementById("ASIN").value;
if (val != '') {
var header = document.evaluate("//div[@class='buying']/a", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (header == undefined) {
header = document.evaluate("//div[@class='buying']//a[contains(@id, 'contribut')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
if (header) {
var link = document.createElement('a');
link.setAttribute('href', 'http://calil.jp/book/' + val);
link.setAttribute('target', '_blank');
link.innerHTML = '<span style=\"font-size:90%; background-color:#ffffcc;\">&raquo;Open Calil<br></span>';
header.parentNode.insertBefore(link, header);
}
}
}
function debug() {
if (typeof DEBUG != 'undefined' && DEBUG) {
console.log.apply(this, arguments);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment