From 4da4827bcbcdd1ef163f635d9b29416ff272b0bb Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 27 Nov 2023 12:48:14 -0500 Subject: Add JSDoc type annotations to project (rebased) --- ext/js/pages/permissions-main.js | 41 +++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'ext/js/pages/permissions-main.js') diff --git a/ext/js/pages/permissions-main.js b/ext/js/pages/permissions-main.js index ff614880..064e9240 100644 --- a/ext/js/pages/permissions-main.js +++ b/ext/js/pages/permissions-main.js @@ -27,6 +27,9 @@ import {PersistentStorageController} from './settings/persistent-storage-control import {SettingsController} from './settings/settings-controller.js'; import {SettingsDisplayController} from './settings/settings-display-controller.js'; +/** + * @returns {Promise} + */ async function setupEnvironmentInfo() { const {manifest_version: manifestVersion} = chrome.runtime.getManifest(); const {browser, platform} = await yomitan.api.getEnvironmentInfo(); @@ -35,20 +38,39 @@ async function setupEnvironmentInfo() { document.documentElement.dataset.manifestVersion = `${manifestVersion}`; } +/** + * @returns {Promise} + */ async function isAllowedIncognitoAccess() { return await new Promise((resolve) => chrome.extension.isAllowedIncognitoAccess(resolve)); } +/** + * @returns {Promise} + */ async function isAllowedFileSchemeAccess() { return await new Promise((resolve) => chrome.extension.isAllowedFileSchemeAccess(resolve)); } +/** + * @returns {void} + */ function setupPermissionsToggles() { const manifest = chrome.runtime.getManifest(); - let optionalPermissions = manifest.optional_permissions; - if (!Array.isArray(optionalPermissions)) { optionalPermissions = []; } - optionalPermissions = new Set(optionalPermissions); + const optionalPermissions = manifest.optional_permissions; + /** @type {Set} */ + const optionalPermissionsSet = new Set(optionalPermissions); + if (Array.isArray(optionalPermissions)) { + for (const permission of optionalPermissions) { + optionalPermissionsSet.add(permission); + } + } + /** + * @param {Set} set + * @param {string[]} values + * @returns {boolean} + */ const hasAllPermisions = (set, values) => { for (const value of values) { if (!set.has(value)) { return false; } @@ -56,10 +78,10 @@ function setupPermissionsToggles() { return true; }; - for (const toggle of document.querySelectorAll('.permissions-toggle')) { - let permissions = toggle.dataset.requiredPermissions; - permissions = (typeof permissions === 'string' && permissions.length > 0 ? permissions.split(' ') : []); - toggle.disabled = !hasAllPermisions(optionalPermissions, permissions); + for (const toggle of /** @type {NodeListOf} */ (document.querySelectorAll('.permissions-toggle'))) { + const permissions = toggle.dataset.requiredPermissions; + const permissionsArray = (typeof permissions === 'string' && permissions.length > 0 ? permissions.split(' ') : []); + toggle.disabled = !hasAllPermisions(optionalPermissionsSet, permissionsArray); } } @@ -77,9 +99,10 @@ function setupPermissionsToggles() { setupEnvironmentInfo(); + /** @type {[HTMLInputElement, HTMLInputElement]} */ const permissionsCheckboxes = [ - document.querySelector('#permission-checkbox-allow-in-private-windows'), - document.querySelector('#permission-checkbox-allow-file-url-access') + /** @type {HTMLInputElement} */ (document.querySelector('#permission-checkbox-allow-in-private-windows')), + /** @type {HTMLInputElement} */ (document.querySelector('#permission-checkbox-allow-file-url-access')) ]; const permissions = await Promise.all([ -- cgit v1.2.3