Changes

Jump to navigation Jump to search
138 bytes added ,  12:16, 25 July 2014
no edit summary
var t = window.getSelection ? window.getSelection().toString() : document.selection.createRange().text;
// create a Regular Expression to test the validity of our input
var re = /ISBN(-1(?:(0)|3))?:?[\x20(s\s)*[0-9]+[- ][0-9]+[- ][0-9]+[- ][0-9]*[- ]*[xX0-9]{10,17}/;
var OK = re.exec(t);
if (!OK) {
// Notify the user if their selection doesn't look right
alert(t + " isn't is not a valid ISBN\n Please just select a 10 or 13 digit ISBN\ndashes and spaces are OK"');
} else {
// clean up by removing dashes and spaces
t = t.replace(/[\-\s]/,'');
// hand off to MLVC search
window.location = 'http://newburyport.mvlc.org/eg/opac/results?contains=contains;_special=1;qtype=identifier%7Cisbn;locg=1;pane=numeric;query=' + t;
{{Messagebox|type=success|text=Note: for the bookmarklet to work, it all has to be on one line. The code above is presented on several lines for readability.}}
Want this bookmarklet? Drag this link to your browser bookmark bar: <html><a href="javascript: (function(){var t=window.getSelection?window.getSelection().toString():document.selection.createRange().text;var re = /[\s\-xX0-9]{10,17}/;var OK = re.exec(t);if (!OK) {alert(t + ' is not a valid ISBN\n Please just select a 10 or 13 digit ISBN\ndashes and spaces are OK');} else {t = t.replace(/[\-\s]/,'');window.location='http://newburyport.mvlc.org/eg/opac/results?contains=contains;_special=1;qtype=identifier%7Cisbn;locg=1;pane=numeric;query='+t}})();">Search MLVC</a></html>
== Try it ==
{{Messagebox|type=failure|text=This is a work in progress. As I tried to add more error handling and input validation things broke and I'll come back later to improve it. Right now the bookmarklet ASSUMES that works only when you have selected a valid numeric ISBN(dashes and spaces are OK)}}Select ONLY the numeric portion of an ISBN. Do not include the letters "ISBN"
* Little Rabbit Foo Foo is ISBN 0671709682
* Free Culture is ISBN 1594200068
4,558

edits

Navigation menu