Skip to content

Commit b04b770

Browse files
committed
execute script
1 parent c5fae40 commit b04b770

40 files changed

+16659
-27767
lines changed

external-scripts/background.js

Lines changed: 552 additions & 388 deletions
Large diffs are not rendered by default.

external-scripts/cachedTypes.js

Lines changed: 57 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -38,160 +38,143 @@ Zotero.Connector_Types = new function() {
3838
*/
3939
this.init = function() {
4040
const schemaTypes = ["itemTypes", "creatorTypes", "fields"];
41-
41+
4242
// attach IDs and make referenceable by either ID or name
43-
for (var i = 0; i < schemaTypes.length; i++) {
43+
for(var i=0; i<schemaTypes.length; i++) {
4444
var schemaType = schemaTypes[i];
4545
this[schemaType] = Zotero.Utilities.deepCopy(TypeSchema[schemaType]);
46-
for (var id in TypeSchema[schemaType]) {
46+
for(var id in TypeSchema[schemaType]) {
4747
var entry = this[schemaType][id];
4848
entry.unshift(parseInt(id, 10));
49-
this[schemaType][entry[1] /* name */ ] = entry;
49+
this[schemaType][entry[1]/* name */] = entry;
5050
}
5151
}
52-
52+
5353
var itemTypes = Zotero.Connector_Types["itemTypes"];
5454
var creatorTypes = Zotero.Connector_Types["creatorTypes"];
5555
var fields = Zotero.Connector_Types["fields"];
5656

5757
Zotero.CachedTypes = function() {
5858
var thisType = Zotero.Connector_Types[this.schemaType];
59-
59+
6060
this.getID = function(idOrName) {
6161
var type = thisType[idOrName];
62-
return (type ? type[0] /* id */ : false);
62+
return (type ? type[0]/* id */ : false);
6363
};
64-
64+
6565
this.getName = function(idOrName) {
6666
var type = thisType[idOrName];
67-
return (type ? type[1] /* name */ : false);
67+
return (type ? type[1]/* name */ : false);
6868
};
69-
69+
7070
this.getLocalizedString = function(idOrName) {
7171
var type = thisType[idOrName];
72-
return (type ? type[2] /* localizedString */ : false);
72+
return (type ? type[2]/* localizedString */ : false);
7373
};
7474
}
75-
75+
7676
Zotero.ItemTypes = new function() {
7777
this.schemaType = "itemTypes";
7878
Zotero.CachedTypes.call(this);
79-
79+
8080
this.getImageSrc = function(idOrName) {
8181
var itemType = Zotero.Connector_Types["itemTypes"][idOrName];
82-
var icon = itemType ? itemType[6] /* icon */ : "treeitem-" + idOrName + ".png";
83-
84-
if (Zotero.isBookmarklet) {
85-
return ZOTERO_CONFIG.BOOKMARKLET_URL + "images/" + icon;
86-
} else if (Zotero.isBrowserExt) {
87-
return browser.runtime.getURL("images/" + icon);
88-
} else if (Zotero.isSafari) {
89-
if (typeof safari == "undefined") {
90-
return "images/" + icon;
91-
} else {
92-
return `${safari.extension.baseURI}safari/` + "images/" + icon;
93-
}
94-
}
82+
var icon = itemType ? itemType[6]/* icon */ : "treeitem-"+idOrName+".png";
83+
84+
return Zotero.getExtensionURL("images/" + icon);
9585
};
9686
}
97-
87+
9888
Zotero.CreatorTypes = new function() {
9989
this.schemaType = "creatorTypes";
10090
Zotero.CachedTypes.call(this);
101-
91+
10292
this.getTypesForItemType = function(idOrName) {
10393
var itemType = itemTypes[idOrName];
104-
if (!itemType) return false;
105-
94+
if(!itemType) return false;
95+
10696
var itemCreatorTypes = itemType[3]; // creatorTypes
10797
if (!itemCreatorTypes
108-
// TEMP: 'note' and 'attachment' have an array containing false
109-
||
110-
(itemCreatorTypes.length == 1 && !itemCreatorTypes[0])) {
98+
// TEMP: 'note' and 'attachment' have an array containing false
99+
|| (itemCreatorTypes.length == 1 && !itemCreatorTypes[0])) {
111100
return [];
112101
}
113102
var n = itemCreatorTypes.length;
114103
var outputTypes = new Array(n);
115-
116-
for (var i = 0; i < n; i++) {
104+
105+
for(var i=0; i<n; i++) {
117106
var creatorType = creatorTypes[itemCreatorTypes[i]];
118-
outputTypes[i] = {
119-
"id": creatorType[0] /* id */ ,
120-
"name": creatorType[1] /* name */
121-
};
107+
outputTypes[i] = {"id":creatorType[0]/* id */,
108+
"name":creatorType[1]/* name */};
122109
}
123110
return outputTypes;
124111
};
125-
112+
126113
this.getPrimaryIDForType = function(idOrName) {
127114
var itemType = itemTypes[idOrName];
128-
if (!itemType) return false;
129-
return itemType[3] /* creatorTypes */ [0];
115+
if(!itemType) return false;
116+
return itemType[3]/* creatorTypes */[0];
130117
};
131-
118+
132119
this.isValidForItemType = function(creatorTypeID, itemTypeID) {
133120
let itemType = itemTypes[itemTypeID];
134-
return itemType[3] /* creatorTypes */ .includes(creatorTypeID);
121+
return itemType[3]/* creatorTypes */.includes(creatorTypeID);
135122
};
136123
};
137-
124+
138125
Zotero.ItemFields = new function() {
139126
this.schemaType = "fields";
140127
Zotero.CachedTypes.call(this);
141-
128+
142129
this.isValidForType = function(fieldIdOrName, typeIdOrName) {
143-
var field = fields[fieldIdOrName],
144-
itemType = itemTypes[typeIdOrName];
145-
130+
var field = fields[fieldIdOrName], itemType = itemTypes[typeIdOrName];
131+
146132
// mimics itemFields.js
147-
if (!field || !itemType) return false;
148-
149-
/* fields */
150-
/* id */
133+
if(!field || !itemType) return false;
134+
135+
/* fields */ /* id */
151136
return itemType[4].indexOf(field[0]) !== -1;
152137
};
153-
138+
154139
this.isBaseField = function(fieldID) {
155140
return fields[fieldID][2];
156141
};
157-
142+
158143
this.getFieldIDFromTypeAndBase = function(typeIdOrName, fieldIdOrName) {
159-
var baseField = fields[fieldIdOrName],
160-
itemType = itemTypes[typeIdOrName];
161-
162-
if (!baseField || !itemType) return false;
163-
144+
var baseField = fields[fieldIdOrName], itemType = itemTypes[typeIdOrName];
145+
146+
if(!baseField || !itemType) return false;
147+
164148
// get as ID
165-
baseField = baseField[0] /* id */ ;
166-
149+
baseField = baseField[0]/* id */;
150+
167151
// loop through base fields for item type
168152
var baseFields = itemType[5];
169-
for (var i in baseFields) {
170-
if (baseFields[i] === baseField) {
153+
for(var i in baseFields) {
154+
if(baseFields[i] === baseField) {
171155
return i;
172156
}
173157
}
174-
158+
175159
return false;
176160
};
177-
161+
178162
this.getBaseIDFromTypeAndField = function(typeIdOrName, fieldIdOrName) {
179-
var field = fields[fieldIdOrName],
180-
itemType = itemTypes[typeIdOrName];
181-
if (!field || !itemType) {
163+
var field = fields[fieldIdOrName], itemType = itemTypes[typeIdOrName];
164+
if(!field || !itemType) {
182165
throw new Error("Invalid field or type ID");
183166
}
184-
185-
var baseField = itemType[5] /* baseFields */ [field[0] /* id */ ];
167+
168+
var baseField = itemType[5]/* baseFields */[field[0]/* id */];
186169
return baseField ? baseField : false;
187170
};
188-
171+
189172
this.getItemTypeFields = function(typeIdOrName) {
190-
return itemTypes[typeIdOrName][4] /* fields */ .slice();
173+
return itemTypes[typeIdOrName][4]/* fields */.slice();
191174
};
192175
}
193176
};
194-
177+
195178
/**
196179
* Passes schema to a callback
197180
*/

0 commit comments

Comments
 (0)