0

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);
}
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Buran
  • 3
  • 3
  • what do you expect `this` to be? Probably want `window.location.href` – charlietfl Jan 20 '15 at 20:46
  • Sorry about that -- accidentally put an old version up. Replaced it with the right one. – Buran Jan 20 '15 at 20:49
  • similar problem though `asin = getASIN(href);` What is `href` supposed to be? It's not defined – charlietfl Jan 20 '15 at 20:55
  • For Greasemonkey questions, you need to also provide a target page where the script is supposed to work. Anyway, I suspect you have an AJAX driven page. Use [AJAX-aware solutions](http://stackoverflow.com/a/11197969/331508). – Brock Adams Jan 20 '15 at 22:21

0 Answers0