diff --git a/Artnet News.js b/Artnet News.js new file mode 100644 index 0000000000..71e6e16e0d --- /dev/null +++ b/Artnet News.js @@ -0,0 +1,231 @@ +{ + "translatorID": "aefdbd62-3cf8-44a4-bc73-68a3b3f70d73", + "label": "Artnet News", + "creator": "czar", + "target": "^https?://news\\.artnet\\.com", + "minVersion": "3.0", + "maxVersion": "", + "priority": 100, + "inRepository": true, + "translatorType": 4, + "browserSupport": "gcsibv", + "lastUpdated": "2018-07-08 15:10:54" +} + +/* + ***** BEGIN LICENSE BLOCK ***** + + Copyright © 2018 czar + http://en.wikipedia.org/wiki/User_talk:Czar + + 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 ***** +*/ + + +function detectWeb(doc, url) { + if (/-\d{4,}$/.test(url)) { + return "blogPost"; + } else if (getSearchResults(doc, true)) { + return "multiple"; + } +} + + +function scrape(doc, url) { + var translator = Zotero.loadTranslator('web'); + translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48'); // embedded metadata (EM) + translator.setDocument(doc); + + translator.setHandler('itemDone', function (obj, item) { // corrections to EM + item.itemType = "blogPost"; + item.publicationTitle = "Artnet News"; + var authorMetadata = doc.querySelectorAll('.article-byline a'); + for (let author of authorMetadata) { + item.creators.push(ZU.cleanAuthor(author.text, "author")); + } + if (item.creators[0].lastName == "Team") { + delete item.creators[0].firstName; // remove the firstName param + item.creators[0].lastName = "Artnet Galleries Team"; // write the desired name to lastName + item.creators[0].fieldMode = 1; // change to single-field mode + } + if (item.tags) { // convert tags from lower to title case + for (let tag in item.tags) { // need "in" for easier write to index + if (item.tags[tag] == item.tags[tag].toLowerCase()) { + item.tags[tag] = item.tags[tag].replace(/\b\w/g, l => l.toUpperCase()); + } + } + } + item.complete(); + }); + + translator.getTranslatorObject(function(trans) { + trans.doWeb(doc, url); + }); +} + + +function getSearchResults(doc, checkOnly) { + var items = {}; + var found = false; + var rows = doc.querySelectorAll('h2.teaser-title'); + var links = doc.querySelectorAll('.teaser-info > a'); + for (let i=0; i