{ "translatorID": "96b9f483-c44d-5784-cdad-ce21b984fe01", "label": "Amazon.com", "creator": "Sean Takats, Michael Berkowitz, and Simon Kornblith", "target": "^https?://(?:www\\.)?amazon", "minVersion": "3.0", "maxVersion": "", "priority": 100, "inRepository": true, "translatorType": 4, "browserSupport": "gcsbv", "lastUpdated": "2014-10-19 06:05:44" } function detectWeb(doc, url) { if(getSearchResults(doc, true)) { return (Zotero.isBookmarklet ? "server" : "multiple"); } else { var xpath = '//input[contains(@name, "ASIN")]'; if(doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null).iterateNext()) { if(Zotero.isBookmarklet) return "server"; var elmt = doc.evaluate('//input[@name="storeID"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext(); if(elmt) { var storeID = elmt.value; //Z.debug(storeID); if (storeID=="music"|storeID=="dmusic"){ return "audioRecording"; } else if (storeID=="dvd"|storeID=="dvd-de"|storeID=="video"|storeID=="movies-tv"){ return "videoRecording"; } else if (storeID=="videogames"|storeID=="mobile-apps") { return "computerProgram"; } else { return "book"; } } else { return "book"; } } } } function getSearchResults(doc, checkOnly) { //search results var links = [], container = doc.getElementById('searchTemplate'); if (container) { links = container.getElementsByClassName('s-access-detail-page'); if (!links.length) { links = ZU.xpath(container, './/div[contains(@class,"results")]/div[starts-with(@id,"result_")]//h3/a'); } } if(!links.length) { //wish lists container = doc.getElementById('item-page-wrapper'); if(container) { links = ZU.xpath(container, './/a[starts-with(@id, "itemName_")]'); } } if(!links.length) return false; var availableItems = {}, found = false, asinRe = /\/(?:dp|product)\/(?:[^?#]+)\//; for(var i=0; i while(x == null) //accepts only element nodes (type 1) or nonempty textnode (type 3) //and skips everything else var x=n.nextSibling; while (x == null || (x.nodeType != 1 && (x.nodeType != 3 || x.textContent.match(/^\s*$/) ))) { if (x==null) { x = get_nextsibling(n.parentNode); } else { x=x.nextSibling; } } return x; } function scrape(doc, url) { var isAsian = url.search(/^https?:\/\/[^\/]+\.(?:jp|cn)[:\/]/) != -1; // Scrape HTML for items without ISBNs, because Amazon doesn't provide an easy way for // open source projects like us to use their API Z.debug("Scraping from Page"); var item = new Zotero.Item(detectWeb(doc, url) || "book"); var title = doc.getElementById('btAsinTitle') || doc.getElementById('title_row') || doc.getElementById('productTitle'); // get first non-empty text node (other text nodes are things like [Paperback] and dates) item.title = ZU.trimInternal( ZU.xpathText(title, '(.//text()[normalize-space(self::text())])[1]') ) // though sometimes [Paperback] or [DVD] is mushed with the title... .replace(/(?: [(\[].+[)\]])+$/, ""); var baseNode = title.parentElement, bncl; while(baseNode && (bncl = baseNode.classList) && !(baseNode.id == 'booksTitle' || bncl.contains('buying') || bncl.contains('content') || bncl.contains('DigitalMusicInfoColumn') || (baseNode.id == 'centerCol' && baseNode.firstElementChild.id.indexOf('title') == 0) ) ) { baseNode = baseNode.parentElement; } if(baseNode) { var authors = ZU.xpath(baseNode, './/span[@id="artistBlurb"]/a'); //if(!authors.length) authors = baseNode.getElementsByClassName('contributorNameID'); if(!authors.length) authors = ZU.xpath(baseNode, '(.//*[@id="byline"]/span[contains(@class, "author")] | .//*[@id="byline"]/span[contains(@class, "author")]/span)/a[contains(@class, "a-link-normal")][1]'); if(!authors.length) authors = ZU.xpath(baseNode, './/span[@class="contributorNameTrigger"]/a[not(@href="#")]'); if(!authors.length) authors = ZU.xpath(baseNode, './/a[following-sibling::*[1][@class="byLinePipe"]]'); if(!authors.length) authors = ZU.xpath(baseNode, './/a[contains(@href, "field-author=")]'); for(var i=0; i