Created
December 9, 2016 05:30
-
-
Save jasonblewis/9c84a2c6dbed725a5a621c3645bd80ee 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 booko amazon ISBN link | |
// @namespace https://emacstragic.net/ | |
// @version 0.1 | |
// @description Make the ISBN-13 a clickable link to booko. | |
// @author Jason Lewis jason@NOdicksonSPAM.st | |
// @match https://www.amazon.com/* | |
// @copyright 2016+, emacstragic.net | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
//var hrefs = new Array(); | |
var elements = $('#productDetailsTable > tbody > tr > td > div > ul > li'); | |
elements.each(function() { | |
console.log($(this)); | |
//console.log($(this)[0].innerText); | |
if ($(this)[0].innerText.indexOf('ISBN-13') !== -1 ) { | |
var isbn=$(this)[0].innerText.replace(/ISBN-13:\s*(\d{3}-\d{10})/,"$1"); | |
console.log('isbn is: ' + isbn); | |
var url = 'https://booko.com.au/' + isbn; | |
var a = document.createElement("a"); | |
var text = document.createTextNode('ISBN-13: ' + isbn); | |
a.setAttribute('href',url); | |
a.setAttribute('target','_blank'); | |
a.appendChild(text); | |
var li = document.createElement("li"); | |
li.appendChild(a); | |
$(this)[0].replaceWith(li); | |
} | |
}); | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment