实现了一个SCAR的zotero translator
Posted on 2009-05-27 in Program, RS | No Comments » Trackback URI
SCAR: Science of Cold and Arid Regions 是所里新办的一个期刊,看了几篇文章,打算摘录下来,zotero却不支持,需要自己再写一个转换器(translator),花了一下午的时间,终于搞出来了,暂时不支持搜索功能。
把下面的代码保存到zotero下的translator目录,给个名字,如SCAR.js,然后重新启动一下FIREFOX,应该就可以使用了。
{
"translatorID":"d5770df3-b41a-45cb-bb3a-261948c9af49",
"translatorType":4,
"label":"SCAR",
"creator":"Liangxu Wang<wangliangxu@gmail.com>",
"target":"http://www.scar.ac.cn/hhkxen/ch/reader",
"minVersion":"1.0",
"maxVersion":"",
"priority":100,
"inRepository":true,
"lastUpdated":"2009-5-27 22:33:00"
}
function detectWeb(doc, url) {
var articleRe = /view_abstract.aspx/;
var s = articleRe.exec(url);
if(s) {
return "journalArticle";
} else {
return "multiple";
}
return false;
}
function scrape(doc) {
var nsResolver = null;
var itemType = "journalArticle";
var newItem = new Zotero.Item(itemType);
Zotero.debug(itemType);
// 标题
var title = doc.getElementById('EnTitle').textContent;
Zotero.debug("Title:"+title);
newItem.title = title;
// 附件,网页快照
var snapName = title + " (SCAR)";
Zotero.debug(snapName);
newItem.attachments.push({document:doc, title:snapName, mimeType:"text/html"});
//Zotero.debug(doc);
//关键词
var keys=doc.getElementById('EnKeyWord');
var tags=keys.getElementsByTagName('u');
var i=0;
for(i=0;i<tags.length;i++){
newItem.tags.push(tags[i].textContent);
Zotero.debug("tag:"+tags[i].textContent);
}
//摘要
var abstract=doc.getElementById('EnAbstract');
newItem.abstractNote = Zotero.Utilities.trim(abstract.textContent);
// 出版社
newItem.publicationTitle = 'Sciences in Cold and Arid Regions';
newItem.ISSN='1674-3822';
newItem.url = doc.location.href;
//出版时间
var ref=doc.getElementById('ReferenceText').textContent;
if (ref.match(/,(\d+).+Sciences in Cold and Arid Regions,(\d+)\((\d+)\):(.+)\./))
{
newItem.volume=ref.match(/,(\d+).+Sciences in Cold and Arid Regions,(\d+)\((\d+)\):(.+)\./)[2];
newItem.issue=ref.match(/,(\d+).+Sciences in Cold and Arid Regions,(\d+)\((\d+)\):(.+)\./)[3];
newItem.pages=ref.match(/,(\d+).+Sciences in Cold and Arid Regions,(\d+)\((\d+)\):(.+)\./)[4];
newItem.date=ref.match(/,(\d+).+Sciences in Cold and Arid Regions,(\d+)\((\d+)\):(.+)\./)[1];
}
//作者
if (ref.match(/(.+),\d+\.+/))
{
authors=ref.match(/(.+),\d+\.+/)[1].split(',');
for(i=0;i<authors.length-1;i++) {
newItem.creators.push(Zotero.Utilities.cleanAuthor(authors[i], "author", true));
}
author=authors[authors.length-1].split('and');
for(i=0;i<author.length;i++) {
newItem.creators.push(Zotero.Utilities.cleanAuthor(author[i], "author", true));
}
}
Zotero.debug("finished.");
newItem.complete();
}
function doWeb(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = null;
if(detectWeb(doc, url) == "multiple") {
Zotero.debug("Enter multiple~");
// TODO: implement the multiple function.
} else {
var urls = [url];
}
Zotero.debug(urls);
// 下面对每条url进行解析
Zotero.Utilities.processDocuments(urls, scrape, function() { Zotero.done(); });
Zotero.wait();
}
也可以直接下载:scar.js