Skip to content
Permalink
Browse files

Fixes and Updates - M (#1200)

* Complete rewrite of Mainichi Daily News.js
** I also simplified the target expression, because I couldn't find examples for the other patterns. CC @fbennett
 * I couldn't find the examples anymore, but I add new examples.
 * It seems that the Japenese websites are sometimes (every second time?) not working during the test, which might be just some problems in loading the page completely...

* Update test in Max Planck Institute for the History of Science Virtual Laboratory Library.js
* Update MDPI Journals.js
* Update medes.js
* Rewrite Medium.js
* Update tests in mEDRA.js
* Update tests in Microbiology Society Journals.js
* Update Musee du Louvre.js
**This is a minimalistic update which just ensures that the translator is working again
and the tests will not fail anymore.
* Rewrite and rename Microsoft Academic (Search)
** Renaming: The original Microsoft Academic Search has been completely
decommissioned and the website suggest to use the
Microsoft Academic instead: http://academic.research.microsoft.com/
** The test cases are not working when called from
Scaffold but everything seems to work fine when called
inside the browser.
  • Loading branch information...
zuphilip authored and adam3smith committed Jan 7, 2017
1 parent 63c47af commit c9a994d4923793a2f7e5d5d73a0d19ec50c5641f
@@ -9,77 +9,84 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2013-11-19 17:39:27"
"lastUpdated": "2016-12-27 12:49:31"
}

/*
MDPI Translator
Copyright (C) 2013 Sebastian Karcher
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
/*
MDPI Translator
Copyright (C) 2013 Sebastian Karcher
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/

function detectWeb(doc,url) {

function detectWeb(doc, url) {
var xpath='//meta[@name="citation_journal_title"]';

if (ZU.xpath(doc, xpath).length > 0) {
return "journalArticle";
} else if (getSearchResults(doc, true)) {
return "multiple";
}

if (url.indexOf("/search?")!=-1 || url.search(/\d{4}-\d{3}.\/\d+/)!=-1) {
multxpath = '//table[@id="articles"]//div[@class="title"]/a'

if (ZU.xpath(doc, multxpath).length>0){
return "multiple";
}
}


function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = ZU.xpath(doc, '//div[contains(@class, "article-content")]/a[contains(@class, "title-link")]');
for (var i=0; i<rows.length; i++) {
var href = rows[i].href;
var title = ZU.trimInternal(rows[i].textContent);
if (!href || !title) continue;
if (checkOnly) return true;
found = true;
items[href] = title;
}
return false;
return found ? items : false;
}


function doWeb(doc,url)
{
function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
var hits = {};
var urls = [];
resultxpath = '//table[@id="articles"]//div[@class="title"]/a'
var results = ZU.xpath(doc, resultxpath);

for (var i in results) {
hits[results[i].href] = results[i].textContent;
}
Z.selectItems(hits, function(items) {
if (items == null) return true;
for (var j in items) {
urls.push(j);
Zotero.selectItems(getSearchResults(doc, false), function (items) {
if (!items) {
return true;
}
ZU.processDocuments(urls, doWeb);
var articles = [];
for (var i in items) {
articles.push(i);
}
ZU.processDocuments(articles, scrape);
});
} else {
var translator = Zotero.loadTranslator('web');
//use Embedded Metadata
translator.setTranslator("951c027d-74ac-47d4-a107-9c3069ab7b48");
translator.setDocument(doc);
translator.setHandler('itemDone', function(obj, item) {
if (!item.abstractNote) item.abstractNote = item.extra;
delete item.extra;
item.complete();
});
translator.translate();
scrape(doc, url);
}
}

function scrape(doc, url) {
var translator = Zotero.loadTranslator('web');
//use Embedded Metadata
translator.setTranslator("951c027d-74ac-47d4-a107-9c3069ab7b48");
translator.setDocument(doc);
translator.setHandler('itemDone', function(obj, item) {
if (!item.abstractNote) item.abstractNote = item.extra;
delete item.extra;
item.complete();
});
translator.translate();
}
/** BEGIN TEST CASES **/
var testCases = [
{
Oops, something went wrong.

0 comments on commit c9a994d

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