- merge WorldCat translators and fix search (for ISBNs, at least)
- make lookup button - podcast icon is now ipod_cast.png and radioBroadcast icon is now transmit.png, both from famfamfam
This commit is contained in:
parent
de67100f20
commit
34cd1103a0
15 changed files with 177 additions and 249 deletions
|
@ -1,92 +0,0 @@
|
|||
{
|
||||
"translatorID":"e07e9b8c-0e98-4915-bb5a-32a08cb2f365",
|
||||
"translatorType":12,
|
||||
"label":"Open WorldCat (Search)",
|
||||
"creator":"Simon Kornblith",
|
||||
"target":"http://partneraccess.oclc.org/",
|
||||
"minVersion":"1.0.0b3.r1",
|
||||
"maxVersion":"",
|
||||
"priority":100,
|
||||
"inRepository":true,
|
||||
"lastUpdated":"2007-03-22 18:15:00"
|
||||
}
|
||||
|
||||
function detectSearch(item) {
|
||||
if(item.itemType == "book" || item.itemType == "bookSection") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// creates an item from an Open WorldCat document
|
||||
function processOWC(doc) {
|
||||
var spanTags = doc.getElementsByTagName("span");
|
||||
for(var i=0; i<spanTags.length; i++) {
|
||||
var spanClass = spanTags[i].getAttribute("class");
|
||||
if(spanClass) {
|
||||
var spanClasses = spanClass.split(" ");
|
||||
if(Zotero.Utilities.inArray("Z3988", spanClasses)) {
|
||||
var spanTitle = spanTags[i].getAttribute("title");
|
||||
var item = new Zotero.Item();
|
||||
if(Zotero.Utilities.parseContextObject(spanTitle, item)) {
|
||||
if(item.title) {
|
||||
item.title = Zotero.Utilities.capitalizeTitle(item.title);
|
||||
} else {
|
||||
item.title = "[Untitled]";
|
||||
}
|
||||
|
||||
item.complete();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function doSearch(item) {
|
||||
if(item.contextObject) {
|
||||
var co = item.contextObject;
|
||||
} else {
|
||||
var co = Zotero.Utilities.createContextObject(item);
|
||||
}
|
||||
|
||||
Zotero.Utilities.loadDocument("http://partneraccess.oclc.org/wcpa/servlet/OpenUrl?"+co, function(doc) {
|
||||
// find new COinS in the Open WorldCat page
|
||||
if(processOWC(doc)) { // we got a single item page
|
||||
Zotero.done();
|
||||
} else { // assume we have a search results page
|
||||
var items = new Array();
|
||||
|
||||
var namespace = doc.documentElement.namespaceURI;
|
||||
var nsResolver = namespace ? function(prefix) {
|
||||
if (prefix == 'x') return namespace; else return null;
|
||||
} : null;
|
||||
|
||||
// first try to get only books
|
||||
var elmts = doc.evaluate('//table[@class="tableLayout"]/tbody/tr/td[@class="content"]/table[@class="tableResults"]/tbody/tr[td/img[@alt="Book"]]/td/div[@class="title"]/a', doc, nsResolver, Components.interfaces.nsIDOMXPathResult.ANY_TYPE,null);
|
||||
var elmt = elmts.iterateNext();
|
||||
if(!elmt) { // if that fails, look for other options
|
||||
var elmts = doc.evaluate('//table[@class="tableLayout"]/tbody/tr/td[@class="content"]/table[@class="tableResults"]/tbody/tr[td/img[@alt="Book"]]/td/div[@class="title"]/a', doc, nsResolver, Components.interfaces.nsIDOMXPathResult.ANY_TYPE,null);
|
||||
elmt = elmts.iterateNext()
|
||||
}
|
||||
|
||||
var urlsToProcess = new Array();
|
||||
do {
|
||||
urlsToProcess.push(elmt.href);
|
||||
} while(elmt = elmts.iterateNext());
|
||||
|
||||
Zotero.Utilities.processDocuments(urlsToProcess, function(doc) {
|
||||
// per URL
|
||||
processOWC(doc);
|
||||
}, function() { // done
|
||||
Zotero.done();
|
||||
});
|
||||
}
|
||||
}, null);
|
||||
|
||||
Zotero.wait();
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
{
|
||||
"translatorID":"c73a4a8c-3ef1-4ec8-8229-7531ee384cc4",
|
||||
"translatorType":4,
|
||||
"label":"Open WorldCat (Web)",
|
||||
"creator":"Sean Takats",
|
||||
"target":"^http://(?:www\\.)?worldcat\\.org/(?:search\\?|profiles/[^/]+/lists/)",
|
||||
"minVersion":"1.0.0b3.r1",
|
||||
"maxVersion":"",
|
||||
"priority":100,
|
||||
"inRepository":true,
|
||||
"lastUpdated":"2007-11-05 18:00:00"
|
||||
}
|
||||
|
||||
function detectWeb(doc, url){
|
||||
var nsResolver = doc.createNSResolver(doc.documentElement);
|
||||
|
||||
var xpath = '//table[@class="tableResults" or @class="table-results"]/tbody/tr/td[3][@class="result"]/div[@class="name"]/a/strong';
|
||||
var results = doc.evaluate(xpath, doc,
|
||||
nsResolver, XPathResult.ANY_TYPE, null);
|
||||
if(results.iterateNext()) {
|
||||
return "multiple";
|
||||
}
|
||||
}
|
||||
|
||||
function processOWC(doc) {
|
||||
var spanTags = doc.getElementsByTagName("span");
|
||||
for(var i=0; i<spanTags.length; i++) {
|
||||
var spanClass = spanTags[i].getAttribute("class");
|
||||
if(spanClass) {
|
||||
var spanClasses = spanClass.split(" ");
|
||||
if(Zotero.Utilities.inArray("Z3988", spanClasses)) {
|
||||
var spanTitle = spanTags[i].getAttribute("title");
|
||||
var item = new Zotero.Item();
|
||||
if(Zotero.Utilities.parseContextObject(spanTitle, item)) {
|
||||
if(item.title) {
|
||||
item.title = Zotero.Utilities.capitalizeTitle(item.title);
|
||||
} else {
|
||||
item.title = "[Untitled]";
|
||||
}
|
||||
|
||||
item.complete();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function doWeb(doc, url){
|
||||
var nsResolver = doc.createNSResolver(doc.documentElement);
|
||||
|
||||
var urls = new Array();
|
||||
var items = new Array();
|
||||
var xpath = '//table[@class="tableResults" or @class="table-results"]/tbody/tr/td[3][@class="result"]/div[@class="name"]/a';
|
||||
var titles = doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null);
|
||||
var title;
|
||||
// Go through titles
|
||||
while(title = titles.iterateNext()) {
|
||||
items[title.href] = title.textContent;
|
||||
}
|
||||
|
||||
items = Zotero.selectItems(items);
|
||||
|
||||
if(!items) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for(var i in items) {
|
||||
urls.push(i);
|
||||
}
|
||||
|
||||
Zotero.Utilities.processDocuments(urls, function(doc) {
|
||||
processOWC(doc);}, function() {Zotero.done();});
|
||||
Zotero.wait();
|
||||
}
|
131
translators/Open WorldCat.js
Normal file
131
translators/Open WorldCat.js
Normal file
|
@ -0,0 +1,131 @@
|
|||
{
|
||||
"translatorID":"c73a4a8c-3ef1-4ec8-8229-7531ee384cc4",
|
||||
"translatorType":12,
|
||||
"label":"Open WorldCat",
|
||||
"creator":"Simon Kornblith",
|
||||
"target":"^http://www\.worldcat\.org/",
|
||||
"minVersion":"1.0.0b3.r1",
|
||||
"maxVersion":"",
|
||||
"priority":100,
|
||||
"inRepository":true,
|
||||
"lastUpdated":"2009-04-15 07:12:45"
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Zotero item from a WorldCat icon src
|
||||
*/
|
||||
function getZoteroType(iconSrc) {
|
||||
// only specify types not specified in COinS
|
||||
if(iconSrc.indexOf("icon-rec") != -1) {
|
||||
return "audioRecording";
|
||||
} if(iconSrc.indexOf("icon-com") != -1) {
|
||||
return "computerProgram";
|
||||
} if(iconSrc.indexOf("icon-map") != -1) {
|
||||
return "map";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a Zotero item from a single item WorldCat page, or the first item on a multiple item
|
||||
* page
|
||||
*/
|
||||
function generateItem(doc, node) {
|
||||
var item = new Zotero.Item();
|
||||
Zotero.Utilities.parseContextObject(node.nodeValue, item);
|
||||
|
||||
// if only one, first check for special types (audio & video recording)
|
||||
var type = false;
|
||||
try {
|
||||
type = doc.evaluate('//img[@class="icn"][contains(@src, "icon-")]/@src', doc, null, XPathResult.ANY_TYPE, null).iterateNext().nodeValue;
|
||||
} catch(e) {}
|
||||
|
||||
if(type) {
|
||||
type = getZoteroType(type);
|
||||
if(type) item.itemType = type;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
function detectWeb(doc) {
|
||||
var xpath = doc.evaluate('//span[@class="Z3988"]/@title', doc, null, XPathResult.ANY_TYPE, null);
|
||||
var node = xpath.iterateNext();
|
||||
if(!node) return false;
|
||||
|
||||
// see if there is more than one
|
||||
if(xpath.iterateNext()) {
|
||||
multiple = true;
|
||||
return "multiple";
|
||||
}
|
||||
|
||||
// generate item and return type
|
||||
return generateItem(doc, node).itemType;
|
||||
}
|
||||
|
||||
function detectSearch(item) {
|
||||
return !!item.ISBN;
|
||||
}
|
||||
|
||||
function doWeb(doc) {
|
||||
// otherwise, we need to get context objects and display select items dialog
|
||||
var elems = [];
|
||||
|
||||
// accumulate OpenURL contextObject nodes
|
||||
var xpath = doc.evaluate('//span[@class="Z3988"]/@title', doc, null, XPathResult.ANY_TYPE, null);
|
||||
while(elem = xpath.iterateNext()) {
|
||||
elems.push(elem);
|
||||
}
|
||||
|
||||
if(elems.length > 1) { // multiple items
|
||||
var items = [];
|
||||
var titles = [];
|
||||
for(var i in elems) {
|
||||
var item = new Zotero.Item();
|
||||
Zotero.Utilities.parseContextObject(elems[i].nodeValue, item);
|
||||
items.push(item);
|
||||
titles.push(item.title);
|
||||
}
|
||||
|
||||
titles = Zotero.selectItems(titles);
|
||||
if(!titles) return true;
|
||||
|
||||
// accumulate appropriate types
|
||||
var i = 0;
|
||||
try {
|
||||
var xpath = doc.evaluate('//div/img[@class="icn"][contains(@src, "icon-")][1]/@src', doc, null, XPathResult.ANY_TYPE, null);
|
||||
while(elem = xpath.iterateNext()) {
|
||||
var type = getZoteroType(elem.nodeValue);
|
||||
if(type) items[i].itemType = type;
|
||||
i++;
|
||||
}
|
||||
} catch(e) {}
|
||||
|
||||
// complete items
|
||||
for(var i in titles) {
|
||||
items[i].complete();
|
||||
}
|
||||
} else { // single item
|
||||
generateItem(doc, elems[0]).complete();
|
||||
}
|
||||
}
|
||||
|
||||
function doSearch(item) {
|
||||
if(item.contextObject) {
|
||||
var co = item.contextObject;
|
||||
} else {
|
||||
var co = Zotero.Utilities.createContextObject(item);
|
||||
}
|
||||
|
||||
Zotero.Utilities.loadDocument("http://www.worldcat.org/search?q=isbn%3A"+item.ISBN+"&=Search&qt=results_page", function(doc) {
|
||||
var node = doc.evaluate('//span[@class="Z3988"]/@title', doc, null, XPathResult.ANY_TYPE, null).iterateNext();
|
||||
if(!node) Zotero.done(false);
|
||||
|
||||
var item = generateItem(doc, node);
|
||||
item.complete();
|
||||
|
||||
Zotero.done();
|
||||
}, null);
|
||||
|
||||
Zotero.wait();
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
{
|
||||
"translatorID":"490909d7-7d79-4c7a-a136-77df618d4db2",
|
||||
"translatorType":4,
|
||||
"label":"Worldcat.org",
|
||||
"creator":"Michael Berkowitz",
|
||||
"target":"http://(www.)?worldcat.org/",
|
||||
"minVersion":"1.0.0b4.r5",
|
||||
"maxVersion":"",
|
||||
"priority":100,
|
||||
"inRepository":true,
|
||||
"lastUpdated":"2009-03-06 20:38:37"
|
||||
}
|
||||
|
||||
function detectWeb(doc, url) {
|
||||
if (url.match(/search?/) && doc.evaluate('//input[@id="itemid"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
|
||||
return "multiple";
|
||||
} else {
|
||||
var type = doc.evaluate('//tbody/tr/td[2][img]', doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent.toLowerCase().match(/(\w+);/)[1];
|
||||
switch (type) {
|
||||
case "book": return "book";
|
||||
case "article": return "journalArticle";
|
||||
case "recording":
|
||||
case "disc": return "audioRecording";
|
||||
case "tape": return "videoRecording";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ENify(str) {
|
||||
return str.match(/^[^&]+/)[0] + '?page=endnote&client=worldcat.org-detailed_record';
|
||||
}
|
||||
function doWeb(doc, url) {
|
||||
var n = doc.documentElement.namespaceURI;
|
||||
var ns = n ? function(prefix) {
|
||||
if (prefix == 'x') return n; else return null;
|
||||
} : null;
|
||||
|
||||
var books = new Array();
|
||||
if (detectWeb(doc, url) == "multiple") {
|
||||
var items = new Object();
|
||||
var titles = doc.evaluate('//div[@class="name"]/a', doc, ns, XPathResult.ANY_TYPE, null);
|
||||
var title;
|
||||
while (title = titles.iterateNext()) {
|
||||
items[title.href] = Zotero.Utilities.trimInternal(title.textContent);
|
||||
}
|
||||
items = Zotero.selectItems(items);
|
||||
for (var i in items) {
|
||||
books.push(ENify(i));
|
||||
}
|
||||
} else {
|
||||
var link = doc.evaluate('//a[contains(text(), "EndNote")]', doc, null, XPathResult.ANY_TYPE, null).iterateNext().href;
|
||||
books = [link];
|
||||
}
|
||||
|
||||
Zotero.Utilities.HTTP.doGet(books, function(text) {
|
||||
text = text.replace("MUSIC", "PAMP");
|
||||
var translator = Zotero.loadTranslator("import");
|
||||
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
|
||||
translator.setString(text);
|
||||
translator.translate();
|
||||
}, function () { Zotero.done(); });
|
||||
Zotero.wait();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue