From 9a431bc8f6020e601fd9f981921dcf16bf499e4d Mon Sep 17 00:00:00 2001 From: Guy Aglionby Date: Fri, 28 Sep 2018 17:18:00 +0100 Subject: [PATCH] Update neural information processing systems (#1747) --- Neural Information Processing Systems.js | 91 ++++++++++++++---------- 1 file changed, 55 insertions(+), 36 deletions(-) diff --git a/Neural Information Processing Systems.js b/Neural Information Processing Systems.js index 2f76b6f0d7f..1204173e6e8 100644 --- a/Neural Information Processing Systems.js +++ b/Neural Information Processing Systems.js @@ -1,67 +1,76 @@ { "translatorID": "c816f8ad-4c73-4f6d-914e-a6e7212746cf", "label": "Neural Information Processing Systems", - "creator": "Fei Qi, Sebastian Karcher", - "target": "^https?://(books|papers)\\.nips\\.cc/", + "creator": "Fei Qi, Sebastian Karcher, Guy Aglionby", + "target": "^https?://papers\\.nips\\.cc/", "minVersion": "3.0", "maxVersion": "", "priority": 100, "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", - "lastUpdated": "2014-03-11 19:45:28" + "lastUpdated": "2018-09-17 14:30:14" } function detectWeb(doc, url) { - var contRe = /\/book\//; - var m = contRe.exec( url ); - if (m && ZU.xpathText(doc, '//ul/li/a[contains(@href, "paper")]')) return "multiple"; - else if (url.indexOf("/paper/") && ZU.xpathText(doc, '//meta[@name="citation_title"]/@content')) return "bookSection"; + let contRe = /\/book\/|\/author\/|\/search\//; + if (contRe.exec(url) && getSearchResults(doc, true)) return "multiple"; + else if (url.includes("/paper/")) return "bookSection"; return false; } function scrape(doc, url) { - var pdfurl = url + ".pdf"; - var bibtexurl = url+ "/bibtex" - Zotero.Utilities.HTTP.doGet(bibtexurl, function( text ) { - var translator = Zotero.loadTranslator("import"); - translator.setTranslator("9cb70025-a888-4a29-a210-93ec52da40d4"); - // Zotero.debug( text ); - translator.setString( text ); - translator.setHandler( "itemDone", function( obj, item ) { - item.attachments = [{url: pdfurl, title:"NIPS Full Text PDF", mimeType:"application/pdf"}, - {document: doc, title: "NIPS Snapshort", mimeTYpe: "text/html"}]; - item.complete(); - }); - translator.translate(); + //work on PDF pages + let baseurl = url.replace(/\.pdf$/, ""); + let pdfurl = baseurl + ".pdf"; + let bibtexurl = baseurl+ "/bibtex"; + Zotero.Utilities.HTTP.doGet(bibtexurl, function( text ) { + let translator = Zotero.loadTranslator("import"); + translator.setTranslator("9cb70025-a888-4a29-a210-93ec52da40d4"); + translator.setString( text ); + translator.setHandler( "itemDone", function( obj, item ) { + item.attachments.push({url: pdfurl, title:"NIPS Full Text PDF", mimeType:"application/pdf"}); + if (url.endsWith(".pdf")) { + item.attachments.push({url: baseurl, title:"NIPS Snapshot", mimeType: "text/html"}); + } + else { + item.attachments.push({document: doc, title: "NIPS Snapshot"}); + } + item.complete(); }); + translator.translate(); + }); } -function doWeb( doc, url ) { - var titleRe = '//ul/li/a[contains(@href, "paper")]'; +function doWeb(doc, url) { if (detectWeb(doc, url) == "multiple") { - // Retrive items - var items = new Object(); - var arts = new Array(); - var titles = doc.evaluate( titleRe, doc, null, XPathResult.ANY_TYPE, null); - while ( title = titles.iterateNext()) { - var art = new Object; - items[title.href] = title.textContent; - } + let items = getSearchResults(doc, false); Zotero.selectItems(items, function (items) { if (!items) { return true; } - for (var i in items) { - arts.push(i); - } - ZU.processDocuments(arts, scrape) + ZU.processDocuments(Object.keys(items), scrape); }); } else { - scrape(doc, url) + scrape(doc, url); } } + +function getSearchResults(doc, checkOnly) { + let items = {}; + let found = false; + let rows = ZU.xpath(doc, '//li//a[contains(@href, "paper")]'); + for (let i=0; i