Skip to content
Permalink
Browse files

Fix ResearchGate linting errors

  • Loading branch information...
GuyAglionby committed Mar 30, 2019
1 parent 35840fb commit 825d9cedc6e90b5d81e44dc27727f273c8aa630d
Showing with 32 additions and 30 deletions.
  1. +32 −30 ResearchGate.js
@@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2019-03-30 14:52:11"
"lastUpdated": "2019-03-30 15:18:21"
}

/*
@@ -40,33 +40,34 @@
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}

function detectWeb(doc, url) {
if (url.indexOf('/publication/')>-1) {
if (url.includes('/publication/')) {
var type = text(doc, 'div.publication-meta strong');
if (!type) {
//for logged in users (yes, really...)
// for logged in users (yes, really...)
type = text(doc, 'b[data-reactid]');
}
type = type.replace('(PDF Available)', '').trim();
switch (type) {
case "Data"://until we have a data itemType
case "Article":
return "journalArticle";
case "Conference Paper":
return "conferencePaper";
case "Chapter":
return "bookSection";
case "Thesis":
return "thesis";
case "Research":
return "report";
case "Presentation":
return "presentation";
default:
return "book";
case "Data":// until we have a data itemType
case "Article":
return "journalArticle";
case "Conference Paper":
return "conferencePaper";
case "Chapter":
return "bookSection";
case "Thesis":
return "thesis";
case "Research":
return "report";
case "Presentation":
return "presentation";
default:
return "book";
}
} else if ((url.match('/search(\\?|/)?') || url.includes('/profile/') || url.includes('/scientific-contributions/')) && getSearchResults(doc, true)) {
return "multiple";
}
return false;
}

function getSearchResults(doc, checkOnly) {
@@ -76,7 +77,7 @@ function getSearchResults(doc, checkOnly) {
if (!rows.length) {
rows = ZU.xpath(doc, '//div[contains(@class, "nova-v-publication-item__stack-item")]//a[contains(@class,"nova-e-link")]');
}
for (var i=0; i<rows.length; i++) {
for (var i = 0; i < rows.length; i++) {
var href = rows[i].href;
var title = ZU.trimInternal(rows[i].textContent);
if (!href || !title) continue;
@@ -98,6 +99,7 @@ function doWeb(doc, url) {
articles.push(i);
}
ZU.processDocuments(articles, scrape);
return true;
});
} else {
scrape(doc, url);
@@ -110,28 +112,28 @@ function scrape(doc, url) {

var uid = attr(doc, 'meta[property="rg:id"]', 'content');
if (!uid) {
//trying to get the uid from URL; for logged in users
// trying to get the uid from URL; for logged in users
var uidURL = url.match(/publication\/(\d+)_/);
if (uidURL) uid = uidURL[1];
}
uid = uid.replace('PB:', '');
var risURL = "https://www.researchgate.net/lite.publication.PublicationDownloadCitationModal.downloadCitation.html?fileType=RIS&citation=citationAndAbstract&publicationUid=" + uid;
var pdfURL = attr(doc, 'meta[property="citation_pdf_url"]', 'content');

ZU.doGet(risURL, function(text) {
//Z.debug(text);
//fix wrong itemType information in RIS
if (type=="bookSection") text = text.replace('TY - BOOK', 'TY - CHAP');
if (type=="conferencePaper") text = text.replace('TY - BOOK', 'TY - CONF');
if (type=="report") text = text.replace('TY - BOOK', 'TY - RPRT');
if (type=="presentation") text = text.replace('TY - BOOK', 'TY - SLIDE');
if (type=="journalArticle") text = text.replace('TY - BOOK', 'TY - JOUR');
if (type=="thesis") text = text.replace('TY - BOOK', 'TY - THES');
ZU.doGet(risURL, function (text) {
// Z.debug(text);
// fix wrong itemType information in RIS
if (type == "bookSection") text = text.replace('TY - BOOK', 'TY - CHAP');
if (type == "conferencePaper") text = text.replace('TY - BOOK', 'TY - CONF');
if (type == "report") text = text.replace('TY - BOOK', 'TY - RPRT');
if (type == "presentation") text = text.replace('TY - BOOK', 'TY - SLIDE');
if (type == "journalArticle") text = text.replace('TY - BOOK', 'TY - JOUR');
if (type == "thesis") text = text.replace('TY - BOOK', 'TY - THES');

var translator = Zotero.loadTranslator("import");
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
translator.setString(text);
translator.setHandler("itemDone", function(obj, item) {
translator.setHandler("itemDone", function (obj, item) {
if (pdfURL) {
item.attachments.push({
url: pdfURL,

0 comments on commit 825d9ce

Please sign in to comment.
You can’t perform that action at this time.