{
"translatorID": "136d5c30-d8b1-476f-9564-702a41b6126e",
"label": "wiso",
"creator": "Philipp Zumstein",
"target": "^https?://www\\.wiso-net\\.de/(document/|dosearch\\?)",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsv",
"lastUpdated": "2016-06-26 18:54:53"
}
/*
***** BEGIN LICENSE BLOCK *****
wiso Translator, Copyright © 2014 Philipp Zumstein
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 (url.search(/document/) !== -1) {
if ( ZU.xpath(doc, '//a[contains(@class, "boxExport")]').length>0 ) {
//single item --> generic fallback = journalArticle
return "journalArticle";
}
} else if (getSearchResults(doc, true)) {
return "multiple";
}
}
function scrape(doc, url) {
var address = ZU.xpathText(doc, '//pre[strong]/a[contains(text(), "https://www.wiso-net.de/document/")]');
var docUid = address.substr(address.lastIndexOf('/')+1);
var risUrl = "/stream/exportDocuments?docUids="
+ docUid + "&dbShortcut=&query=&source=Document&format=Citavi";
ZU.doGet(risUrl, function(text) {
//author names are messy and not consistently saved
//sometimes a list of authors is saved in one field seperated by commas
//to prevent this breaking sync:
text = text.replace(/^(A[U123]|ED)\s+-\s+(.+[,;].+)$/mg, cleanAuthorFields );
//sometimes more than one T1 fields are present
//or the title is distributed over T1, T2, T3...
if ( /^TY\s+-\s+JOUR/m.test(text) && /^JF\s+-\s+/m.test(text) && !/^TI\s+-\s+/m.test(text)) {
var titlesArray = [];
text = text.replace(/\r?\n^T[1-5]\s+-\s+(.+)$/mg, function(m, title) {
title = ZU.trimInternal(title);
if (title) titlesArray.push(title);
return '';
});
if (titlesArray.length) {
//insert an aggregated TI tag
text = text.replace(/^TY\s+-\s+(.+)$/m , "$&\nTI - " + titlesArray.join(": "));
}
}
//the field custom field TS seems to be used for some database info
text = text.replace(/^TS\s+-/m,"DB -");
//language LA not LG
text = text.replace(/^LG\s+-/m,"LA -");
//sometimes an abstract is saved in the N1 field instead of the AB filed:
if ( text.search(/^AB\s+-/m) == -1) {
text = text.replace(/^N1\s+-/m,"AB -");
}
var trans = Zotero.loadTranslator('import');
trans.setTranslator('32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7');//https://github.com/zotero/translators/blob/master/RIS.js
trans.setString(text);
//Z.debug(text);
trans.setHandler('itemDone', function (obj, item) {
item.date = item.date.replace(/(\d\d)\.(\d\d)\.(\d\d\d\d)/,"$3-$2-$1");//e.g. 02.03.2014 ==> 2014-03-02
item.attachments = [{
title: "Snapshot",
document:doc
}];
//the url for ebooks is sometimes wrong/incomplete
if (item.url.includes("DOKV_DB=&")) {
item.url = ZU.xpathText(doc, '//a[@class="linkifyplus"]');
}
//Zotero.debug(item);
item.complete();
});
trans.translate();
} , null , "ISO-8859-1");//the text file is LATIN1 encoded
}
function cleanAuthorFields(m, tag, authorStr) {
//m = matched string (everything)
//tag = first parenthesized submatch, i.e., AU, A1, A2, A3 or ED
//authorStr = second parenthesized submatch, i.e., what is following the tag
var authors = authorStr.split(';');
var fixName = false;
if (authors.length == 1) {
//no semicolon
fixName = true;
authors = authorStr.split(',');
if (authors.length < 3) {
//at most single comma, don't mess with it
return m;
} else if (authors.length == 3) {
//we have to distinguish the correct cases where the third part is
//just a suffix as "Jr." and wrong cases where this is a list of
//three authors ==> easiest is maybe to check for a space
if (!ZU.superCleanString(authors[2]).includes(' ')) {
return m;
}
}
}
//here: One of the following two cases holds:
//(i) authorStr contains semicolon(s), authors is the array of its different parts, fixName = false
//(ii) authorStr contains no semicolon but more than one comma, authors is the array of its different parts, fixName = true
var str = '';
for (var i=0; i