-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreferences.js
More file actions
75 lines (68 loc) · 2.13 KB
/
preferences.js
File metadata and controls
75 lines (68 loc) · 2.13 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
74
75
var ZotPDF2mdPrefs = {
init() {
let clearCacheButton = document.getElementById("zotpdf2md-cache-clear");
if (clearCacheButton) {
clearCacheButton.addEventListener("command", () => this.clearCache());
}
},
async pickExportDir() {
try {
let ownerWindow = window;
try {
let { FilePicker } = ChromeUtils.importESModule("chrome://zotero/content/modules/filePicker.mjs");
let fp = new FilePicker();
fp.init(ownerWindow, "Select export directory", fp.modeGetFolder);
let rv = await fp.show();
if (rv === fp.returnOK) {
this.applyExportDir(fp.file?.path || fp.filePath || fp.path || "");
return;
}
} catch (innerError) {
Zotero.logError(innerError);
}
if (typeof Zotero.FilePicker === "function") {
let fp = new Zotero.FilePicker();
fp.init(ownerWindow, "Select export directory", fp.modeGetFolder);
let rv = await fp.show();
if (rv === fp.returnOK) {
this.applyExportDir(fp.file?.path || fp.filePath || fp.path || "");
return;
}
}
throw new Error("File picker unavailable");
} catch (e) {
Zotero.logError(e);
Zotero.alert(null, "ZotPDF2md", "Could not open folder picker. Please paste the path manually.\n\n" + e.message);
}
},
applyExportDir(path) {
if (!path) {
throw new Error("Selected folder path unavailable");
}
let normalized = path;
if (!Zotero.isWin) {
normalized = normalized.replace(/\\([\\'"~ ])/g, "$1");
}
let input = document.getElementById("zotpdf2md-export-dir");
if (input) {
input.value = normalized;
}
Zotero.Prefs.set("extensions.zotpdf2md.output.exportDir", normalized, true);
},
clearCache() {
Zotero.Prefs.set("extensions.zotpdf2md.cache.data", "{\"entries\":{}}", true);
Zotero.alert(null, "ZotPDF2md", "Cache cleared.");
}
};
function initPrefs() {
try {
ZotPDF2mdPrefs.init();
} catch (e) {
Zotero.logError(e);
}
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", initPrefs);
} else {
initPrefs();
}