-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathpreferences.js
More file actions
73 lines (66 loc) · 1.73 KB
/
preferences.js
File metadata and controls
73 lines (66 loc) · 1.73 KB
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
ZoteroCitationCounts_Prefs = {
/**
* @TODO reference ZoteroCitationCounts.APIs directly.
*/
APIs: [
{
key: "crossref",
name: "Crossref",
},
{
key: "inspire",
name: "INSPIRE-HEP",
},
{
key: "semanticscholar",
name: "Semantic Scholar",
},
],
init: function () {
this.APIs.concat({ key: "none" }).forEach((api) => {
const label =
api.key === "none"
? {
"data-l10n-id":
"citationcounts-preferences-pane-autoretrieve-api-none",
}
: {
"data-l10n-id":
"citationcounts-preferences-pane-autoretrieve-api",
"data-l10n-args": `{"api": "${api.name}"}`,
};
this._injectXULElement(
document,
"radio",
`citationcounts-preferences-pane-autoretrieve-radio-${api.key}`,
{
...label,
value: api.key,
},
"citationcounts-preference-pane-autoretrieve-radiogroup"
);
});
},
/**
* @TODO reference ZoteroCitationCounts._injectXULElement directly.
*/
_injectXULElement: function (
document,
elementType,
elementID,
elementAttributes,
parentID,
eventListeners
) {
const element = document.createXULElement(elementType);
element.id = elementID;
Object.entries(elementAttributes || {})
.filter(([_, value]) => value !== null && value !== undefined)
.forEach(([key, value]) => element.setAttribute(key, value));
Object.entries(eventListeners || {}).forEach(([eventType, listener]) => {
element.addEventListener(eventType, listener);
});
document.getElementById(parentID).appendChild(element);
return element;
},
};