-
Notifications
You must be signed in to change notification settings - Fork 767
/
BBC.js
148 lines (128 loc) · 4.01 KB
/
BBC.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
140
141
142
143
144
145
146
147
148
{
"translatorID": "f4130157-93f7-4493-8f24-a7c85549013d",
"label": "BBC",
"creator": "Ben Parr",
"target": "^https?://(?:www|news?)\\.bbc\\.co\\.uk",
"minVersion": "1.0.0b4.r1",
"maxVersion": "",
"priority": 100,
"browserSupport": "gcsb",
"inRepository": true,
"translatorType": 4,
"lastUpdated": "2012-01-01 01:42:16"
}
function detectWeb(doc, url)
{
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
var xpath;
xpath='//meta[@name="Headline"]';
if(content=doc.evaluate(xpath, doc, nsResolver,XPathResult.ANY_TYPE, null).iterateNext())
{ return "newspaperArticle"; }
xpath='//font[@class="poshead"]/b';
if(doc.evaluate(xpath, doc, nsResolver,XPathResult.ANY_TYPE, null).iterateNext())
{ return "newspaperArticle"; }
return null;
}
function scrape(doc,url,title)
{
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
var newItem = new Zotero.Item("newspaperArticle");
newItem.url=url;
newItem.repository="bbc.co.uk";
newItem.publicationTitle="BBC";
newItem.title=title;
xpath='//meta[@name="OriginalPublicationDate"]/@content';
var temp=doc.evaluate(xpath, doc, nsResolver,XPathResult.ANY_TYPE, null).iterateNext();
if(temp)
{
temp=temp.value;
temp=temp.split(" ")[0];
newItem.date=temp;
}
else
{
xpath='//font[@class="postxt"][@size="1"]';
var rows=doc.evaluate(xpath, doc, nsResolver,XPathResult.ANY_TYPE, null);
var row;
while(row=rows.iterateNext())
{
temp=row.textContent;
if(temp.substr(0,9)=="Created: ")
{
newItem.date=temp.substr(9);
break;
}
}
}
xpath='//meta[@name="Section"]/@content';
temp=doc.evaluate(xpath, doc, nsResolver,XPathResult.ANY_TYPE, null).iterateNext();
if(temp)
{ newItem.section=temp.value; }
xpath='//meta[@name="Description"]/@content';
temp=doc.evaluate(xpath, doc, nsResolver,XPathResult.ANY_TYPE, null).iterateNext();
if(temp)
{ newItem.abstractNote=temp.value; }
else
{
xpath='//meta[@name="description"]/@content';
temp=doc.evaluate(xpath, doc, nsResolver,XPathResult.ANY_TYPE, null).iterateNext();
if(temp)
{ newItem.abstractNote=temp.value; }
}
newItem.attachments.push({url:url, title:"BBC News Snapshot",mimeType:"text/html"});
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 xpath='//meta[@name="Headline"]/@content';
var title;
if(title=doc.evaluate(xpath, doc, nsResolver,XPathResult.ANY_TYPE, null).iterateNext())
{ scrape(doc,url,title.value) }
else
{
xpath='//font[@class="poshead"]/b';
if(title=doc.evaluate(xpath, doc, nsResolver,XPathResult.ANY_TYPE, null).iterateNext())
{ scrape(doc,url,title.textContent) }
}
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://www.bbc.co.uk/news/magazine-15335899",
"items": [
{
"itemType": "newspaperArticle",
"creators": [],
"notes": [],
"tags": [],
"seeAlso": [],
"attachments": [
{
"url": "http://www.bbc.co.uk/news/magazine-15335899",
"title": "BBC News Snapshot",
"mimeType": "text/html"
}
],
"url": "http://www.bbc.co.uk/news/magazine-15335899",
"publicationTitle": "BBC",
"title": "Spain's stolen babies",
"date": "2011/10/18",
"section": "Magazine",
"abstractNote": "Spanish society has been shaken by revelations of the mass trafficking of babies, dating back to the Franco era but continuing until the 1990s involving respected doctors, nuns and priests.",
"libraryCatalog": "bbc.co.uk",
"accessDate": "CURRENT_TIMESTAMP"
}
]
}
]
/** END TEST CASES **/