From 2325d1bd4ad60559e056a4e54f18f71c533e1aab Mon Sep 17 00:00:00 2001 From: Teal Dulcet Date: Tue, 1 Aug 2023 02:11:02 -0700 Subject: [PATCH 1/3] ESLint fixes. --- src/background/modules/InstallUpgrade.js | 15 ++------------- src/background/modules/OmniboxSearch.js | 10 +++++----- src/common/modules/BrowserCompat.js | 6 ++---- src/common/modules/EmojiInteraction.js | 8 ++++---- src/common/modules/IconHandler.js | 17 ++++++++--------- src/common/modules/LanguageHelper.js | 10 +++++----- src/common/modules/data/MessageLevel.js | 10 +++++----- src/common/modules/data/Tips.js | 10 ++++++---- src/content_scripts/insertIntoPage.js | 2 +- src/options/modules/CustomOptionTriggers.js | 21 +++++---------------- src/options/modules/ManualAdjustments.js | 2 +- src/popup/index.js | 8 ++++---- src/popup/module/ConfirmationHint.js | 2 +- src/popup/module/EmojiPicker.js | 8 ++++---- src/popup/module/EmojiSelect.js | 2 +- 15 files changed, 54 insertions(+), 77 deletions(-) diff --git a/src/background/modules/InstallUpgrade.js b/src/background/modules/InstallUpgrade.js index cd6ee1e..3924f13 100644 --- a/src/background/modules/InstallUpgrade.js +++ b/src/background/modules/InstallUpgrade.js @@ -29,7 +29,7 @@ async function upgradeEmojiSet(emojiPickerSettings) { // eslint-disable-next-line no-case-declarations const text = "No emoji set upgrade needed."; console.log(text); - return Promise.reject(new Error(text)); + throw new Error(text); } console.log("Doing emoji set upgrade."); @@ -38,7 +38,6 @@ async function upgradeEmojiSet(emojiPickerSettings) { }); console.info("Emoji set upgrade successful.", await browser.storage.sync.get()); - return Promise.resolve(); } /** @@ -62,14 +61,4 @@ async function handleInstalled(details) { upgradeEmojiSet(oldData.emojiPicker).catch(() => {}); } -/** - * Inits module. - * - * @private - * @returns {void} - */ -function init() { - browser.runtime.onInstalled.addListener(handleInstalled); -} - -init(); +browser.runtime.onInstalled.addListener(handleInstalled); diff --git a/src/background/modules/OmniboxSearch.js b/src/background/modules/OmniboxSearch.js index 29e666b..065d5d1 100644 --- a/src/background/modules/OmniboxSearch.js +++ b/src/background/modules/OmniboxSearch.js @@ -27,7 +27,7 @@ function loadEmojiMart() { const emojiMartLoader = document.createElement("script"); emojiMartLoader.setAttribute("async", true); emojiMartLoader.setAttribute("src", "/common/lib/emoji-mart-embed/dist/emoji-mart.js"); - document.querySelector("head").appendChild(emojiMartLoader); + document.querySelector("head").append(emojiMartLoader); emojiMartIsLoaded = true; } @@ -105,7 +105,7 @@ export function triggerOmnixboxSuggestion(text, suggest) { export async function triggerOmnixboxDisabledSearch(text, disposition) { // if search API is allowed, we just fall-back to default search if (browser.search) { - let tabId = undefined; + let tabId; switch (disposition) { case "currentTab": { @@ -154,7 +154,7 @@ export async function triggerOmnixboxSearch(text, disposition) { if (foundEmoji) { searchResult.push(foundEmoji); } - } catch (e) { + } catch { // ignore errors, as we usually expect text strings there and these are // totally fine, too; search may find something here } @@ -171,7 +171,7 @@ export async function triggerOmnixboxSearch(text, disposition) { copyToClipboard: true }); } else if (emojiSearch.action === "emojipedia") { - const resultUrl = `https://emojipedia.org/search/?q=${emojiText}`; + const resultUrl = `https://emojipedia.org/search/?q=${encodeURIComponent(emojiText)}`; // navigate to URL in current or new tab openTabUrl(resultUrl, disposition); @@ -187,7 +187,7 @@ export async function triggerOmnixboxSearch(text, disposition) { // browser.browserAction.openPopup(); // search for result in emojipedia - const resultUrl = `https://emojipedia.org/search/?q=${text}`; + const resultUrl = `https://emojipedia.org/search/?q=${encodeURIComponent(text)}`; openTabUrl(resultUrl, disposition); } } diff --git a/src/common/modules/BrowserCompat.js b/src/common/modules/BrowserCompat.js index 09016c8..2db9967 100644 --- a/src/common/modules/BrowserCompat.js +++ b/src/common/modules/BrowserCompat.js @@ -18,10 +18,8 @@ export async function getBrowserValue(switchBrowser) { if (browserInfo.name === "Thunderbird") { return switchBrowser.thunderbird; - } else { - return switchBrowser.firefox; } - } else { - return switchBrowser.chrome; + return switchBrowser.firefox; } + return switchBrowser.chrome; } diff --git a/src/common/modules/EmojiInteraction.js b/src/common/modules/EmojiInteraction.js index f0822af..fc0733d 100644 --- a/src/common/modules/EmojiInteraction.js +++ b/src/common/modules/EmojiInteraction.js @@ -16,7 +16,7 @@ export async function insertOrCopy(text, options) { // destructure config const { insertIntoPage, - copyOnlyOnFallback, + copyOnlyOnFallback } = options; let copyToClipboard = options.copyToClipboard; @@ -30,12 +30,12 @@ export async function insertOrCopy(text, options) { // wait for successful execution, if wanted if (insertIntoPage && copyOnlyOnFallback) { - await (emojiInsertResult.then(() => { + await emojiInsertResult.then(() => { // if successful, do not copy emoji copyToClipboard = false; - })).catch((e) => { + }).catch((error) => { // log error just as a warning, as we expect copying can fail - console.warn(e); + console.warn(error); // but resolve promise, so await/fallback continues }); } diff --git a/src/common/modules/IconHandler.js b/src/common/modules/IconHandler.js index 3e36d2c..a2fe01b 100644 --- a/src/common/modules/IconHandler.js +++ b/src/common/modules/IconHandler.js @@ -26,11 +26,11 @@ function setPopupIcon(icon) { const browserAction = typeof messenger !== "undefined" ? browser.composeAction : browser.browserAction; // ignore request if API is not available - if (browserAction.setIcon === undefined) { + if (!browserAction.setIcon) { return Promise.resolve(); } - if (icon === null || icon === undefined) { + if (icon == null) { return browserAction.setIcon({path: null}); } @@ -38,10 +38,10 @@ function setPopupIcon(icon) { if (icon === "colored") { // WTF: For whatever reason, these paths need to be absolute... return browserAction.setIcon({path: { - "16": "/icons/icon_32.png", - "32": "/icons/icon_32.png", - "64": "/icons/icon_64.png", - "128": "/icons/icon_128.png" + 16: "/icons/icon_32.png", + 32: "/icons/icon_32.png", + 64: "/icons/icon_64.png", + 128: "/icons/icon_128.png" }}); } @@ -58,10 +58,9 @@ function setPopupIcon(icon) { export function changeIconIfColored(popupIconColored) { if (popupIconColored === true) { return setPopupIcon("colored"); - } else { - // reset icon - return setPopupIcon(null); } + // reset icon + return setPopupIcon(null); } /** diff --git a/src/common/modules/LanguageHelper.js b/src/common/modules/LanguageHelper.js index 90c173a..3315023 100644 --- a/src/common/modules/LanguageHelper.js +++ b/src/common/modules/LanguageHelper.js @@ -18,7 +18,7 @@ * @private * @type {string[]} */ -const ADDON_TRANSLATED_INTO = [ +const ADDON_TRANSLATED_INTO = new Set([ // German "de", "de-DE", // Hebrew @@ -26,8 +26,8 @@ const ADDON_TRANSLATED_INTO = [ // English "en", "en-US", // French - "fr", "fr-FR", -].map((lang) => lang.toLowerCase()); + "fr", "fr-FR" +].map((lang) => lang.toLowerCase())); /** * Returns whether the user also speaks a language that the add-on is not @@ -41,12 +41,12 @@ export async function userSpeaksLocaleNotYetTranslated() { const uiLanguage = browser.i18n.getUILanguage(); const acceptedLanguages = await browser.i18n.getAcceptLanguages(); - console.log("Addon is translated into", addonLanguage, ", browser into ", uiLanguage, "and user accepts the languages", acceptedLanguages, "."); + console.log("Addon is translated into", addonLanguage, ", browser into", uiLanguage, "and user accepts the languages", acceptedLanguages, "."); // Note: actually addonLanguage and uiLanguage should be the same, see https://discourse.mozilla.org/t/not-clear-that-there-are-three-locales/27533 // for evaluation, we can assume the user also speaks the language their browser is translated into acceptedLanguages.push(uiLanguage); // if the language the user speaks is not already translated, they probably know another locale we do not know yet - return acceptedLanguages.some((userLang) => ! ADDON_TRANSLATED_INTO.includes(userLang.toLowerCase())); + return acceptedLanguages.some((userLang) => !ADDON_TRANSLATED_INTO.has(userLang.toLowerCase())); } diff --git a/src/common/modules/data/MessageLevel.js b/src/common/modules/data/MessageLevel.js index 415ee40..ddcfe23 100644 --- a/src/common/modules/data/MessageLevel.js +++ b/src/common/modules/data/MessageLevel.js @@ -12,9 +12,9 @@ * @default */ export const MESSAGE_LEVEL = Object.freeze({ - "ERROR": 3, - "WARN": 2, - "INFO": 1, - "LOADING": -2, - "SUCCESS": -3 + ERROR: 3, + WARN: 2, + INFO: 1, + LOADING: -2, + SUCCESS: -3 }); diff --git a/src/common/modules/data/Tips.js b/src/common/modules/data/Tips.js index 9d517cf..da6e5c1 100644 --- a/src/common/modules/data/Tips.js +++ b/src/common/modules/data/Tips.js @@ -99,7 +99,7 @@ const tipArray = [ maximumDismiss: 2, requiredTriggers: 10, showInContext: { - "popup": 1 + popup: 1 }, randomizeDisplay: false, text: "tipYouLikeAddon", @@ -156,13 +156,13 @@ const tipArray = [ showTip: async (tipSpec) => { // do not show tip if add-on is already translated into a locale the // user speaks - if (!(await userSpeaksLocaleNotYetTranslated())) { + if (!await userSpeaksLocaleNotYetTranslated()) { // Instead of returning false, we "just" make it unlikely that // the tip is shown. // This means we can be sure the tip is shown anyway to some // users, who may speak a language we already have the add-on // translated into it, as they can still improve translations etc. - tipSpec.randomizeDisplay = 0.10; // 10% + tipSpec.randomizeDisplay = 0.1; // 10% return null; } @@ -173,7 +173,9 @@ const tipArray = [ ]; // freeze it all, this is strongly recommend -tipArray.forEach((object) => Object.freeze(object)); +for (const object of tipArray) { + Object.freeze(object); +} /** * The list of all tips. (now exported) diff --git a/src/content_scripts/insertIntoPage.js b/src/content_scripts/insertIntoPage.js index 10218ac..e251a0f 100644 --- a/src/content_scripts/insertIntoPage.js +++ b/src/content_scripts/insertIntoPage.js @@ -19,7 +19,7 @@ function insertIntoPage(newText) { // eslint-disable-line no-unused-vars const start = elFocused.selectionStart; const end = elFocused.selectionEnd; - if (start !== undefined && end !== undefined) { + if (start != null && end != null) { elFocused.setRangeText(newText, start, end, "end"); return elFocused.value; } diff --git a/src/options/modules/CustomOptionTriggers.js b/src/options/modules/CustomOptionTriggers.js index b315434..129b613 100644 --- a/src/options/modules/CustomOptionTriggers.js +++ b/src/options/modules/CustomOptionTriggers.js @@ -43,11 +43,7 @@ function applyPopupIconColor(optionValue) { * @returns {Promise} */ function saveEmojiSet(param) { - if (param.optionValue.set === "native") { - param.optionValue.native = true; - } else { - param.optionValue.native = false; - } + param.optionValue.native = param.optionValue.set === "native"; return AutomaticSettings.Trigger.overrideContinue(param.optionValue); } @@ -151,11 +147,7 @@ function preparePickerResultTypeOptionForInput(param) { * @returns {Promise} */ function adjustPickerResultTypeOption(param) { - if (param.optionValue.resultType) { - param.optionValue.resultType = "colons"; - } else { - param.optionValue.resultType = "native"; - } + param.optionValue.resultType = param.optionValue.resultType ? "colons" : "native"; return AutomaticSettings.Trigger.overrideContinue(param.optionValue); } @@ -169,11 +161,9 @@ function adjustPickerResultTypeOption(param) { * @returns {string} messageName */ function getPluralForm(language, optionValue) { - if (!language) { - language = "en"; - } + language ||= "en"; - switch(language) { + switch (language) { case "tr": return optionValue > 1 ? "optionEmojisPerLineStatusPlural" : "optionEmojisPerLineStatusSingular"; // en, de @@ -329,9 +319,8 @@ function applyEmojiSearch(optionValue, option, event = {}) { // So this is equivalent to a "then". reloadEmojiSearchStatus(); }); - } else { - PermissionRequest.cancelPermissionPrompt(CLIPBOARD_WRITE_PERMISSION, MESSAGE_EMOJI_COPY_PERMISSION_SEARCH); } + PermissionRequest.cancelPermissionPrompt(CLIPBOARD_WRITE_PERMISSION, MESSAGE_EMOJI_COPY_PERMISSION_SEARCH); return Promise.resolve(); } diff --git a/src/options/modules/ManualAdjustments.js b/src/options/modules/ManualAdjustments.js index 086b864..0bb2144 100644 --- a/src/options/modules/ManualAdjustments.js +++ b/src/options/modules/ManualAdjustments.js @@ -11,7 +11,7 @@ export function init() { getBrowserValue({ firefox: "https://addons.mozilla.org/firefox/addon/unicodify-text-transformer/?utm_source=awesomeEmojiPicker-addon&utm_medium=addon&utm_content=awesomeEmojiPicker-addon-settings-inline&utm_campaign=awesomeEmojiPicker-addon-settings-inline", thunderbird: "https://addons.thunderbird.net/thunderbird/addon/unicodify-text-transformer/?utm_source=awesomeEmojiPicker-addon&utm_medium=addon&utm_content=awesomeEmojiPicker-addon-settings-inline&utm_campaign=awesomeEmojiPicker-addon-settings-inline", - chrome: "https://chrome.google.com/webstore/detail/unicodify-text-transformer/?utm_source=awesomeEmojiPicker-addon&utm_medium=addon&utm_content=awesomeEmojiPicker-addon-settings-inline&utm_campaign=awesomeEmojiPicker-addon-settings-inline", + chrome: "https://chrome.google.com/webstore/detail/unicodify-text-transformer/?utm_source=awesomeEmojiPicker-addon&utm_medium=addon&utm_content=awesomeEmojiPicker-addon-settings-inline&utm_campaign=awesomeEmojiPicker-addon-settings-inline" }).then((browserUrl) => { // Uncomment this line after https://github.com/rugk/awesome-emoji-picker/pull/93 is merged. // document.getElementById("link-unicodify").href = browserUrl; diff --git a/src/popup/index.js b/src/popup/index.js index ee3071e..ef35f11 100644 --- a/src/popup/index.js +++ b/src/popup/index.js @@ -55,7 +55,7 @@ export async function focusElement(element, retries = 20, delay = 50) { // if element is focussed, we are lucky if (document.activeElement === element) { console.log(element, "focussed with", retries, "retries left, at delay", delay); - return Promise.resolve(); + return; } if (retries <= 0) { @@ -81,12 +81,12 @@ createPicker().then(async () => { const popupType = EnvironmentDetector.getPopupType(); if (popupType === EnvironmentDetector.POPUP_TYPE.OVERFLOW || - popupType === EnvironmentDetector.POPUP_TYPE.NEW_PAGE ) { + popupType === EnvironmentDetector.POPUP_TYPE.NEW_PAGE) { // prevent overflow and stretch GUI (even if it is a up to 20% underflow) if (EnvironmentDetector.getOverflowInPercentage(EnvironmentDetector.SIZE.WIDTH) > -20) { // make popup smaller, so it fits - document.querySelector(".emoji-mart").style.width = `${window.innerWidth-20}px`; - document.querySelector(".emoji-mart").style.height = `${window.innerHeight+20}px`; + document.querySelector(".emoji-mart").style.width = `${window.innerWidth - 20}px`; + document.querySelector(".emoji-mart").style.height = `${window.innerHeight + 20}px`; setTimeout(() => { document.querySelector(".emoji-mart").style.width = "100vw"; diff --git a/src/popup/module/ConfirmationHint.js b/src/popup/module/ConfirmationHint.js index b4a9c18..036c9dc 100644 --- a/src/popup/module/ConfirmationHint.js +++ b/src/popup/module/ConfirmationHint.js @@ -157,7 +157,7 @@ export function show(position, messageId, options = {}) { // (needs to be done before showing the popup, as we need to get the browser // to calculate the size of it) elPanel = document.importNode(elTemplate.content, true).getElementById("confirmation-hint"); - document.body.appendChild(elPanel); + document.body.append(elPanel); const elAnimationBox = elPanel.querySelector("#confirmation-hint-checkmark-animation-container"); // show popup diff --git a/src/popup/module/EmojiPicker.js b/src/popup/module/EmojiPicker.js index 94f4af9..3d03601 100644 --- a/src/popup/module/EmojiPicker.js +++ b/src/popup/module/EmojiPicker.js @@ -22,7 +22,7 @@ export const hardcodedSettings = Object.freeze({ autoFocus: true, onSelect: EmojiSelect.triggerOnSelect, onClick: EmojiSelect.saveClickPosition, - style: { "border": "none" }, + style: { border: "none" }, theme: "auto", backgroundImageFn: getEmojiSheet, title: browser.i18n.getMessage("extensionNameShort"), // show the extension name by default @@ -53,7 +53,7 @@ function getEmojiMartLocalised() { objects: browser.i18n.getMessage("emojiMartCategoryObjects"), symbols: browser.i18n.getMessage("emojiMartCategorySymbols"), flags: browser.i18n.getMessage("emojiMartCategoryFlags"), - custom: browser.i18n.getMessage("emojiMartCategoryCustom"), + custom: browser.i18n.getMessage("emojiMartCategoryCustom") }, categorieslabel: browser.i18n.getMessage("emojiMartCategoriesLabel"), // Accessible title for the list of categories skintones: { @@ -62,7 +62,7 @@ function getEmojiMartLocalised() { 3: browser.i18n.getMessage("emojiMartSkintone3"), 4: browser.i18n.getMessage("emojiMartSkintone4"), 5: browser.i18n.getMessage("emojiMartSkintone5"), - 6: browser.i18n.getMessage("emojiMartSkintone6"), + 6: browser.i18n.getMessage("emojiMartSkintone6") } }; } @@ -111,6 +111,6 @@ export function init(settings) { return promiseCreateElement.then(() => { emojiPicker = document.createElement("emoji-picker"); - document.body.appendChild(emojiPicker); + document.body.append(emojiPicker); }); } diff --git a/src/popup/module/EmojiSelect.js b/src/popup/module/EmojiSelect.js index ef07f32..4a21991 100644 --- a/src/popup/module/EmojiSelect.js +++ b/src/popup/module/EmojiSelect.js @@ -99,7 +99,7 @@ export async function triggerOnSelect(emoji) { if (lastClick.forEmoji === emoji) { clickedEmoji = { left: lastClick.posX, - top: lastClick.posY, + top: lastClick.posY }; } From f8346c0edb9070bac7f7f03795a16a25e9ab3a57 Mon Sep 17 00:00:00 2001 From: Teal Dulcet Date: Tue, 1 Aug 2023 02:16:38 -0700 Subject: [PATCH 2/3] Enabled TypeScript Compiler and made fixes. --- jsconfig.json | 9 ++++++++- src/background/modules/InstallUpgrade.js | 4 ++-- src/background/modules/OmniboxSearch.js | 6 +++--- src/common/modules/BrowserCompat.js | 2 +- src/common/modules/EmojiInteraction.js | 2 +- src/common/modules/IconHandler.js | 2 +- src/common/modules/LanguageHelper.js | 2 +- src/common/modules/MobileHelper.js | 2 +- src/common/modules/PageHandler.js | 2 +- src/common/modules/data/MessageLevel.js | 2 +- src/common/modules/data/Tips.js | 20 ++++++++++---------- src/options/modules/ColorSchemeModeHelper.js | 2 +- src/options/modules/CustomOptionTriggers.js | 6 +++--- src/options/modules/ManualAdjustments.js | 2 +- src/popup/module/ConfirmationHint.js | 2 +- src/popup/module/EmojiSelect.js | 4 ++-- src/popup/module/EmojiSettings.js | 6 +++--- 17 files changed, 41 insertions(+), 34 deletions(-) diff --git a/jsconfig.json b/jsconfig.json index 75a3cfa..c37ec57 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -1,6 +1,13 @@ { "compilerOptions": { - "target": "ES6", + "target": "es2021", + "module": "es2021", + "checkJs": true, + "strict": true, + "noImplicitAny": false, + "forceConsistentCasingInFileNames": true, + "noUnusedLocals": true, + "noUnusedParameters": true, "baseUrl": "./src", "paths": { "/*": ["./*"], diff --git a/src/background/modules/InstallUpgrade.js b/src/background/modules/InstallUpgrade.js index 3924f13..2cf4a4a 100644 --- a/src/background/modules/InstallUpgrade.js +++ b/src/background/modules/InstallUpgrade.js @@ -12,7 +12,7 @@ * * @private * @param {Object} emojiPickerSettings - * @returns {Promise} + * @returns {Promise} */ async function upgradeEmojiSet(emojiPickerSettings) { // change removed emoji sets to best existing one @@ -46,7 +46,7 @@ async function upgradeEmojiSet(emojiPickerSettings) { * @see {@link https://developer.mozilla.org/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onInstalled} * @private * @param {Object} details - * @returns {Promise} + * @returns {Promise} */ async function handleInstalled(details) { // only trigger for usual addon updates diff --git a/src/background/modules/OmniboxSearch.js b/src/background/modules/OmniboxSearch.js index 065d5d1..6710d0d 100644 --- a/src/background/modules/OmniboxSearch.js +++ b/src/background/modules/OmniboxSearch.js @@ -138,7 +138,7 @@ export async function triggerOmnixboxDisabledSearch(text, disposition) { * @public * @param {string} text the string the user entered or selected * @param {string} disposition how the result should be possible - * @returns {void} + * @returns {Promise} * @see {@link https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/omnibox/onInputEntered} */ export async function triggerOmnixboxSearch(text, disposition) { @@ -197,7 +197,7 @@ export async function triggerOmnixboxSearch(text, disposition) { * * @private * @param {boolean} toEnable - * @returns {void} + * @returns {Promise} * @throws TypeError */ async function toggleEnabledStatus(toEnable) { @@ -207,7 +207,7 @@ async function toggleEnabledStatus(toEnable) { } // if we do not have the permission for clipboard, and need it for settings, force-disable feature - if (!(await browser.permissions.contains(CLIPBOARD_WRITE_PERMISSION))) { + if (!await browser.permissions.contains(CLIPBOARD_WRITE_PERMISSION)) { const emojiSearch = await AddonSettings.get("emojiSearch"); if (emojiSearch.action === "copy") { diff --git a/src/common/modules/BrowserCompat.js b/src/common/modules/BrowserCompat.js index 2db9967..23a785e 100644 --- a/src/common/modules/BrowserCompat.js +++ b/src/common/modules/BrowserCompat.js @@ -10,7 +10,7 @@ * * @private * @param {Object} switchBrowser an object with values to return per browser - * @returns {string} + * @returns {Promise} */ export async function getBrowserValue(switchBrowser) { if (browser.runtime.getBrowserInfo) { diff --git a/src/common/modules/EmojiInteraction.js b/src/common/modules/EmojiInteraction.js index fc0733d..b12387c 100644 --- a/src/common/modules/EmojiInteraction.js +++ b/src/common/modules/EmojiInteraction.js @@ -4,7 +4,7 @@ import * as PageHandler from "./PageHandler.js"; * As per users settings, insert emoji into web page or copy to clipboard. * * @private - * @param {Object} text + * @param {string} text * @param {Object} options * @param {boolean} options.insertIntoPage whether to try to insert it into the active page * @param {boolean} options.copyOnlyOnFallback whether to fallback to copying emojis (alos requires copyToClipboard=true) diff --git a/src/common/modules/IconHandler.js b/src/common/modules/IconHandler.js index a2fe01b..e8140e9 100644 --- a/src/common/modules/IconHandler.js +++ b/src/common/modules/IconHandler.js @@ -6,7 +6,7 @@ const POPUP_ICON_OPTION = "popupIconColored"; * Sets a popup icon variant. * * @private - * @param {string} icon version or "null"/"undefined" to reset to default + * @param {string|null} icon version or "null"/"undefined" to reset to default * @returns {Promise} */ function setPopupIcon(icon) { diff --git a/src/common/modules/LanguageHelper.js b/src/common/modules/LanguageHelper.js index 3315023..1a45091 100644 --- a/src/common/modules/LanguageHelper.js +++ b/src/common/modules/LanguageHelper.js @@ -34,7 +34,7 @@ const ADDON_TRANSLATED_INTO = new Set([ * translated into. * * @public - * @returns {boolean} + * @returns {Promise} */ export async function userSpeaksLocaleNotYetTranslated() { const addonLanguage = browser.i18n.getMessage("@@ui_locale"); diff --git a/src/common/modules/MobileHelper.js b/src/common/modules/MobileHelper.js index 78d1ff9..7f7089a 100644 --- a/src/common/modules/MobileHelper.js +++ b/src/common/modules/MobileHelper.js @@ -9,7 +9,7 @@ * Returns whether the current runtime is a mobile one (true) or not (false). * * @public - * @returns {Promise} with Boolean + * @returns {Promise} with Boolean */ export async function isMobile() { const platformInfo = await browser.runtime.getPlatformInfo(); diff --git a/src/common/modules/PageHandler.js b/src/common/modules/PageHandler.js index b426a40..dd9abd6 100644 --- a/src/common/modules/PageHandler.js +++ b/src/common/modules/PageHandler.js @@ -37,7 +37,7 @@ export async function insertIntoPage(text) { // send request to insert emoji // This will not work in Manifest V3: https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#executing-arbitrary-strings return browser.tabs.executeScript(tab.id, { - code: `insertIntoPage("${text}");`, + code: `insertIntoPage(${JSON.stringify(text)});`, allFrames: true, runAt: "document_end" }); diff --git a/src/common/modules/data/MessageLevel.js b/src/common/modules/data/MessageLevel.js index ddcfe23..fba01c3 100644 --- a/src/common/modules/data/MessageLevel.js +++ b/src/common/modules/data/MessageLevel.js @@ -8,7 +8,7 @@ * Specifies the message level to use, * * @readonly - * @enum {int} + * @enum {number} * @default */ export const MESSAGE_LEVEL = Object.freeze({ diff --git a/src/common/modules/data/Tips.js b/src/common/modules/data/Tips.js index da6e5c1..083af07 100644 --- a/src/common/modules/data/Tips.js +++ b/src/common/modules/data/Tips.js @@ -4,26 +4,26 @@ * @public * @typedef {Object} TipObject * @property {string} id just some ID - * @property {integer|null} requiredShowCount Shows the message x times; set + * @property {number|null} requiredShowCount Shows the message x times; set * to `null` to show infinitively. This is the maximum value. - * @property {bool} [allowDismiss=true] set to false to disallow dismissing + * @property {boolean} [allowDismiss=true] set to false to disallow dismissing * the message. This likely makes no sense for any tip, so the default is true. - * @property {bool|integer} [requireDismiss=false] show the message, if it is + * @property {boolean|number} [requireDismiss=false] show the message, if it is * not, at least, dismissed for x times. Alternatively set to true to require * that message is dismissed the exact same number as requiredShowCount states, * i.e. only dismissed count as "tip shown". - * @property {integer|null} [maximumDismiss=null] hides the message, if it + * @property {number|null} [maximumDismiss=null] hides the message, if it * has been dismissed x times. - * @property {integer} [requiredTriggers=10] require some displays ("triggers") + * @property {number} [requiredTriggers=10] require some displays ("triggers") * of (any) add-on page before showing tip. This is effectively just a minimum * limit, so it is not shown too "early". - * @property {Object.} [showInContext] a key-value object with + * @property {Object.} [showInContext] a key-value object with * context -> num to require the tip to be shown in a specific context for the * given number of times. See {@link RandomTips.setContext}. - * @property {Object.} [maximumInContest] a key-value object with + * @property {Object.} [maximumInContest] a key-value object with * context -> num to only show the tip in a specific context at most for the * given number of times. See {@link RandomTips.setContext}. - * @property {bool|integer} [randomizeDisplay=false] Randomizes the display with a + * @property {boolean|number} [randomizeDisplay=false] Randomizes the display with a * chance of 50% by default (when set to `true`). You can override that percentage * by specifying an integer < 1 (e.g. 0.2 for a 20% chance) as a propbability. * The chance is the chance that the tip *is shown*, i.e. the tip is shown for @@ -71,7 +71,7 @@ * @param {TipObject} tipSpecOrig the original, unmodified (frozen) TipObject * of the tip * @param {module:RandomTips~ModuleConfig} moduleConfig the whole config of this module - * @return {boolean|null} + * @return {Promise} */ import {isMobile} from "../MobileHelper.js"; @@ -182,6 +182,6 @@ for (const object of tipArray) { * * @public * @const - * @type {Array.} + * @type {readonly TipObject[]} */ export const tips = Object.freeze(tipArray); diff --git a/src/options/modules/ColorSchemeModeHelper.js b/src/options/modules/ColorSchemeModeHelper.js index 0789c00..c2e5405 100644 --- a/src/options/modules/ColorSchemeModeHelper.js +++ b/src/options/modules/ColorSchemeModeHelper.js @@ -25,7 +25,7 @@ function changeScreenshotTheme(darkQuery) { export function init() { const dark = window.matchMedia("(prefers-color-scheme: dark)"); - dark.addListener(changeScreenshotTheme); + dark.addEventListener("change", changeScreenshotTheme); return changeScreenshotTheme(dark); } diff --git a/src/options/modules/CustomOptionTriggers.js b/src/options/modules/CustomOptionTriggers.js index 129b613..0bcb390 100644 --- a/src/options/modules/CustomOptionTriggers.js +++ b/src/options/modules/CustomOptionTriggers.js @@ -157,7 +157,7 @@ function adjustPickerResultTypeOption(param) { * * @private * @param {string} language - * @param {integer} optionValue + * @param {number} optionValue * @returns {string} messageName */ function getPluralForm(language, optionValue) { @@ -177,7 +177,7 @@ function getPluralForm(language, optionValue) { * after the options have been loaded and when the option value is updated by the user. * * @private - * @param {integer} optionValue + * @param {Object} optionValue * @param {string} option the name of the option that has been changed * @param {Event} event the event (input or change) that triggered saving * (may not always be defined, e.g. when loading) @@ -206,7 +206,7 @@ function updatePerLineStatus(optionValue, option, event) { * Adjust maximum value of emojis per line when the emoji size is adjusted. * * @private - * @param {integer} optionValue + * @param {Object} optionValue * @param {string} option the name of the option that has been changed * @param {Event} event the event (input or change) that triggered saving * (may not always be defined, e.g. when loading) diff --git a/src/options/modules/ManualAdjustments.js b/src/options/modules/ManualAdjustments.js index 0bb2144..81d70c7 100644 --- a/src/options/modules/ManualAdjustments.js +++ b/src/options/modules/ManualAdjustments.js @@ -5,7 +5,7 @@ import { getBrowserValue } from "/common/modules/BrowserCompat.js"; * * Applies the adjustments. * - * @returns {Promise} + * @returns {void} */ export function init() { getBrowserValue({ diff --git a/src/popup/module/ConfirmationHint.js b/src/popup/module/ConfirmationHint.js index 036c9dc..352e0ad 100644 --- a/src/popup/module/ConfirmationHint.js +++ b/src/popup/module/ConfirmationHint.js @@ -125,7 +125,7 @@ function hidePopup(elPanel) { * @param {HTMLElement} options An object with the following optional properties: * @param {event} [options.event] The event that triggered the feedback. * @param {boolean} [options.showDescription] show description text (confirmationHint..description) - * @returns {Promise} + * @returns {Promise} */ export function show(position, messageId, options = {}) { return new Promise((resolve) => { diff --git a/src/popup/module/EmojiSelect.js b/src/popup/module/EmojiSelect.js index 4a21991..30c8159 100644 --- a/src/popup/module/EmojiSelect.js +++ b/src/popup/module/EmojiSelect.js @@ -23,7 +23,7 @@ let optionPickerResult; * * @public * @param {Object} emoji - * @param {Object} event + * @param {MouseEvent} event * @returns {void} */ export function saveClickPosition(emoji, event) { @@ -59,7 +59,7 @@ export function getEmojiHtml(emoji) { * @private * @param {boolean} isEmojiInserted * @param {boolean} isEmojiCopied - * @returns {Promise} + * @returns {string} */ function getUserMessageForResult(isEmojiInserted, isEmojiCopied) { let messageToBeShown; diff --git a/src/popup/module/EmojiSettings.js b/src/popup/module/EmojiSettings.js index 2fbd898..a3f7c07 100644 --- a/src/popup/module/EmojiSettings.js +++ b/src/popup/module/EmojiSettings.js @@ -14,7 +14,7 @@ let emojiMartStorage = {}; * @todo create * @public * @param {string} emoji - * @returns {string} + * @returns {void} */ export function copyEmoji(emoji) { navigator.clipboard.writeText(emoji.native); @@ -24,7 +24,7 @@ export function copyEmoji(emoji) { * Get all the settings for the Emoji picker. * * @public - * @returns {Object} + * @returns {Promise} */ export async function getAllSettings() { const settings = await AddonSettings.get("emojiPicker"); @@ -35,7 +35,7 @@ export async function getAllSettings() { * Sets the emoji-mart data storage. * * @private - * @returns {void} + * @returns {Promise} * @see https://github.com/missive/emoji-mart#storage */ export async function initEmojiMartStorage() { From 4fdfbd76819224cf9d654260ddca8171faa6ff7b Mon Sep 17 00:00:00 2001 From: Teal Dulcet Date: Fri, 4 Aug 2023 01:50:13 -0700 Subject: [PATCH 3/3] Updated to use the URLSearchParams API. --- src/background/modules/OmniboxSearch.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/background/modules/OmniboxSearch.js b/src/background/modules/OmniboxSearch.js index 6710d0d..a7163f8 100644 --- a/src/background/modules/OmniboxSearch.js +++ b/src/background/modules/OmniboxSearch.js @@ -142,6 +142,7 @@ export async function triggerOmnixboxDisabledSearch(text, disposition) { * @see {@link https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/omnibox/onInputEntered} */ export async function triggerOmnixboxSearch(text, disposition) { + text = text.trim(); const searchResult = window.emojiMart.emojiIndex.search(text); const emojiSearch = await AddonSettings.get("emojiSearch"); @@ -171,7 +172,7 @@ export async function triggerOmnixboxSearch(text, disposition) { copyToClipboard: true }); } else if (emojiSearch.action === "emojipedia") { - const resultUrl = `https://emojipedia.org/search/?q=${encodeURIComponent(emojiText)}`; + const resultUrl = `https://emojipedia.org/search/?${new URLSearchParams({ q: emojiText })}`; // navigate to URL in current or new tab openTabUrl(resultUrl, disposition); @@ -187,7 +188,7 @@ export async function triggerOmnixboxSearch(text, disposition) { // browser.browserAction.openPopup(); // search for result in emojipedia - const resultUrl = `https://emojipedia.org/search/?q=${encodeURIComponent(text)}`; + const resultUrl = `https://emojipedia.org/search/?${new URLSearchParams({ q: text })}`; openTabUrl(resultUrl, disposition); } }