aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/common/extension-content-controller.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-11-27 12:48:14 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-11-27 12:48:14 -0500
commit4da4827bcbcdd1ef163f635d9b29416ff272b0bb (patch)
treea8a0f1a8befdb78a554e1be91f2c6059ca3ad5f9 /ext/js/pages/common/extension-content-controller.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
Add JSDoc type annotations to project (rebased)
Diffstat (limited to 'ext/js/pages/common/extension-content-controller.js')
-rw-r--r--ext/js/pages/common/extension-content-controller.js32
1 files changed, 28 insertions, 4 deletions
diff --git a/ext/js/pages/common/extension-content-controller.js b/ext/js/pages/common/extension-content-controller.js
index 3792130c..1c3f9c74 100644
--- a/ext/js/pages/common/extension-content-controller.js
+++ b/ext/js/pages/common/extension-content-controller.js
@@ -19,6 +19,7 @@
import {Environment} from '../../extension/environment.js';
export class ExtensionContentController {
+ /** */
prepare() {
this._prepareSpecialUrls();
this._prepareExtensionIdExamples();
@@ -27,6 +28,7 @@ export class ExtensionContentController {
// Private
+ /** */
async _prepareEnvironmentInfo() {
const {dataset} = document.documentElement;
const {manifest_version: manifestVersion} = chrome.runtime.getManifest();
@@ -40,6 +42,7 @@ export class ExtensionContentController {
dataset.os = platform.os;
}
+ /** */
_prepareExtensionIdExamples() {
const nodes = document.querySelectorAll('.extension-id-example');
let url = '';
@@ -53,8 +56,9 @@ export class ExtensionContentController {
}
}
+ /** */
_prepareSpecialUrls() {
- const nodes = document.querySelectorAll('[data-special-url]');
+ const nodes = /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('[data-special-url]'));
if (nodes.length === 0) { return; }
let extensionId = '';
@@ -77,16 +81,27 @@ export class ExtensionContentController {
}
}
+ /**
+ * @param {MouseEvent} e
+ */
_onSpecialUrlLinkClick(e) {
switch (e.button) {
case 0:
case 1:
- e.preventDefault();
- this._createTab(e.currentTarget.dataset.specialUrl, true);
+ {
+ const element = /** @type {HTMLElement} */ (e.currentTarget);
+ const {specialUrl} = element.dataset;
+ if (typeof specialUrl !== 'string') { return; }
+ e.preventDefault();
+ this._createTab(specialUrl, true);
+ }
break;
}
}
+ /**
+ * @param {MouseEvent} e
+ */
_onSpecialUrlLinkMouseDown(e) {
switch (e.button) {
case 0:
@@ -96,10 +111,17 @@ export class ExtensionContentController {
}
}
+ /**
+ * @param {string} url
+ * @param {boolean} useOpener
+ * @returns {Promise<chrome.tabs.Tab>}
+ */
async _createTab(url, useOpener) {
+ /** @type {number|undefined} */
let openerTabId;
if (useOpener) {
try {
+ /** @type {chrome.tabs.Tab|undefined} */
const tab = await new Promise((resolve, reject) => {
chrome.tabs.getCurrent((result) => {
const e = chrome.runtime.lastError;
@@ -110,7 +132,9 @@ export class ExtensionContentController {
}
});
});
- openerTabId = tab.id;
+ if (typeof tab !== 'undefined') {
+ openerTabId = tab.id;
+ }
} catch (e) {
// NOP
}