forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTime-Blog.com.js
139 lines (121 loc) · 3.99 KB
/
Time-Blog.com.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
{
"translatorID":"b33bbb49-03d2-4175-91c4-3840501bc953",
"translatorType":4,
"label":"Time-Blog.com",
"creator":"Michael Berkowitz",
"target":"^http://time-blog.com/",
"minVersion":"1.0.0b4.r5",
"maxVersion":"",
"priority":100,
"inRepository":true,
"lastUpdated":"2011-01-11 04:31:00"
}
function detectWeb(doc, url) {
if (url.substr(-4,4) == "html") {
return "blogPost";
} else {
return "multiple";
}
}
function scrape(doc, url) {
var newItem = new Zotero.Item("blogPost");
newItem.url = doc.location.href;
newItem.title = doc.title.substr(0, doc.title.indexOf(" - "));
var titleRE = new RegExp('^http://time-blog.com/([^/]*)/');
var title = titleRE.exec(doc.location.href)[1].split("_");
for (var i = 0 ; i < title.length ; i++) {
title[i] = title[i][0].toUpperCase() + title[i].substr(1).toLowerCase();
}
newItem.blogTitle = title.join(" ");
var metaTags = new Object();
var metaTagHTML = doc.getElementsByTagName("meta");
for (var i = 0 ; i < metaTagHTML.length ; i++) {
metaTags[metaTagHTML[i].getAttribute("name")] = metaTagHTML[i].getAttribute("content");
}
if (metaTags["description"]) {
newItem.abstractNote = Zotero.Utilities.trimInternal(Zotero.Utilities.cleanTags(metaTags["description"]));
}
if (metaTags["date"]) {
var date = metaTags["date"];
var months = new Object();
months["jan"] = "January";
months["feb"] = "February";
months["mar"] = "March";
months["apr"] = "April";
months["may"] = "May";
months["jun"] = "June";
months["jul"] = "July";
months["aug"] = "August";
months["sep"] = "September";
months["oct"] = "October";
months["nov"] = "November";
months["dec"] = "December";
date = date.split(".").join("").split(", ");
date[0] = months[date[0].split(" ")[0].toLowerCase()] + " " + date[0].split(" ")[1];
newItem.date = date.join(", ");
}
if (metaTags["keywords"]) {
newItem.tags = metaTags["keywords"].split(", ");
for (var i in newItem.tags) {
if (newItem.tags[i] == "" || newItem.tags[i] == " ") {
break;
} else {
var words = newItem.tags[i].split(" ");
for (var j = 0 ; j < words.length ; j++) {
if (words[j][0] == words[j][0].toLowerCase() && words[j][0]) {
words[j] = words[j][0].toUpperCase() + words[j].substr(1).toLowerCase();
}
}
}
newItem.tags[i] = words.join(" ");
}
}
if (doc.evaluate('//span[@class="postedby"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext()) {
var byline = Zotero.Utilities.trimInternal(doc.evaluate('//span[@class="postedby"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
if (byline.substr(0,9).toLowerCase() == "posted by") {
byline = byline.substr(10).split(" ");
} else {
byline.split(" ");
}
for (var i = 0; i < byline.length ; i++) {
byline[i] = byline[i][0].toUpperCase() + byline[i].substr(1).toLowerCase();
}
newItem.creators.push(Zotero.Utilities.cleanAuthor(byline.join(" "), "author"));
} else if (newItem.blogTitle == "Theag") {
newItem.creators.push(Zotero.Utilities.cleanAuthor("Matthew Yeomans", "author"));
newItem.blogTitle = "the Aggregator";
}
Zotero.debug(newItem);
newItem.complete();
}
function doWeb(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == "x") return namespace; else return null;
} : null;
var URIS = new Array();
var xpath = '//h1[@class="entryTitle"]/a';
var articles = doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null);
var art = articles.iterateNext();
var arts = new Array();
var urls = new Array();
while (art) {
arts.push(art.textContent);
urls.push(art.href);
art = articles.iterateNext();
}
if (arts.length > 1) {
var items = new Object;
for (var i = 0; i < arts.length ; i++ ) {
items[urls[i]] = arts[i];
}
items = Zotero.selectItems(items);
for (i in items) {
URIS.push(i);
}
} else {
URIS.push(url);
}
Zotero.Utilities.processDocuments(URIS, scrape, function() { Zotero.done(); } );
Zotero.wait();
}