diff --git a/translators/CNKI.js b/translators/CNKI.js new file mode 100644 index 0000000000..e6bdf101ec --- /dev/null +++ b/translators/CNKI.js @@ -0,0 +1,217 @@ +{ + "translatorID":"5c95b67b-41c5-4f55-b71a-48d5d7183063", + "label":"CNKI", + "creator":"Ace Strong and Heromyth", + "target":"^https?://(?:(?:(dlib|epub|ckrd)(?:.edu)?.cnki.net)|(?:[0-9.]+))/(?:kns50|grid2008|grid20)", + "minVersion":"2.0.b4", + "maxVersion":"", + "priority":100, + "inRepository":true, + "translatorType":4, + "lastUpdated":"2010-09-26 15:08:45" +} + +/* + CNKI(China National Knowledge Infrastructure) Translator + Copyright (C) 2009-2010 TAO Cheng, acestrong@gmail.com + + 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 detectWeb(doc, url) { + var articleRe = /detail.aspx/; + var s = articleRe.exec(url); + + if(s) { + return "journalArticle"; + } else { + articleRe = /Brief.aspx/; + s = articleRe.exec(url); + if(s) + return "multiple"; + + } + + return false; +} + +function scrape(doc, url) { + //var namespace = doc.documentElement.namespaceURI; + //var nsResolver = namespace ? function(prefix) { + // if (prefix == "x") return namespace; else return null; + //} : null; + var nsResolver = null; + + var itemType = "journalArticle"; + // TODO: 因为中英文信息都不想丢失,所以存为两个Item,也算是中国特色吧~ + // 但是目前只解析出中文的信息,下个版本中添加英文信息。 + var newItem = new Zotero.Item(itemType); + //Zotero.debug(itemType); + newItem.url = url; + + // 标题 + var titles = doc.title.split('-').slice(0,-1); + //Zotero.debug(titles); + var title = titles.join("-"); + Zotero.debug("Title:"+title); + newItem.title = title; + + // 附件,网页快照 + var snapName = title + " (CNKI)"; + //Zotero.debug(snapName); + //newItem.attachments.push({document:doc, title:snapName}); + newItem.attachments.push({url:newItem.url, snapshot:true, title:snapName, mimeType:"text/html"}); + //Zotero.debug(doc); + + // 其他信息,/html/body/table[4]/tbody/tr/td[2]/table/tbody/tr/td[2]/table[2]/tbody + var dataRows = doc.evaluate('//body/table[4]/tbody/tr/td[2]/table/tbody/tr/td[2]/table[2]/tbody/tr', doc, nsResolver, + XPathResult.ANY_TYPE, null); + var dataRow; + while(dataRow = dataRows.iterateNext()) { + var tds = dataRow.getElementsByTagName("td"); + var heading = Zotero.Utilities.trimInternal(tds[0].textContent); + var content = tds[1]; + if(heading == "【作者中文名】" || heading == "【作者】") { + //Zotero.debug("Authors:"); + var as = content.getElementsByTagName("a"); + //Zotero.debug(as.length); + var i=0; + for(i=0;i