forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEducation Week.js
95 lines (80 loc) · 3.1 KB
/
Education Week.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
{
"translatorID":"7e51d3fb-082e-4063-8601-cda08f6004a3",
"translatorType":4,
"label":"Education Week",
"creator":"Ben Parr",
"target":"^https?://(?:www\\.|blogs\\.|www2\\.)?edweek",
"minVersion":"1.0.0b4.r1",
"maxVersion":"",
"priority":100,
"inRepository":true,
"lastUpdated":"2011-01-11 04:31:00"
}
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='//meta[@name="Story_type"]/@content';
var temp=doc.evaluate(xpath, doc, nsResolver,XPathResult.ANY_TYPE,null).iterateNext();
if(temp)
{
if(temp.value=="Blog")
{return "blogPost";}
if(temp.value.indexOf("Story")>-1)
{return "magazineArticle";}
}
}
function associateMeta(newItem, metaTags, field, zoteroField) {
if(metaTags[field]) {
newItem[zoteroField] = metaTags[field];
}
}
function scrape(doc, url) {
var newItem = new Zotero.Item("magazineArticle");
if(url&&url.indexOf("blogs.edweek.org")>-1)
{newItem.itemType="blogPost";}
newItem.url = doc.location.href;
var metaTags = new Object();
var metaTagHTML = doc.getElementsByTagName("meta");
var i;
for (i = 0 ; i < metaTagHTML.length ; i++) {
metaTags[metaTagHTML[i].getAttribute("name")]=Zotero.Utilities.cleanTags(metaTagHTML[i].getAttribute("content"));
}
associateMeta(newItem, metaTags, "Title", "title");
associateMeta(newItem, metaTags, "Cover_date", "date");
associateMeta(newItem, metaTags, "Description", "abstractNote");
associateMeta(newItem, metaTags, "ArticleID", "accessionNumber");
associateMeta(newItem,metaTags,"Source","publicationTitle");
if (metaTags["Authors"]) {
var author = Zotero.Utilities.trimInternal(metaTags["Authors"]);
if (author.substr(0,3).toLowerCase() == "by ") {
author = author.substr(3);
}
var authors = author.split(" and ");
for each(var author in authors) {
var words = author.split(" ");
for (var i in words) {
words[i] = words[i][0].toUpperCase() +words[i].substr(1).toLowerCase();
}
author = words.join(" ");
newItem.creators.push(Zotero.Utilities.cleanAuthor(author, "author"));
}
}
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="Story_type"]/@content';
var temp=doc.evaluate(xpath, doc, nsResolver,XPathResult.ANY_TYPE,null).iterateNext();
if(temp)
{
if(temp.value.indexOf("Story")>-1 || temp.value=="Blog")
{scrape(doc,url);}
}
}