{
"translatorID": "ca0e7488-ef20-4485-8499-9c47e60dcfa7",
"label": "RSC Publishing",
"creator": "Sebastian Karcher",
"target": "^https?://(:?www\\.|google\\.)?pubs\\.rsc\\.org/",
"minVersion": "2.1.9",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsb",
"lastUpdated": "2014-06-01 22:04:46"
}
/*
RSC Publishing Translator
Copyright (C) 2011 Aurimas Vinckevicius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
function getResults(doc) {
/**Both search result and book ToC pages use javascript to load content, so
* this actually doesn't work as intended. Search results will work, but
* will also trigger on empty result set. detectWeb for book ToC does not
* work, but doWeb does,
*/
return ZU.xpath(doc, '//div[@id="all" or @id="chapterList"]\
//div[contains(@class,"title_text")]\
//a[not(contains(@href,"/database/"))]');
}
function detectWeb(doc, url) {
if(url.search(/\/results[?\/]/i) != -1 || url.indexOf('/ebook/') != -1 &&
getResults(doc).length) {
return 'multiple';
}
//apparently URLs sometimes have upper case as in /Content/ArticleLanding/
if(url.search(/\/content\/articlelanding\//i) != -1 && ZU.xpathText(doc, '//meta[@name="citation_title"]/@content')) {
return 'journalArticle';
}
if(url.search(/\/content\/chapter\//i) != -1) {
return 'bookSection';
}
}
function scrape(doc, type) {
var translator = Zotero.loadTranslator('web');
translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48');
// temporary hack: move meta tags to the head (reported to RSC 2014-04-30)
var meta = doc.body.getElementsByTagName('meta');
while(meta.length) {
doc.head.appendChild(meta[0]);
}
translator.setDocument(doc);
translator.setHandler('itemDone', function(obj, item) {
item.itemType = type;
if(type == 'bookSection') {
//fix title for book chapters
var title = ZU.xpathText(doc, '//label[@id="lblTitle"]/node()',
null, ' ');
if(title) item.title = ZU.trimInternal(title);
//add bookTitle
item.bookTitle = ZU.xpathText(doc, '//h1[@class="sub_title"]');
if (item.bookTitle){
item.bookTitle = item.bookTitle.replace(/\s*:/, ":");
}
} else if(type == 'journalArticle') {
//journal title is abbreviated. We can fetch full title from the page
item.publicationTitle = ZU.xpathText(doc, '//div[contains(@class, "hg_title")]//h1');
}
//keywords is frequently an empty string
if(item.tags.length == 1 && !item.tags[0]) {
item.tags = [];
}
item.complete();
});
translator.translate();
}
function doWeb(doc, url) {
var type = detectWeb(doc, url);
if(type == 'multiple') {
var results = getResults(doc);
var items = new Object();
for(var i=0, n=results.length; i