forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 2
/
BusinessWeek.js
102 lines (100 loc) · 3 KB
/
BusinessWeek.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{
"translatorID": "fb342bae-7727-483b-a871-c64c663c2fae",
"label": "BusinessWeek",
"creator": "Michael Berkowitz",
"target": "^https?://(www\\.)?businessweek\\.com",
"minVersion": "1.0.0b4.r5",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcs",
"lastUpdated": "2012-01-30 22:52:13"
}
function detectWeb(doc, url) {
if (doc.title == "BusinessWeek Search Results") {
return "multiple";
} else if (doc.evaluate('//meta[@name="headline"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
return "magazineArticle";
}
}
function doWeb(doc, url) {
var articles = new Array();
if (detectWeb(doc, url) == "multiple") {
var results = doc.evaluate('//h3[@class="story"]/a', doc, null, XPathResult.ANY_TYPE, null);
var result;
var items = new Object();
while (result = results.iterateNext()) {
items[result.href] = Zotero.Utilities.trimInternal(result.textContent);
}
items = Zotero.selectItems(items);
for (var i in items) {
articles.push(i);
}
} else {
articles = [url];
}
Zotero.debug(articles);
Zotero.Utilities.processDocuments(articles, function(newDoc) {
var metaTags = new Object();
var metas = newDoc.evaluate('//meta', newDoc, null, XPathResult.ANY_TYPE, null);
var meta;
while (meta = metas.iterateNext()) {
metaTags[meta.name] = meta.content;
}
Zotero.debug(metaTags);
var item = new Zotero.Item("magazineArticle");
item.title = metaTags['headline'];
item.abstractNote = metaTags['abstract'];
item.tags = metaTags['keywords'].split(/\s*,\s*/);
//some articles don't have author tags - prevent this from failing
if (metaTags['author']) item.creators.push(Zotero.Utilities.cleanAuthor(metaTags['author'], "author"));
item.publicationTitle = "BusinessWeek: " + metaTags['channel'];
item.url = newDoc.location.href;
item.date = metaTags['pub_date'].replace(/(\d{4})(\d{2})(\d{2})/, "$2/$3/$1");
item.complete();
}, function() {Zotero.done();});
Zotero.wait();
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://www.businessweek.com/management/ten-things-only-bad-managers-say-09232011.html?campaign_id=rss_topStories",
"items": [
{
"itemType": "magazineArticle",
"creators": [
{
"firstName": "Liz",
"lastName": "Ryan",
"creatorType": "author"
}
],
"notes": [],
"tags": [
"leadership",
"management",
"bad bosses",
"leaders",
"Liz Ryan",
"bad managers",
"lousy managers"
],
"seeAlso": [],
"attachments": [],
"title": "Ten Things Only Bad Managers Say",
"publicationTitle": "BusinessWeek: Management",
"url": "http://www.businessweek.com/management/ten-things-only-bad-managers-say-09232011.html?campaign_id=rss_topStories",
"date": "09/23/2011",
"libraryCatalog": "BusinessWeek",
"accessDate": "CURRENT_TIMESTAMP"
}
]
},
{
"type": "web",
"url": "http://search.businessweek.com/Search?searchTerm=linux&resultsPerPage=20",
"items": "multiple"
}
]
/** END TEST CASES **/