{ "translatorID": "c73a4a8c-3ef1-4ec8-8229-7531ee384cc4", "label": "Open WorldCat", "creator": "Simon Kornblith, Sebastian Karcher", "target": "^https?://[^/]+\\.worldcat\\.org/", "minVersion": "3.0.9", "maxVersion": "", "priority": 100, "inRepository": true, "translatorType": 12, "browserSupport": "gcsbv", "lastUpdated": "2017-03-19 23:26:57" } /** * Gets Zotero item from a WorldCat icon src */ function getZoteroType(iconSrc) { // only specify types not specified in COinS if (iconSrc.indexOf("icon-rec") != -1) { return "audioRecording"; } if (iconSrc.indexOf("icon-com") != -1) { return "computerProgram"; } if (iconSrc.indexOf("icon-map") != -1) { return "map"; } return false; } /** * Generates a Zotero item from a single item WorldCat page, * or the first item on a multiple item page */ function generateItem(doc, co) { var item = new Zotero.Item(); ZU.parseContextObject(co, item); // if only one, first check for special types (audio & video recording) var type = ZU.xpathText(doc, '//img[@class="icn"][contains(@src, "icon-")][1]/@src'); if (type) { type = getZoteroType(type); if (type) item.itemType = type; } return item; } function getSearchResults(doc) { var results = doc.getElementsByClassName('result'); for (var i=0; i\s*Notes:\s*<\/strong>\s*
\s*/i, ''); if (notes) { itemData[oclcID] = { notes: ZU.unescapeHTML(ZU.unescapeHTML(notes)) //it's double-escaped on WorldCat }; } } } Zotero.selectItems(items, function(items) { if (!items) return true; var ids = [], data = []; for (var i in items) { ids.push(i); data.push(itemData[i]); } scrape(ids, data); }); } else { var oclcID = extractOCLCID(url); if (!oclcID) { // Seems like some single search results redirect to the item page, // but the URL is still a search URL. Grab cannonical URL from meta tag // to extract the OCLC ID var canonicalURL = ZU.xpath(doc, '/html/head/link[@rel="canonical"][1]')[0]; if (canonicalURL) { oclcID = extractOCLCID(canonicalURL.href); } } if (!oclcID) throw new Error("WorldCat: Failed to extract OCLC ID from URL: " + url); scrape([oclcID]); } } function sanitizeInput(items, checkOnly) { if (items.length === undefined || typeof items == 'string') { items = [items]; } var cleanItems = []; for (var i=0; i