{ "translatorID": "3dcbb947-f7e3-4bbd-a4e5-717f3701d624", "label": "HeinOnline", "creator": "Frank Bennett", "target": "^https?://(www\\.)?heinonline\\.org/HOL/(LuceneSearch|Page|IFLPMetaData)\\?", "minVersion": "3.0", "maxVersion": "", "priority": 100, "inRepository": true, "translatorType": 4, "browserSupport": "gcsbv", "lastUpdated": "2019-10-26 13:45:08" } /* ***** BEGIN LICENSE BLOCK ***** Copyright © 2015-2016 Frank Bennett This file is part of Zotero. Zotero is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Zotero is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Zotero. If not, see . ***** END LICENSE BLOCK ***** */ /* *************** ** Utilities ** *************** */ // attr()/text() v2 // eslint-disable-next-line function attr(docOrElem,selector,attr,index){var elem=index?docOrElem.querySelectorAll(selector).item(index):docOrElem.querySelector(selector);return elem?elem.getAttribute(attr):null}function text(docOrElem,selector,index){var elem=index?docOrElem.querySelectorAll(selector).item(index):docOrElem.querySelector(selector);return elem?elem.textContent:null} // Get any search results from current page // Used in detectWeb() and doWeb() function getSearchResults(doc) { var results = doc.getElementsByClassName("lucene_search_result_b"), items = {}, found = false; for (var i = 0, ilen = results.length; i < ilen; i++) { var url = getXPathStr("href", results[i], './/a[1]'); var title = getXPathStr("textContent", results[i], './/a[1]'); title = ZU.trimInternal(title); // title = title.replace(/\s*\[[^\]]*\]$/, ''); if (!title || !url) continue; items[url] = title; found = true; } return found ? items : false; } // Get the string value of the first object matching XPath function getXPathStr(attr, elem, path) { var res = ZU.xpath(elem, path); res = res.length ? res[0][attr] : ''; return res ? res : ''; } // Extract query values to keys on an object function extractQueryValues(url) { var ret = {}; ret.base = url.replace(/[a-zA-Z]+\?.*/, ""); var query = url.replace(/.*?\?/, ""); query = query.split("&"); for (var i = 0, ilen = query.length; i < ilen; i++) { var pair = query[i].split("="); ret[pair[0]] = pair[1]; } return ret; } // Not all pages have a downloadable PDF function translateRIS(ris, pdfURL) { var trans = Zotero.loadTranslator('import'); trans.setTranslator('32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7');// https://github.com/zotero/translators/blob/master/RIS.js trans.setString(ris); trans.setHandler('itemDone', function (obj, item) { if (pdfURL) { item.attachments = [{ title: "Full Text PDF", url: pdfURL, mimeType: "application/pdf" }]; } item.complete(); }); trans.getTranslatorObject(function (transObject) { transObject.options.fieldMap = { VO: "volume" }; transObject.doImport(); }); } function translateCOinS(COinS) { var item = new Zotero.Item(); Zotero.Utilities.parseContextObject(COinS, item); item.complete(); } // Build URL for RIS, and for PDF if available function scrapePage(doc, url) { // We need the id= and the handle= of the current target item. // From that, we can build URL for RIS. // Check for an RIS popup link in the page. var risPopupLink = getXPathStr("href", doc, '//form[@id="pagepicker"]//a[contains(@href, "PrintRequest")][1]'); if (risPopupLink) { // Get the id from pageSelect. var pageID = doc.getElementById("pageSelect").value; // Get other parameters from the page URL. var docParams = extractQueryValues(url); // Compose the RIS link. var risURL = docParams.base + "CitationFile?kind=ris&handle=" + docParams.handle + "&id=" + pageID + "&base=js"; ZU.doGet(risURL, function (ris) { // the PDF URL gives us a page that will refresh itself to the PDF. var pdfPageURL = attr(doc, '[data-original-title*="Download PDF"]', 'href'); if (pdfPageURL) { pdfPageURL = docParams.base + pdfPageURL; // Z.debug(pdfPageURL) ZU.doGet(pdfPageURL, function (pdfPage) { // Call to pdfPageURL prepares PDF for download via META refresh URL var pdfURL = null; var m = pdfPage.match(/