zotero-plugin 2.0.2 → 2.0.4
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 +8 -3
- package/debug-log.js +67 -51
- package/package.json +2 -1
package/debug-log.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
export declare function unregister(plugin: string): void;
|
|
2
1
|
declare class DebugLogSender {
|
|
2
|
+
id: {
|
|
3
|
+
menu: string;
|
|
4
|
+
menupopup: string;
|
|
5
|
+
menuitem: string;
|
|
6
|
+
};
|
|
3
7
|
plugins: Record<string, string[]>;
|
|
8
|
+
convertLegacy(): void;
|
|
9
|
+
private element;
|
|
4
10
|
register(plugin: string, preferences?: string[]): void;
|
|
5
11
|
unregister(plugin: string): void;
|
|
6
12
|
private alert;
|
|
7
|
-
|
|
8
|
-
send(): void;
|
|
13
|
+
send(target: EventTarget): void;
|
|
9
14
|
private sendAsync;
|
|
10
15
|
private preferences;
|
|
11
16
|
private post;
|
package/debug-log.js
CHANGED
|
@@ -1,42 +1,67 @@
|
|
|
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() {
|
|
10
|
+
this.id = {
|
|
11
|
+
menu: 'debug-log-sender-menu',
|
|
12
|
+
menupopup: 'debug-log-sender-menupopup',
|
|
13
|
+
menuitem: 'debug-log-sender',
|
|
14
|
+
};
|
|
21
15
|
this.plugins = {};
|
|
22
16
|
}
|
|
17
|
+
convertLegacy() {
|
|
18
|
+
var _a;
|
|
19
|
+
if (!Zotero.DebugLogSender)
|
|
20
|
+
return;
|
|
21
|
+
const plugins = Zotero.DebugLogSender.plugins || {};
|
|
22
|
+
delete Zotero.DebugLogSender;
|
|
23
|
+
const doc = Zotero.getMainWindow().document;
|
|
24
|
+
(_a = doc.querySelector('menuitem#debug-log-menu')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
25
|
+
for (const [plugin, preferences] of Object.entries(plugins)) {
|
|
26
|
+
this.register(plugin, preferences);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
element(name, attrs = {}) {
|
|
30
|
+
const doc = Zotero.getMainWindow().document;
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
32
|
+
const elt = doc[Zotero.platformMajorVersion >= 102 ? 'createXULElement' : 'createElement'](name);
|
|
33
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
34
|
+
elt.setAttribute(k, v);
|
|
35
|
+
}
|
|
36
|
+
return elt;
|
|
37
|
+
}
|
|
23
38
|
register(plugin, preferences = []) {
|
|
24
|
-
|
|
39
|
+
var _a;
|
|
40
|
+
this.convertLegacy();
|
|
25
41
|
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');
|
|
42
|
+
let menupopup = doc.querySelector(`#${this.id.menupopup}`);
|
|
43
|
+
if (!menupopup) {
|
|
44
|
+
menupopup = doc.querySelector('menupopup#menu_HelpPopup')
|
|
45
|
+
.appendChild(this.element('menu', { id: this.id.menu, label: 'Send debug log to file.io' }))
|
|
46
|
+
.appendChild(this.element('menupopup', { id: this.id.menupopup }));
|
|
36
47
|
}
|
|
48
|
+
(_a = doc.querySelector(`.${this.id.menuitem}[label=${JSON.stringify(plugin)}]`)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
49
|
+
const menuitem = menupopup.appendChild(this.element('menuitem', {
|
|
50
|
+
label: plugin,
|
|
51
|
+
class: this.id.menuitem,
|
|
52
|
+
'data-preferences': JSON.stringify(preferences || []),
|
|
53
|
+
}));
|
|
54
|
+
menuitem.addEventListener('command', event => this.send(event.currentTarget));
|
|
37
55
|
}
|
|
38
56
|
unregister(plugin) {
|
|
39
|
-
|
|
57
|
+
var _a, _b;
|
|
58
|
+
const doc = Zotero.getMainWindow().document;
|
|
59
|
+
Zotero.debug(`debug-log-sender: removing .debug-log-sender[label=${JSON.stringify(plugin)}]: ${!!doc.querySelector(`.debug-log-sender[label=${JSON.stringify(plugin)}]`)}`);
|
|
60
|
+
(_a = doc.querySelector(`.debug-log-sender[label=${JSON.stringify(plugin)}]`)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
61
|
+
const menupopup = doc.querySelector('#debug-log-sender-menupopup');
|
|
62
|
+
Zotero.debug(`debug-log-sender: removing #debug-log-sender-menupopup: ${menupopup && menupopup.children.length}`);
|
|
63
|
+
if (menupopup && !menupopup.children.length)
|
|
64
|
+
(_b = doc.querySelector('#debug-log-sender-menu')) === null || _b === void 0 ? void 0 : _b.remove();
|
|
40
65
|
}
|
|
41
66
|
alert(title, body) {
|
|
42
67
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
@@ -44,48 +69,38 @@ class DebugLogSender {
|
|
|
44
69
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
45
70
|
ps.alert(null, title, body);
|
|
46
71
|
}
|
|
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) => {
|
|
72
|
+
send(target) {
|
|
73
|
+
const elt = target;
|
|
74
|
+
const plugin = elt.getAttribute('label');
|
|
75
|
+
const preferences = JSON.parse(elt.getAttribute('data-preferences'));
|
|
76
|
+
this.sendAsync(plugin, preferences).catch((err) => {
|
|
61
77
|
this.alert('Debug log submission error', `${err}`); // eslint-disable-line @typescript-eslint/restrict-template-expressions
|
|
62
78
|
});
|
|
63
79
|
}
|
|
64
|
-
async sendAsync() {
|
|
80
|
+
async sendAsync(plugin, preferences) {
|
|
65
81
|
await Zotero.Schema.schemaUpdatePromise;
|
|
66
|
-
const plugin = this.select();
|
|
67
82
|
const tape = new tar_js_1.default;
|
|
68
83
|
let out;
|
|
69
84
|
const key = Zotero.Utilities.generateObjectKey();
|
|
70
85
|
const log = [
|
|
71
|
-
await this.info(
|
|
86
|
+
await this.info(preferences),
|
|
72
87
|
Zotero.getErrors(true).join('\n\n'),
|
|
73
88
|
Zotero.Debug.getConsoleViewerOutput().slice(-250000).join('\n'), // eslint-disable-line no-magic-numbers
|
|
74
89
|
].filter((txt) => txt).join('\n\n').trim();
|
|
75
|
-
out = tape.append(`${key}
|
|
90
|
+
out = tape.append(`${key}/debug.txt`, log);
|
|
76
91
|
const rdf = await this.rdf();
|
|
77
92
|
if (rdf)
|
|
78
|
-
out = tape.append(`${key}
|
|
93
|
+
out = tape.append(`${key}/items.rdf`, rdf);
|
|
79
94
|
const blob = new Blob([(0, pako_1.gzip)(out)], { type: 'application/zip' });
|
|
80
95
|
const formData = new FormData();
|
|
81
96
|
formData.append('file', blob, `${key}.tgz`);
|
|
82
97
|
const response = await this.post('https://file.io', formData);
|
|
83
98
|
this.alert(`Debug log ID for ${plugin}`, `${response.key}-${key}`);
|
|
84
99
|
}
|
|
85
|
-
preferences(
|
|
100
|
+
preferences(preferences) {
|
|
86
101
|
const prefs = {};
|
|
87
102
|
const names = [];
|
|
88
|
-
for (const pref of
|
|
103
|
+
for (const pref of preferences) {
|
|
89
104
|
if (pref.endsWith('.')) {
|
|
90
105
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
91
106
|
const childkeys = Services.prefs.getBranch(pref).getChildList('', {});
|
|
@@ -107,7 +122,7 @@ class DebugLogSender {
|
|
|
107
122
|
return (await response.json());
|
|
108
123
|
}
|
|
109
124
|
// general state of Zotero
|
|
110
|
-
async info(
|
|
125
|
+
async info(preferences) {
|
|
111
126
|
let info = '';
|
|
112
127
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
|
113
128
|
const appInfo = Components.classes['@mozilla.org/xre/app-info;1'].getService(Components.interfaces.nsIXULAppInfo);
|
|
@@ -117,17 +132,19 @@ class DebugLogSender {
|
|
|
117
132
|
if (addons.length) {
|
|
118
133
|
info += 'Addons:\n' + addons.map((addon) => ` ${addon}\n`).join(''); // eslint-disable-line prefer-template
|
|
119
134
|
}
|
|
120
|
-
for (const [pref, value] of Object.entries(this.preferences(
|
|
135
|
+
for (const [pref, value] of Object.entries(this.preferences(preferences))) {
|
|
121
136
|
info += `${pref} = ${JSON.stringify(value)}\n`;
|
|
122
137
|
}
|
|
123
138
|
return info;
|
|
124
139
|
}
|
|
125
140
|
rdf() {
|
|
126
141
|
return new Promise((resolve, reject) => {
|
|
127
|
-
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
|
143
|
+
const items = Zotero.getActiveZoteroPane().getSelectedItems();
|
|
128
144
|
if (items.length === 0)
|
|
129
145
|
return resolve('');
|
|
130
|
-
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
147
|
+
const translation = new Zotero.Translate.Export();
|
|
131
148
|
translation.setItems(items);
|
|
132
149
|
translation.setTranslator('14763d24-8ba0-45df-8f52-b8d1108e7ac9'); // rdf
|
|
133
150
|
translation.setHandler('done', (obj, success) => {
|
|
@@ -142,5 +159,4 @@ class DebugLogSender {
|
|
|
142
159
|
});
|
|
143
160
|
}
|
|
144
161
|
}
|
|
145
|
-
|
|
146
|
-
exports.DebugLog = Zotero.DebugLogSender;
|
|
162
|
+
exports.DebugLog = new DebugLogSender;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zotero-plugin",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "Zotero plugin builder",
|
|
5
5
|
"homepage": "https://github.com/retorquere/zotero-plugin/wiki",
|
|
6
6
|
"bin": {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"postversion": "git push --follow-tags",
|
|
20
20
|
"test": "eslint . --ext .ts && npm run build",
|
|
21
21
|
"build": "tsc && chmod +x bin/*.js",
|
|
22
|
+
"pack": "npm test && npm pack",
|
|
22
23
|
"prepublishOnly": "npm install && npm run build",
|
|
23
24
|
"ncu": "ncu -u && npm i && git add package.json package-lock.json && git commit -m ncu"
|
|
24
25
|
},
|