Skip to content

Commit c73d61e

Browse files
committed
Minor tweaks and test updates
1 parent 418d847 commit c73d61e

13 files changed

+193
-213
lines changed

Newsnetz.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"inRepository": true,
1010
"translatorType": 4,
1111
"browserSupport": "gcs",
12-
"lastUpdated": "2012-01-30 22:45:37"
12+
"lastUpdated": "2012-03-05 04:49:07"
1313
}
1414

1515
/*
@@ -56,25 +56,23 @@ function detectWeb(doc, url) {
5656
/* Zotero API */
5757
function doWeb(doc, url) {
5858
//Zotero.debug("ibex doWeb URL= "+ url);
59-
var urls = new Array();
6059
if (detectWeb(doc, url) == "multiple") {
6160
var items = Zotero.Utilities.getItemArray(doc, doc.getElementById("panelArticleItems").getElementsByTagName("h3"), '/story/\\d+');
6261
if (!items || countObjectProperties(items) == 0) {
6362
return true;
6463
}
65-
items = Zotero.selectItems(items);
66-
if (!items) {
67-
return true;
68-
}
64+
Zotero.selectItems(items, function(items) {
65+
if (!items) return true;
6966

70-
for (var i in items) {
71-
urls.push(i);
72-
}
67+
var urls = new Array();
68+
for (var i in items) {
69+
urls.push(i);
70+
}
71+
ZU.processDocuments(urls, scrape);
72+
});
7373
} else {
74-
urls.push(doc.location.href);
74+
scrape(doc);
7575
}
76-
Zotero.Utilities.processDocuments(urls, scrape, function() { Zotero.done(); } );
77-
Zotero.wait();
7876
}
7977

8078
function scrape(doc) {

TalisPrism.js

+24-16
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"inRepository": true,
1010
"translatorType": 4,
1111
"browserSupport": "gcs",
12-
"lastUpdated": "2012-01-30 22:42:54"
12+
"lastUpdated": "2012-03-05 04:46:31"
1313
}
1414

1515
/* TalisPrism translator.
@@ -221,7 +221,8 @@ function scrape(doc, url, item){
221221

222222
if (publishing.match(/(13|14|15|16|17|18|19|20)\d\d/)) {
223223
var pos = publishing.search(/(13|14|15|16|17|18|19|20)\d\d/);
224-
item.date = publishing.substring(pos, publishing.lastIndexOf('.')).match(/\d\d\d\d/);
224+
var date = publishing.substring(pos, publishing.lastIndexOf('.')).match(/\d\d\d\d/);
225+
if(date) item.date = date[0];
225226
var place = publishing.substring(0, publishing.indexOf(':'));
226227
item.place = place.replace(/^\s+|\s+$/g, '');
227228
var publisher = publishing.substring(publishing.indexOf(':')+1, pos);
@@ -235,7 +236,8 @@ function scrape(doc, url, item){
235236
}
236237

237238
isbn=isbn.replace(/^\D+|\D+$/g, "");
238-
item.ISBN = isbn.substring(0).match(/\d+/);
239+
isbn = isbn.substring(0).match(/\d+/);
240+
if(isbn) item.ISBN = isbn[0];
239241

240242
var series = getField(doc, 'Series');
241243
var pos2 =series.lastIndexOf(';');
@@ -375,7 +377,6 @@ function doWeb(doc, url) {
375377
if (prefix == "x" ) return namespace; else return null;
376378
} : null;
377379

378-
var articles = new Array ();
379380
var names = new Array ();
380381
var items = new Object ();
381382
var nextTitle;
@@ -408,29 +409,36 @@ function doWeb(doc, url) {
408409
items[nextTitle.href] = nextTitle.textContent;
409410
names.push(nextTitle.textContent);
410411
}
411-
items = Zotero.selectItems(items);
412-
for (var i in items) {
413-
articles.push(i);
414-
}
415-
Zotero.Utilities.processDocuments(articles, multiscrape, function(){Zotero.done();});
416-
412+
Zotero.selectItems(items, function(items) {
413+
if(!items) return true;
414+
415+
var articles = new Array ();
416+
for (var i in items) {
417+
articles.push(i);
418+
}
419+
ZU.processDocuments(articles, function(doc) { multiscrape(doc, doc.location.href) });
420+
});
417421
} else if (doctype == "multiple") {
418422
var titlePath = '//td[4]/font/span[@class="text"]/table/tbody/tr/td/font/span[@class="text"]/table/tbody/tr/td[1]/font/span[@class="text"]/a';
419423
var titles = doc.evaluate(titlePath, doc, nsResolver, XPathResult.ANY_TYPE, null);
420424
while (nextTitle = titles.iterateNext()) {
421425
items[nextTitle.href] = nextTitle.textContent;
422426
names.push(nextTitle.textContent);
423427
}
424-
items = Zotero.selectItems(items);
425-
for (var i in items) {
426-
articles.push(i);
427-
}
428-
Zotero.Utilities.processDocuments(articles, multiscrape, function(){Zotero.done();});
428+
429+
Zotero.selectItems(items, function(items) {
430+
if(!items) return true;
431+
432+
var articles = new Array ();
433+
for (var i in items) {
434+
articles.push(i);
435+
}
436+
ZU.processDocuments(articles, function(doc) { multiscrape(doc, doc.location.href) });
437+
});
429438
}
430439
else {
431440
soloscrape(doc, url);
432441
}
433-
Zotero.wait();
434442

435443
}/** BEGIN TEST CASES **/
436444
var testCases = [

Tatknigafund.js

+49-43
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"inRepository": true,
1010
"translatorType": 4,
1111
"browserSupport": "gcs",
12-
"lastUpdated": "2012-01-30 22:42:48"
12+
"lastUpdated": "2012-03-05 04:34:44"
1313
}
1414

1515
/*
@@ -59,6 +59,44 @@
5959
in lieu of up-to-date translator documentation.
6060
*/
6161

62+
function scrape(doc, url) {
63+
var n = doc.documentElement.namespaceURI;
64+
var ns = n ? function(prefix) {
65+
if (prefix == 'x') return n; else return null;
66+
} : null;
67+
68+
item = new Zotero.Item("book");
69+
item.title = Zotero.Utilities.trimInternal(
70+
doc.evaluate('//div[@class="description"]/h1', doc, ns, XPathResult.ANY_TYPE, null).iterateNext().textContent
71+
);
72+
73+
var author = doc.evaluate('//a[@class="author_link"]', doc, ns, XPathResult.ANY_TYPE, null).iterateNext().textContent;
74+
// Authors here are Last Name, First initial(s) (ФИО)
75+
var spaceIndex = author.lastIndexOf(" ");
76+
var firstName = author.substring(spaceIndex+1);
77+
var lastName = author.substring(0, spaceIndex);
78+
item.creators.push({firstName:firstName, lastName:lastName, creatorType:"author"});
79+
80+
var info = doc.evaluate('//p[@class="summary"]', doc, ns, XPathResult.ANY_TYPE, null).iterateNext().textContent;
81+
var pub = info.match(/(Нәшрият|Издательство): (.+)/);
82+
var publisher = pub[2];
83+
yr = info.match(/(Нәшрият|Издательство): (.+),\s+(\d+)\s(ел|г)\./);
84+
var year = yr[3];
85+
86+
var pagematch = info.match(/(\d+) (бит|страница|страниц|страницы)/);
87+
var pages = pagematch[1];
88+
item.publisher = Zotero.Utilities.trimInternal(publisher);
89+
item.date = Zotero.Utilities.trimInternal(year);
90+
item.numPages = pages;
91+
92+
var description = doc.evaluate('//div[@class="description"]/p[2]', doc, ns, XPathResult.ANY_TYPE, null).iterateNext().textContent;
93+
item.abstractNote = description;
94+
95+
item.url = url;
96+
97+
item.complete();
98+
}
99+
62100
function detectWeb(doc, url) {
63101
if (url.match("books/search?")) {
64102
return "multiple";
@@ -73,8 +111,7 @@ function doWeb(doc, url) {
73111
var ns = n ? function(prefix) {
74112
if (prefix == 'x') return n; else return null;
75113
} : null;
76-
77-
var books = new Array();
114+
78115
if (detectWeb(doc, url) == "multiple") {
79116
var tablerow = doc.evaluate('//table[@class="books_list"]/tbody/tr', doc, ns, XPathResult.ANY_TYPE, null);
80117
var items = new Array();
@@ -85,48 +122,17 @@ function doWeb(doc, url) {
85122
var url = link.href;
86123
items[url] = title;
87124
}
88-
items = Zotero.selectItems(items);
89-
if(!items) return true;
90-
for (var i in items) {
91-
books.push(i);
92-
}
125+
Zotero.selectItems(items, function(items) {
126+
if(!items) return true;
127+
var books = new Array();
128+
for (var i in items) {
129+
books.push(i);
130+
}
131+
ZU.processDocuments(books, function(doc){ scrape(doc, doc.location.href) });
132+
});
93133
} else {
94-
books = [url];
134+
scrape(doc, url);
95135
}
96-
97-
Zotero.Utilities.processDocuments(books, function(doc) {
98-
item = new Zotero.Item("book");
99-
item.title = Zotero.Utilities.trimInternal(
100-
doc.evaluate('//div[@class="description"]/h1', doc, ns, XPathResult.ANY_TYPE, null).iterateNext().textContent
101-
);
102-
103-
var author = doc.evaluate('//a[@class="author_link"]', doc, ns, XPathResult.ANY_TYPE, null).iterateNext().textContent;
104-
// Authors here are Last Name, First initial(s) (ФИО)
105-
var spaceIndex = author.lastIndexOf(" ");
106-
var firstName = author.substring(spaceIndex+1);
107-
var lastName = author.substring(0, spaceIndex);
108-
item.creators.push({firstName:firstName, lastName:lastName, creatorType:"author"});
109-
110-
var info = doc.evaluate('//p[@class="summary"]', doc, ns, XPathResult.ANY_TYPE, null).iterateNext().textContent;
111-
var pub = info.match(/(Нәшрият|Издательство): (.+)/);
112-
var publisher = pub[2];
113-
yr = info.match(/(Нәшрият|Издательство): (.+),\s+(\d+)\s(ел|г)\./);
114-
var year = yr[3];
115-
116-
var pagematch = info.match(/(\d+) (бит|страница|страниц|страницы)/);
117-
var pages = pagematch[1];
118-
item.publisher = Zotero.Utilities.trimInternal(publisher);
119-
item.date = Zotero.Utilities.trimInternal(year);
120-
item.numPages = pages;
121-
122-
var description = doc.evaluate('//div[@class="description"]/p[2]', doc, ns, XPathResult.ANY_TYPE, null).iterateNext().textContent;
123-
item.abstractNote = description;
124-
125-
item.url = url;
126-
127-
item.complete();
128-
}, function() {Zotero.done();});
129-
Zotero.wait();
130136
}
131137
/** BEGIN TEST CASES **/
132138
var testCases = [

The Atlantic.js

+9-3
Large diffs are not rendered by default.

The Chronicle of Higher Education.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"inRepository": true,
1010
"translatorType": 4,
1111
"browserSupport": "gcs",
12-
"lastUpdated": "2011-10-23 15:18:54"
12+
"lastUpdated": "2012-03-05 03:55:36"
1313
}
1414

1515
/*
@@ -245,7 +245,6 @@ var testCases = [
245245
"seeAlso": [],
246246
"attachments": [
247247
{
248-
"url": false,
249248
"title": "Chronicle of Higher Education Snapshot",
250249
"mimeType": "text/html"
251250
}
@@ -255,8 +254,11 @@ var testCases = [
255254
"ISSN": "0009-5982",
256255
"date": "June 16, 2006",
257256
"title": "Grinnell's Green Secrets",
258-
"section": "News",
259-
"libraryCatalog": "The Chronicle of Higher Education"
257+
"section": "News : Short Subjects",
258+
"pages": "A9",
259+
"edition": "Volume 52, Issue 41",
260+
"libraryCatalog": "The Chronicle of Higher Education",
261+
"accessDate": "CURRENT_TIMESTAMP"
260262
}
261263
]
262264
},

The Daily Beast.js

+6-5
Large diffs are not rendered by default.

The Free Dictionary.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"translatorID": "0c661209-5ec8-402b-8f18-7dec6ae37d95",
33
"label": "The Free Dictionary",
44
"creator": "Michael Berkowitz",
5-
"target": "http://(.*\\.)?thefreedictionary.com/(\\w+)",
5+
"target": "http://(.*\\.)?thefreedictionary.com/\\w+$",
66
"minVersion": "1.0.0b4.r5",
77
"maxVersion": "",
88
"priority": 100,
99
"inRepository": true,
1010
"translatorType": 4,
1111
"browserSupport": "gcs",
12-
"lastUpdated": "2012-01-30 22:42:23"
12+
"lastUpdated": "2012-03-05 03:44:25"
1313
}
1414

1515
function detectWeb(doc, url) {

The Hamilton Spectator.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
"inRepository": true,
1010
"translatorType": 4,
1111
"browserSupport": "gcs",
12-
"lastUpdated": "2012-01-30 22:42:12"
12+
"lastUpdated": "2012-03-05 03:14:39"
1313
}
1414

1515
function detectWeb(doc, url) {
16-
if (doc.location.href.match("SearchResults")) {
16+
if (url.indexOf("SearchResults") != -1) {
1717
return "multiple";
18-
} else if (doc.location.href.match("article")) {
18+
} else if (url.indexOf("article") != -1) {
1919
return "newspaperArticle";
2020
}
2121
}
@@ -70,7 +70,10 @@ function scrape(doc, url) {
7070

7171
var xPathTitle = '//h1';
7272
newItem.title = doc.evaluate(xPathTitle, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
73-
73+
74+
newItem.abstractNote = ZU.xpathText(doc, '//meta[@name="Description"]/@content');
75+
newItem.date = ZU.xpathText(doc, '//span[contains(@class,"ts-publishdate")]');
76+
7477
newItem.url = doc.location.href;
7578
newItem.publicationTitle = "The Hamilton Spectator";
7679

@@ -83,8 +86,6 @@ function doWeb(doc, url) {
8386
if (prefix == 'x') return namespace; else return null;
8487
} : null;
8588

86-
var articles = new Array();
87-
8889
if (detectWeb(doc, url) == "multiple") {
8990
var items = new Object();
9091

@@ -94,15 +95,18 @@ function doWeb(doc, url) {
9495
while (next_title = titles.iterateNext()) {
9596
items[next_title.href] = next_title.textContent;
9697
}
97-
items = Zotero.selectItems(items);
98-
for (var i in items) {
99-
articles.push(i);
100-
}
98+
Zotero.selectItems(items, function(items) {
99+
if(!items) return true;
100+
101+
var articles = new Array();
102+
for (var i in items) {
103+
articles.push(i);
104+
}
105+
ZU.processDocuments(articles, function(doc) { scrape(doc, doc.location.href) });
106+
});
101107
} else {
102-
articles = [url];
108+
scrape(doc, url);
103109
}
104-
Zotero.Utilities.processDocuments(articles, scrape, function() {Zotero.done();});
105-
Zotero.wait();
106110
}/** BEGIN TEST CASES **/
107111
var testCases = [
108112
{
@@ -123,6 +127,8 @@ var testCases = [
123127
"seeAlso": [],
124128
"attachments": [],
125129
"title": "Expert calls Occupy demos most important in generations",
130+
"abstractNote": "The Occupy protest is the most important democratic social movement of the last two generations and demonstrators who have taken over parks and other",
131+
"date": "Wed Nov 16 2011",
126132
"url": "http://www.thespec.com/news/ontario/article/626278--expert-calls-occupy-demos-most-important-in-generations",
127133
"publicationTitle": "The Hamilton Spectator",
128134
"libraryCatalog": "The Hamilton Spectator",

0 commit comments

Comments
 (0)