I'm new to JavaScript and have pieced this together from what I know of C++ code and from looking at other Greasemonkey scripts. This script is designed to add a link to view a book on ereaderiq.com to any Kindle book.
Unfortunately, it doesn't seem to do anything. I'm sure I'm missing something simple and basic, but hopefully someone else's eyes can spot whatever it is I'm missing. It is my first attempt at writing my own Greasemonkey script.
// ==UserScript==
// @name View Kindle Book on ereaderiq
// @namespace buran.public
// @description Adds a link to Amazon Kindle book product pages for easy viewing of that book on ereaderiq.com
// @include *.amazon.com/*
// @include *.amzn.com/*
// @version 1
// @grant none
// ==/UserScript==
function getASIN(urlstring) {
var asinMatch;
asinMatch = whereami.match(/\/exec\/obidos\/ASIN\/(\w{10})/i);
if (!asinMatch) { asinMatch = urlstring.match(/\/gp\/product\/(\w{10})/i); }
if (!asinMatch) { asinMatch = urlstring.match(/\/exec\/obidos\/tg\/detail\/\-\/(\w{10})/i); }
if (!asinMatch) { asinMatch = urlstring.match(/\/dp\/(\w{10})/i); }
if (!asinMatch) { return null; }
return asinMatch[1];
}
asin = getASIN(window.location.href);
var bl = document.getElementById("btAsinTitle");
if asin.substring(0,3) !== "B00" {
//do-nothing code
} else {
var bookTitle = document.getElementById("btAsinTitle");
var elmNewContent = document.createElement('a');
elmNewContent.href = 'http://www.example.com/';
var sb = "<a href='" + url + "'>click here</a>";
var ereaderiqURL = "[<a href='http://www.ereaderiq.com/dp/" + asin + "'>View on eReaderIQ</a>]";
elmNewContent.appendChild(document.createTextNode('click here'));
var elmFoo = document.getElementById('foo');
elmFoo.parentNode.insertBefore(elmNewContent, elmFoo);
}