forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ARTstor.js
131 lines (103 loc) · 3.52 KB
/
ARTstor.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
{
"translatorID": "5278b20c-7c2c-4599-a785-12198ea648bf",
"label": "ARTstor",
"creator": "Sebastian Karcher",
"target": "^https?://library\\.artstor\\.org",
"minVersion": "3.1",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcs",
"lastUpdated": "2014-11-13 15:09:17"
}
/*
***** BEGIN LICENSE BLOCK *****
ARTstor Translator, Copyright © 2012 Sebastian Karcher
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
function getData(doc, checkOnly) {
var data = {},
widgets = doc.getElementsByClassName('MetaDataWidget'),
topWidget = null, topZIndex;
// Dtermine the top metadata window
for (var i=0; i<widgets.length; i++) {
var zindex = doc.defaultView.getComputedStyle(widgets[i], null)
.getPropertyValue('z-index');
if (!zindex && zindex !== 0) continue;
if (!topWidget || topZIndex < zindex) {
topWidget = widgets[i];
topZIndex = zindex;
}
}
if (!topWidget) return false;
var fields = topWidget.getElementsByClassName('field'),
found = false;
for (var i=0; i<fields.length; i++) {
var field = ZU.trimInternal(fields[i].textContent);
var value = fields[i].nextElementSibling;
if (!value || !value.classList.contains('data')) continue;
value = ZU.unescapeHTML(ZU.cleanTags(value.innerHTML));
if (!field || !value.trim()) continue;
if (checkOnly) return true;
found = true;
data[field] = value;
}
return found ? data : false;
}
function detectWeb(doc, url) {
//monitor changes to body's direct children. That's where the metadata popup is added
Zotero.monitorDOMChanges(doc.body, {childList: true});
if (getData(doc, true)) {
return "artwork";
}
}
function associateData(newItem, value, field) {
if (!value) return;
if (typeof value == 'string') value = ZU.trimInternal(value);
if (!value) return;
newItem[field] = value;
}
function doWeb(doc, url) {
var newItem = new Zotero.Item("artwork"),
data = getData(doc),
content;
if (data.Creator) {
content = data.Creator.replace(/\s*\(.*/, '');
associateData(newItem,
ZU.cleanAuthor(content, "artist", artist.indexOf(',') != -1),
'creators'
);
}
if (data.Date) {
content = data.Date.replace(/^Photographed (?:in )?/, '');
associateData(newItem, content, "date");
}
if (data.Rights) {
var m = data.Rights.match(/^.*(©.*)$/m);
if (m) associateData(newItem, m[1], "rights");
}
if (data.Subject) {
content = data.Subject.split(/\s*;\s*/);
associateData(newItem, content, 'tags');
}
//these might not be complete - it's pretty straightforward to add more
associateData(newItem, data.Title, "title");
associateData(newItem, data.Measurements, "artworkSize");
associateData(newItem, data.Material, "artworkMedium");
associateData(newItem, data.Repository, "archive");
associateData(newItem, data['ID Number'], "archiveLocation");
associateData(newItem, data.Description, "abstractNote");
newItem.complete();
}