zotero-plugin 2.0.25 → 2.0.26

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.
Files changed (2) hide show
  1. package/debug-log.js +31 -25
  2. package/package.json +1 -1
package/debug-log.js CHANGED
@@ -14,15 +14,17 @@ class DebugLogSender {
14
14
  this.debugEnabledAtStart = Zotero ? (Zotero.Prefs.get('debug.store') || Zotero.Debug.enabled) : null;
15
15
  }
16
16
  convertLegacy() {
17
- var _a;
17
+ var _a, _b;
18
18
  if (!Zotero.DebugLogSender)
19
19
  return;
20
20
  const plugins = Zotero.DebugLogSender.plugins || {};
21
21
  delete Zotero.DebugLogSender;
22
- const doc = Zotero.getMainWindow().document;
23
- (_a = doc.querySelector('menuitem#debug-log-menu')) === null || _a === void 0 ? void 0 : _a.remove();
24
- for (const [plugin, preferences] of Object.entries(plugins)) {
25
- this.register(plugin, preferences);
22
+ const doc = (_a = Zotero.getMainWindow()) === null || _a === void 0 ? void 0 : _a.document;
23
+ if (doc) {
24
+ (_b = doc.querySelector('menuitem#debug-log-menu')) === null || _b === void 0 ? void 0 : _b.remove();
25
+ for (const [plugin, preferences] of Object.entries(plugins)) {
26
+ this.register(plugin, preferences);
27
+ }
26
28
  }
27
29
  }
28
30
  element(name, attrs = {}) {
@@ -35,30 +37,34 @@ class DebugLogSender {
35
37
  return elt;
36
38
  }
37
39
  register(plugin, preferences = []) {
38
- var _a;
40
+ var _a, _b;
39
41
  this.convertLegacy();
40
- const doc = Zotero.getMainWindow().document;
41
- let menupopup = doc.querySelector(`#${this.id.menupopup}`);
42
- if (!menupopup) {
43
- menupopup = doc.querySelector('menupopup#menu_HelpPopup')
44
- .appendChild(this.element('menu', { id: this.id.menu, label: 'Send debug log to file.io' }))
45
- .appendChild(this.element('menupopup', { id: this.id.menupopup }));
42
+ const doc = (_a = Zotero.getMainWindow()) === null || _a === void 0 ? void 0 : _a.document;
43
+ if (doc) {
44
+ let menupopup = doc.querySelector(`#${this.id.menupopup}`);
45
+ if (!menupopup) {
46
+ menupopup = doc.querySelector('menupopup#menu_HelpPopup')
47
+ .appendChild(this.element('menu', { id: this.id.menu, label: 'Send debug log to file.io' }))
48
+ .appendChild(this.element('menupopup', { id: this.id.menupopup }));
49
+ }
50
+ (_b = doc.querySelector(`.${this.id.menuitem}[label=${JSON.stringify(plugin)}]`)) === null || _b === void 0 ? void 0 : _b.remove();
51
+ const menuitem = menupopup.appendChild(this.element('menuitem', {
52
+ label: plugin,
53
+ class: this.id.menuitem,
54
+ 'data-preferences': JSON.stringify(preferences || []),
55
+ }));
56
+ menuitem.addEventListener('command', event => this.send(event.currentTarget));
46
57
  }
47
- (_a = doc.querySelector(`.${this.id.menuitem}[label=${JSON.stringify(plugin)}]`)) === null || _a === void 0 ? void 0 : _a.remove();
48
- const menuitem = menupopup.appendChild(this.element('menuitem', {
49
- label: plugin,
50
- class: this.id.menuitem,
51
- 'data-preferences': JSON.stringify(preferences || []),
52
- }));
53
- menuitem.addEventListener('command', event => this.send(event.currentTarget));
54
58
  }
55
59
  unregister(plugin) {
56
- var _a, _b;
57
- const doc = Zotero.getMainWindow().document;
58
- (_a = doc.querySelector(`.debug-log-sender[label=${JSON.stringify(plugin)}]`)) === null || _a === void 0 ? void 0 : _a.remove();
59
- const menupopup = doc.querySelector('#debug-log-sender-menupopup');
60
- if (menupopup && !menupopup.children.length)
61
- (_b = doc.querySelector('#debug-log-sender-menu')) === null || _b === void 0 ? void 0 : _b.remove();
60
+ var _a, _b, _c;
61
+ const doc = (_a = Zotero.getMainWindow()) === null || _a === void 0 ? void 0 : _a.document;
62
+ if (doc) {
63
+ (_b = doc.querySelector(`.debug-log-sender[label=${JSON.stringify(plugin)}]`)) === null || _b === void 0 ? void 0 : _b.remove();
64
+ const menupopup = doc.querySelector('#debug-log-sender-menupopup');
65
+ if (menupopup && !menupopup.children.length)
66
+ (_c = doc.querySelector('#debug-log-sender-menu')) === null || _c === void 0 ? void 0 : _c.remove();
67
+ }
62
68
  }
63
69
  alert(title, body) {
64
70
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zotero-plugin",
3
- "version": "2.0.25",
3
+ "version": "2.0.26",
4
4
  "description": "Zotero plugin builder",
5
5
  "homepage": "https://github.com/retorquere/zotero-plugin/wiki",
6
6
  "bin": {