-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
bibtexConverter.js
58 lines (53 loc) · 1.53 KB
/
bibtexConverter.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
convertToBibTex = function(items, conversionMode) {
let deferred = Zotero.Promise.defer();
let translation = new Zotero.Translate.Export();
translation.setItems(items);
if (conversionMode === "biblatex") {
console.log("JabRef: Converting item(s) to BibLaTeX: %o", items);
translation.setTranslator("b6e39b57-8942-4d11-8259-342c46ce395f"); // BibLaTeX
}
else {
console.log("JabRef: Converting item(s) to BibTeX: %o", items);
translation.setTranslator("9cb70025-a888-4a29-a210-93ec52da40d4"); // BibTeX
}
translation.setHandler("done", function(obj, worked) {
if (worked) {
deferred.resolve(obj.string);
} else {
deferred.reject("Problem translating the item to BibTeX.")
}
});
translation.translate();
return deferred.promise;
};
Zotero.Translate.ItemGetter = function() {
this._itemsLeft = [];
this._collectionsLeft = null;
this._exportFileDirectory = null;
this.legacy = false;
};
Zotero.Translate.ItemGetter.prototype = {
"setItems": function(items) {
this._itemsLeft = items;
this._itemsLeft.sort(function(a, b) {
return a.id - b.id;
});
this.numItems = this._itemsLeft.length;
},
/**
* Retrieves the next available item
*/
"nextItem": function() {
if (this._itemsLeft.length !== 0) {
return this._itemsLeft.shift();
} else {
return false;
}
}
};
browser.runtime.onMessage.addListener(message => {
if (message.convertToBibTex) {
console.log("JabRef: Got task to convert %o to BibTeX", message.convertToBibTex);
return convertToBibTex(message.convertToBibTex, message.conversionMode);
}
});