zotero-plugin 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/debug-log.d.ts +3 -3
- package/debug-log.js +58 -51
- package/package.json +1 -1
package/debug-log.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export declare function unregister(plugin: string): void;
|
|
2
1
|
declare class DebugLogSender {
|
|
3
2
|
plugins: Record<string, string[]>;
|
|
3
|
+
convertLegacy(): void;
|
|
4
|
+
private element;
|
|
4
5
|
register(plugin: string, preferences?: string[]): void;
|
|
5
6
|
unregister(plugin: string): void;
|
|
6
7
|
private alert;
|
|
7
|
-
|
|
8
|
-
send(): void;
|
|
8
|
+
send(target: EventTarget): void;
|
|
9
9
|
private sendAsync;
|
|
10
10
|
private preferences;
|
|
11
11
|
private post;
|
package/debug-log.js
CHANGED
|
@@ -1,42 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable no-magic-numbers */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.DebugLog =
|
|
4
|
+
exports.DebugLog = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const tar_js_1 = tslib_1.__importDefault(require("tar-js"));
|
|
7
7
|
const pako_1 = require("pako");
|
|
8
|
-
function unregister(plugin) {
|
|
9
|
-
Zotero.debug(`debug-log-sender: unregistering ${plugin}`);
|
|
10
|
-
delete Zotero.DebugLogSender.plugins[plugin];
|
|
11
|
-
if (!Object.keys(Zotero.DebugLogSender.plugins).length) {
|
|
12
|
-
const doc = Zotero.getMainWindow().document;
|
|
13
|
-
const menuitem = doc.querySelector('menuitem#debug-log-menu');
|
|
14
|
-
if (menuitem)
|
|
15
|
-
menuitem.remove();
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.unregister = unregister;
|
|
19
8
|
class DebugLogSender {
|
|
20
9
|
constructor() {
|
|
21
10
|
this.plugins = {};
|
|
22
11
|
}
|
|
12
|
+
convertLegacy() {
|
|
13
|
+
var _a, _b, _c;
|
|
14
|
+
const doc = Zotero.getMainWindow().document;
|
|
15
|
+
(_a = doc.querySelector('menuitem#debug-log-menu')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
16
|
+
if ((_b = Zotero.DebugLogSender) === null || _b === void 0 ? void 0 : _b.plugins) {
|
|
17
|
+
for (const [plugin, preferences] of Object.entries(Zotero.DebugLogSender.plugins)) {
|
|
18
|
+
this.register(plugin, preferences);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
(_c = Zotero.DebugLogSender) === null || _c === void 0 ? true : delete _c.plugins;
|
|
22
|
+
}
|
|
23
|
+
element(name, attrs = {}) {
|
|
24
|
+
const doc = Zotero.getMainWindow().document;
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
26
|
+
const elt = doc[Zotero.platformMajorVersion >= 102 ? 'createXULElement' : 'createElement'](name);
|
|
27
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
28
|
+
elt.setAttribute(k, v);
|
|
29
|
+
}
|
|
30
|
+
return elt;
|
|
31
|
+
}
|
|
23
32
|
register(plugin, preferences = []) {
|
|
24
|
-
|
|
33
|
+
var _a;
|
|
34
|
+
this.convertLegacy();
|
|
25
35
|
const doc = Zotero.getMainWindow().document;
|
|
26
|
-
|
|
27
|
-
if (!
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const menuitem = help.appendChild(doc[Zotero.platformMajorVersion >= 102 ? 'createXULElement' : 'createElement']('menuitem'));
|
|
32
|
-
menuitem.setAttribute('id', 'debug-log-menu');
|
|
33
|
-
menuitem.setAttribute('label', 'Send debug log to file.io');
|
|
34
|
-
menuitem.setAttribute('oncommand', 'Zotero.DebugLogSender.send()');
|
|
35
|
-
Zotero.debug('debug-log-sender: menu entry added');
|
|
36
|
+
let menupopup = doc.querySelector('#debug-log-sender-menupopup');
|
|
37
|
+
if (!menupopup) {
|
|
38
|
+
menupopup = doc.querySelector('menupopup#menu_HelpPopup')
|
|
39
|
+
.appendChild(this.element('menu', { id: 'debug-log-sender-menu', label: 'Send debug log to file.io' }))
|
|
40
|
+
.appendChild(this.element('menupopup', { id: 'debug-log-sender-menupopup' }));
|
|
36
41
|
}
|
|
42
|
+
(_a = doc.querySelector(`.debug-log-sender[label=${JSON.stringify(plugin)}]`)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
43
|
+
const menuitem = menupopup.appendChild(this.element('menuitem', {
|
|
44
|
+
label: plugin,
|
|
45
|
+
'data-preferences': JSON.stringify(preferences || []),
|
|
46
|
+
}));
|
|
47
|
+
menuitem.addEventListener('command', event => this.send(event.currentTarget));
|
|
37
48
|
}
|
|
38
49
|
unregister(plugin) {
|
|
39
|
-
|
|
50
|
+
var _a, _b;
|
|
51
|
+
const doc = Zotero.getMainWindow().document;
|
|
52
|
+
(_a = doc.querySelector(`.debug-log-sender[label=${JSON.stringify(plugin)}]`)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
53
|
+
const menupopup = doc.querySelector('#debug-log-sender-menupopup');
|
|
54
|
+
if (menupopup && !menupopup.children.length)
|
|
55
|
+
(_b = doc.querySelector('#debug-log-sender-menu')) === null || _b === void 0 ? void 0 : _b.remove();
|
|
40
56
|
}
|
|
41
57
|
alert(title, body) {
|
|
42
58
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
@@ -44,48 +60,38 @@ class DebugLogSender {
|
|
|
44
60
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
45
61
|
ps.alert(null, title, body);
|
|
46
62
|
}
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const prompts = Components.classes['@mozilla.org/embedcomp/prompt-service;1'].getService(Components.interfaces.nsIPromptService);
|
|
53
|
-
const selected = { value: -1 };
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
55
|
-
if (!prompts.select(null, 'Plugin', 'Send debug log for', plugins.length, plugins, selected))
|
|
56
|
-
return null;
|
|
57
|
-
return plugins[selected.value];
|
|
58
|
-
}
|
|
59
|
-
send() {
|
|
60
|
-
this.sendAsync().catch((err) => {
|
|
63
|
+
send(target) {
|
|
64
|
+
const elt = target;
|
|
65
|
+
const plugin = elt.getAttribute('label');
|
|
66
|
+
const preferences = JSON.parse(elt.getAttribute('data-preferences'));
|
|
67
|
+
this.sendAsync(plugin, preferences).catch((err) => {
|
|
61
68
|
this.alert('Debug log submission error', `${err}`); // eslint-disable-line @typescript-eslint/restrict-template-expressions
|
|
62
69
|
});
|
|
63
70
|
}
|
|
64
|
-
async sendAsync() {
|
|
71
|
+
async sendAsync(plugin, preferences) {
|
|
65
72
|
await Zotero.Schema.schemaUpdatePromise;
|
|
66
|
-
const plugin = this.select();
|
|
67
73
|
const tape = new tar_js_1.default;
|
|
68
74
|
let out;
|
|
69
75
|
const key = Zotero.Utilities.generateObjectKey();
|
|
70
76
|
const log = [
|
|
71
|
-
await this.info(
|
|
77
|
+
await this.info(preferences),
|
|
72
78
|
Zotero.getErrors(true).join('\n\n'),
|
|
73
79
|
Zotero.Debug.getConsoleViewerOutput().slice(-250000).join('\n'), // eslint-disable-line no-magic-numbers
|
|
74
80
|
].filter((txt) => txt).join('\n\n').trim();
|
|
75
|
-
out = tape.append(`${key}
|
|
81
|
+
out = tape.append(`${key}/debug.txt`, log);
|
|
76
82
|
const rdf = await this.rdf();
|
|
77
83
|
if (rdf)
|
|
78
|
-
out = tape.append(`${key}
|
|
84
|
+
out = tape.append(`${key}/items.rdf`, rdf);
|
|
79
85
|
const blob = new Blob([(0, pako_1.gzip)(out)], { type: 'application/zip' });
|
|
80
86
|
const formData = new FormData();
|
|
81
87
|
formData.append('file', blob, `${key}.tgz`);
|
|
82
88
|
const response = await this.post('https://file.io', formData);
|
|
83
89
|
this.alert(`Debug log ID for ${plugin}`, `${response.key}-${key}`);
|
|
84
90
|
}
|
|
85
|
-
preferences(
|
|
91
|
+
preferences(preferences) {
|
|
86
92
|
const prefs = {};
|
|
87
93
|
const names = [];
|
|
88
|
-
for (const pref of
|
|
94
|
+
for (const pref of preferences) {
|
|
89
95
|
if (pref.endsWith('.')) {
|
|
90
96
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
91
97
|
const childkeys = Services.prefs.getBranch(pref).getChildList('', {});
|
|
@@ -107,7 +113,7 @@ class DebugLogSender {
|
|
|
107
113
|
return (await response.json());
|
|
108
114
|
}
|
|
109
115
|
// general state of Zotero
|
|
110
|
-
async info(
|
|
116
|
+
async info(preferences) {
|
|
111
117
|
let info = '';
|
|
112
118
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
|
113
119
|
const appInfo = Components.classes['@mozilla.org/xre/app-info;1'].getService(Components.interfaces.nsIXULAppInfo);
|
|
@@ -117,17 +123,19 @@ class DebugLogSender {
|
|
|
117
123
|
if (addons.length) {
|
|
118
124
|
info += 'Addons:\n' + addons.map((addon) => ` ${addon}\n`).join(''); // eslint-disable-line prefer-template
|
|
119
125
|
}
|
|
120
|
-
for (const [pref, value] of Object.entries(this.preferences(
|
|
126
|
+
for (const [pref, value] of Object.entries(this.preferences(preferences))) {
|
|
121
127
|
info += `${pref} = ${JSON.stringify(value)}\n`;
|
|
122
128
|
}
|
|
123
129
|
return info;
|
|
124
130
|
}
|
|
125
131
|
rdf() {
|
|
126
132
|
return new Promise((resolve, reject) => {
|
|
127
|
-
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
|
134
|
+
const items = Zotero.getActiveZoteroPane().getSelectedItems();
|
|
128
135
|
if (items.length === 0)
|
|
129
136
|
return resolve('');
|
|
130
|
-
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
138
|
+
const translation = new Zotero.Translate.Export();
|
|
131
139
|
translation.setItems(items);
|
|
132
140
|
translation.setTranslator('14763d24-8ba0-45df-8f52-b8d1108e7ac9'); // rdf
|
|
133
141
|
translation.setHandler('done', (obj, success) => {
|
|
@@ -142,5 +150,4 @@ class DebugLogSender {
|
|
|
142
150
|
});
|
|
143
151
|
}
|
|
144
152
|
}
|
|
145
|
-
|
|
146
|
-
exports.DebugLog = Zotero.DebugLogSender;
|
|
153
|
+
exports.DebugLog = new DebugLogSender;
|