summaryrefslogtreecommitdiff
path: root/ext/js/pages/common/extension-content-controller.js
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-12-06 03:53:16 +0000
committerGitHub <noreply@github.com>2023-12-06 03:53:16 +0000
commitbd5bc1a5db29903bc098995cd9262c4576bf76af (patch)
treec9214189e0214480fcf6539ad1c6327aef6cbd1c /ext/js/pages/common/extension-content-controller.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
parent23e6fb76319c9ed7c9bcdc3efba39bc5dd38f288 (diff)
Merge pull request #339 from toasted-nutbread/type-annotations
Type annotations
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
}