diff --git a/GamesRadar.js b/GamesRadar.js new file mode 100644 index 0000000000..1f2037fc5a --- /dev/null +++ b/GamesRadar.js @@ -0,0 +1,233 @@ +{ + "translatorID": "81f151f1-8f7e-4042-9e15-0fedda396d97", + "label": "GamesRadar", + "creator": "czar", + "target": "^https?://(www\\.)gamesradar\\.com", + "minVersion": "3.0", + "maxVersion": "", + "priority": 100, + "inRepository": true, + "translatorType": 4, + "browserSupport": "gcsibv", + "lastUpdated": "2018-07-08 02:19:02" +} + +/* + ***** 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 (doc.querySelector('h1[itemprop="name headline"]')) { + 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 = "GamesRadar"; + if (item.language) { + item.language = item.language.replace('EN','en').replace('_','-'); + } + item.creators = []; // reset bad author metadata + var authorMetadata = doc.querySelectorAll('a[rel="author"]'); + for (let author of authorMetadata) { + item.creators.push(ZU.cleanAuthor(author.text, "author")); + } + item.complete(); + }); + + translator.getTranslatorObject(function(trans) { + trans.addCustomFields({ // pull from meta tags in here + 'pub_date': 'date' + }); + trans.doWeb(doc, url); + }); +} + + +function getSearchResults(doc, checkOnly) { + var items = {}; + var found = false; + var rows = doc.querySelectorAll('h3.article-name'); + var links = doc.querySelectorAll('div.listingResult a:first-of-type'); + for (let i=0; i