├── README.md ├── content_script.js ├── images ├── icon128.png ├── icon16.png └── icon48.png └── manifest.json /README.md: -------------------------------------------------------------------------------- 1 | # isbn-search 2 | 3 | ISBN-search traverses a web page replacing isbn numbers with links to a gen.lib.rus.ec search for the isbn number. Not every textbook can be found online for free, but if the textbook can be found online, it will likely be on gen.lib.rus.ec 4 | -------------------------------------------------------------------------------- /content_script.js: -------------------------------------------------------------------------------- 1 | traverse(document.body); 2 | 3 | function traverse(node) { 4 | var child, next 5 | 6 | switch(node.nodeType) { 7 | case 1: 8 | case 9: 9 | case 11: 10 | child = node.firstChild; 11 | while(child) { 12 | next = child.nextSibling; 13 | traverse(child); 14 | child = next; 15 | } 16 | break; 17 | case 3: 18 | handleText(node); 19 | break; 20 | } 21 | } 22 | 23 | // Produces a link to a search for an isbn on gen.lib.rus.ec 24 | function generateBookLink(isbn) { 25 | var url = "http://gen.lib.rus.ec/search.php?req=" + isbn + "&column=identifier\"" 26 | var hyperLink = document.createElement('a'); 27 | var linkText = document.createTextNode(isbn); 28 | hyperLink.appendChild(linkText); 29 | hyperLink.href = url; 30 | return hyperLink; 31 | } 32 | 33 | // Function is called on every section of text 34 | function handleText(textNode) { 35 | 36 | var isbnRegex = /(97[89][- ]?[0-9]{1,5}[- ]?[0-9]+[- ]?[0-9]+[- ]?[0-9])/g; 37 | var textContents = textNode.nodeValue; 38 | var regexResults = isbnRegex.exec(textContents); 39 | 40 | if(regexResults) { 41 | // Determine the start and index of regex search 42 | var startIndex = regexResults.index; 43 | var endIndex = startIndex + regexResults[0].length; 44 | 45 | // Break up textNode contents into subparts 46 | var part1 = textContents.substring(0, startIndex); 47 | var part2 = generateBookLink(regexResults[0]); 48 | var part3 = textContents.substring(endIndex); 49 | 50 | console.log(part1); console.log(part3); 51 | 52 | // Create text nodes for subparts 53 | var part1Node = document.createTextNode(part1); 54 | var part3Node = document.createTextNode(part3); 55 | var parentNode = textNode.parentNode; 56 | 57 | // Replace textNode with subparts 58 | parentNode.replaceChild(part1Node, textNode); 59 | parentNode.insertBefore(part2, part1Node.nextSibling); 60 | parentNode.insertBefore(part3Node, part2.nextSibling); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /images/icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DuncanKeith/isbn-search/5a278dec206d1ea56c6adf80dc77e1dd0b01377f/images/icon128.png -------------------------------------------------------------------------------- /images/icon16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DuncanKeith/isbn-search/5a278dec206d1ea56c6adf80dc77e1dd0b01377f/images/icon16.png -------------------------------------------------------------------------------- /images/icon48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DuncanKeith/isbn-search/5a278dec206d1ea56c6adf80dc77e1dd0b01377f/images/icon48.png -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "content_scripts": [ { 3 | "js": [ "content_script.js" ], 4 | "matches": [ "*://*/*" ], 5 | "run_at": "document_end" 6 | } ], 7 | "description": "Replaces ISBNs with appropriate links to gen.lib.rus.ec (Online search engine for books)", 8 | "icons": { 9 | "128": "images/icon128.png", 10 | "16": "images/icon16.png", 11 | "48": "images/icon48.png" 12 | }, 13 | "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApYo0e7HwsVPk4HTWyiofKPLjnrOa51nBwjsC6rDc6mcDazesAKkIW7QeDHOKsKwLsy7cZ6CR2+9Q/gQRh1wTrewnxKEeWZyISJ/HLV4nnERunDUGJLrhwxlkVWjcXIqQVoO4N+u9f2lQWH28isEtOWO3ZisQUaysS0dA0HTaMesyJCh/1X7IA1w+AyCC1htEIH32Ek4Si/0HEEUT3V3N3Qmzhoo9c6r0Ps9QFtu/sSxJPtMtQSoDaMAUMYv5LsL/YPUUum9Qexw+KD9LlV0lnjkhUmwMmo6gFp/DeCU32F8S34Tagh33/2a/onZVQtYWIYPXoVBJSm1POf182QDBCQIDAQAB", 14 | "manifest_version": 2, 15 | "name": "ISBN Search", 16 | "update_url": "https://clients2.google.com/service/update2/crx", 17 | "version": "1.0.0" 18 | } 19 | --------------------------------------------------------------------------------