summaryrefslogtreecommitdiff
path: root/ext/js/pages/permissions-main.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/permissions-main.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
parent23e6fb76319c9ed7c9bcdc3efba39bc5dd38f288 (diff)
Merge pull request #339 from toasted-nutbread/type-annotations
Type annotations
Diffstat (limited to 'ext/js/pages/permissions-main.js')
-rw-r--r--ext/js/pages/permissions-main.js41
1 files changed, 32 insertions, 9 deletions
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<void>}
+ */
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<boolean>}
+ */
async function isAllowedIncognitoAccess() {
return await new Promise((resolve) => chrome.extension.isAllowedIncognitoAccess(resolve));
}
+/**
+ * @returns {Promise<boolean>}
+ */
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<string>} */
+ const optionalPermissionsSet = new Set(optionalPermissions);
+ if (Array.isArray(optionalPermissions)) {
+ for (const permission of optionalPermissions) {
+ optionalPermissionsSet.add(permission);
+ }
+ }
+ /**
+ * @param {Set<string>} 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<HTMLInputElement>} */ (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([