diff --git a/.eslintrc b/.eslintrc index a8d62a3..c360d7d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,7 @@ { "root": true, "parserOptions": { - "ecmaVersion": 2017, + "ecmaVersion": 14, "sourceType": "module", "ecmaFeatures": { "impliedStrict": true @@ -10,7 +10,7 @@ "env": { "browser": true, "webextensions": true, - "es6": true + "es2023": true }, "extends": "eslint:recommended", "rules": { diff --git a/scripts/manifests/chromemanifest.json b/scripts/manifests/chromemanifest.json index 5272040..c4517c6 100644 --- a/scripts/manifests/chromemanifest.json +++ b/scripts/manifests/chromemanifest.json @@ -9,8 +9,6 @@ "homepage_url": "https://github.com/rugk/awesome-emoji-picker", "browser_action": { - "browser_style": true, - "chrome_style": true, "default_icon": "icons/fa-grin-dark.png", "default_title": "__MSG_browserActionButtonTitle__", "default_popup": "popup/index.html", @@ -28,13 +26,12 @@ }, "options_ui": { - "page": "options/options.html", - "browser_style": true, - "chrome_style": true + "page": "options/options.html" }, "background": { - "page": "background/background.html" + "scripts": ["browser-polyfill.js", "background/modules/InstallUpgrade.js", "background/background.js"], + "type": "module" }, "content_scripts": [ { diff --git a/scripts/manifests/dev.json b/scripts/manifests/dev.json index d796e75..d2a1c68 100644 --- a/scripts/manifests/dev.json +++ b/scripts/manifests/dev.json @@ -9,7 +9,6 @@ "homepage_url": "https://github.com/rugk/awesome-emoji-picker", "browser_action": { - "browser_style": true, "default_icon": "icons/fa-grin-dark.svg", "default_title": "__MSG_browserActionButtonTitle__", "default_popup": "popup/index.html", @@ -27,12 +26,12 @@ }, "options_ui": { - "page": "options/options.html", - "browser_style": true + "page": "options/options.html" }, "background": { - "page": "background/background.html" + "scripts": ["background/modules/InstallUpgrade.js", "background/background.js"], + "type": "module" }, "content_scripts": [ { @@ -75,7 +74,7 @@ "browser_specific_settings": { "gecko": { "id": "awesome-emoji-picker@rugk.github.io", - "strict_min_version": "87.0" + "strict_min_version": "112.0" } } } diff --git a/scripts/manifests/firefox.json b/scripts/manifests/firefox.json index d8c9289..38333d0 100644 --- a/scripts/manifests/firefox.json +++ b/scripts/manifests/firefox.json @@ -9,7 +9,6 @@ "homepage_url": "https://github.com/rugk/awesome-emoji-picker", "browser_action": { - "browser_style": true, "default_icon": "icons/fa-grin-dark.svg", "default_title": "__MSG_browserActionButtonTitle__", "default_popup": "popup/index.html", @@ -27,12 +26,12 @@ }, "options_ui": { - "page": "options/options.html", - "browser_style": true + "page": "options/options.html" }, "background": { - "page": "background/background.html" + "scripts": ["background/modules/InstallUpgrade.js", "background/background.js"], + "type": "module" }, "content_scripts": [ { @@ -74,7 +73,7 @@ "browser_specific_settings": { "gecko": { "id": "awesome-emoji-picker@rugk.github.io", - "strict_min_version": "87.0" + "strict_min_version": "112.0" } } } diff --git a/scripts/manifests/thunderbirdmanifest.json b/scripts/manifests/thunderbirdmanifest.json index b1fe38d..ad6f573 100644 --- a/scripts/manifests/thunderbirdmanifest.json +++ b/scripts/manifests/thunderbirdmanifest.json @@ -10,7 +10,6 @@ "compose_action": { - "browser_style": true, "default_area": "formattoolbar", "default_icon": "icons/fa-grin-dark.svg", "default_title": "__MSG_browserActionButtonTitle__", @@ -25,12 +24,12 @@ }, "options_ui": { - "page": "options/options.html", - "browser_style": true + "page": "options/options.html" }, "background": { - "page": "background/background.html" + "scripts": ["background/modules/InstallUpgrade.js", "background/background.js"], + "type": "module" }, "commands": { "_execute_compose_action": { @@ -63,7 +62,7 @@ "browser_specific_settings": { "gecko": { "id": "awesome-emoji-picker@rugk.github.io", - "strict_min_version": "91.0" + "strict_min_version": "112.0" } } } diff --git a/src/background/background.html b/src/background/background.html index f7d179d..a5d88a2 100644 --- a/src/background/background.html +++ b/src/background/background.html @@ -7,7 +7,7 @@ - + diff --git a/src/background/modules/ContextMenu.js b/src/background/modules/ContextMenu.js index 3c15e50..5513173 100644 --- a/src/background/modules/ContextMenu.js +++ b/src/background/modules/ContextMenu.js @@ -78,9 +78,7 @@ export async function init() { applySettings(contextMenu); - // IS_THUNDERBIRD should not have been needed after https://bugzilla.mozilla.org/show_bug.cgi?id=1681153 - // Fixed in Thunderbird 99 by https://bugzilla.mozilla.org/show_bug.cgi?id=1751895 - if (IS_THUNDERBIRD || IS_CHROME) { + if (IS_CHROME) { menus.onClicked.addListener(handle); } } diff --git a/src/background/modules/OmniboxSearch.js b/src/background/modules/OmniboxSearch.js index a7163f8..146f35c 100644 --- a/src/background/modules/OmniboxSearch.js +++ b/src/background/modules/OmniboxSearch.js @@ -50,13 +50,13 @@ function openTabUrl(url, disposition) { case "newForegroundTab": browser.tabs.create({ active: true, - url: url + url }); break; case "newBackgroundTab": browser.tabs.create({ active: false, - url: url + url }); break; } @@ -123,7 +123,7 @@ export async function triggerOmnixboxDisabledSearch(text, disposition) { default: // eslint-disable-line no-fallthrough return browser.search.search({ query: text, - tabId: tabId + tabId }); } } diff --git a/src/common/modules/AutocorrectHandler.js b/src/common/modules/AutocorrectHandler.js index 1ea4a7f..9c47f39 100644 --- a/src/common/modules/AutocorrectHandler.js +++ b/src/common/modules/AutocorrectHandler.js @@ -5,8 +5,8 @@ import * as BrowserCommunication from "/common/modules/BrowserCommunication/Brow import { COMMUNICATION_MESSAGE_TYPE } from "/common/modules/data/BrowserCommunicationTypes.js"; import * as symbols from "/common/modules/data/Symbols.js"; -// Not actually a module -import * as emojimart from "/common/lib/emoji-mart-embed/dist/emoji-mart.js"; +// Not actually a module, but sets the emojiMart global +import "/common/lib/emoji-mart-embed/dist/emoji-mart.js"; const settings = { enabled: null, @@ -223,11 +223,11 @@ function sendSettings(autocorrect) { enabled: settings.enabled, autocomplete: settings.autocomplete, autocompleteSelect: settings.autocompleteSelect, - autocorrections: autocorrections, - longest: longest, + autocorrections, + longest, symbolpatterns: IS_CHROME ? symbolpatterns.source : symbolpatterns, antipatterns: IS_CHROME ? antipatterns.source : antipatterns, - emojiShortcodes: emojiShortcodes + emojiShortcodes } ).catch(onError); } @@ -263,11 +263,11 @@ export async function init() { enabled: settings.enabled, autocomplete: settings.autocomplete, autocompleteSelect: settings.autocompleteSelect, - autocorrections: autocorrections, - longest: longest, + autocorrections, + longest, symbolpatterns: IS_CHROME ? symbolpatterns.source : symbolpatterns, antipatterns: IS_CHROME ? antipatterns.source : antipatterns, - emojiShortcodes: emojiShortcodes + emojiShortcodes }; // console.log(response); return Promise.resolve(response); diff --git a/src/common/modules/EmojiInteraction.js b/src/common/modules/EmojiInteraction.js index 46f476e..3f56cbc 100644 --- a/src/common/modules/EmojiInteraction.js +++ b/src/common/modules/EmojiInteraction.js @@ -18,7 +18,7 @@ export async function insertOrCopy(text, options) { insertIntoPage, copyOnlyOnFallback } = options; - let copyToClipboard = options.copyToClipboard; + let { copyToClipboard } = options; console.log("Action triggered for emoji:", text); diff --git a/src/common/modules/PageHandler.js b/src/common/modules/PageHandler.js index 71a599c..6c76845 100644 --- a/src/common/modules/PageHandler.js +++ b/src/common/modules/PageHandler.js @@ -3,6 +3,8 @@ * */ +import { COMMUNICATION_MESSAGE_TYPE } from "/common/modules/data/BrowserCommunicationTypes.js"; + /** * Insert emoji into page. * @@ -10,7 +12,7 @@ * * @public * @param {string} text - * @returns {Promise} + * @returns {Promise[]} */ export async function insertIntoPage(text) { const tabs = await browser.tabs.query({ @@ -20,11 +22,9 @@ export async function insertIntoPage(text) { const promises = tabs.map((tab) => { // 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(${JSON.stringify(text)});`, - allFrames: true, - runAt: "document_end" + return browser.tabs.sendMessage(tab.id, { + type: COMMUNICATION_MESSAGE_TYPE.INSERT, + text }); }); diff --git a/src/common/modules/data/BrowserCommunicationTypes.js b/src/common/modules/data/BrowserCommunicationTypes.js index 541ac91..b65d82a 100644 --- a/src/common/modules/data/BrowserCommunicationTypes.js +++ b/src/common/modules/data/BrowserCommunicationTypes.js @@ -16,5 +16,6 @@ export const COMMUNICATION_MESSAGE_TYPE = Object.freeze({ OMNIBAR_TOGGLE: "omnibarToggle", AUTOCORRECT_BACKGROUND: "autocorrectBackground", AUTOCORRECT_CONTENT: "autocorrectContent", - CONTEXT_MENU: "contextMenu" + CONTEXT_MENU: "contextMenu", + INSERT: "insert" }); diff --git a/src/content_scripts/autocorrect.js b/src/content_scripts/autocorrect.js index 350c302..ed7da3d 100644 --- a/src/content_scripts/autocorrect.js +++ b/src/content_scripts/autocorrect.js @@ -3,6 +3,7 @@ // communication type // directly include magic constant as a workaround as we cannot import modules in content scripts due to https://bugzilla.mozilla.org/show_bug.cgi?id=1451545 const AUTOCORRECT_CONTENT = "autocorrectContent"; +const INSERT = "insert"; let insertedText; // Last insert text let deletedText; // Last deleted text @@ -316,28 +317,29 @@ function undoAutocorrect(event) { * @returns {void} */ function handleResponse(message, sender) { - if (message.type !== AUTOCORRECT_CONTENT) { - return; - } - ({ - enabled, - autocomplete, - autocompleteSelect, - autocorrections, - longest, - symbolpatterns, - antipatterns, - emojiShortcodes - } = message); - symbolpatterns = IS_CHROME ? new RegExp(symbolpatterns, "u") : symbolpatterns; - antipatterns = IS_CHROME ? new RegExp(antipatterns, "u") : antipatterns; - - if (enabled) { - addEventListener("beforeinput", undoAutocorrect, true); - addEventListener("beforeinput", autocorrect, true); - } else { - removeEventListener("beforeinput", undoAutocorrect, true); - removeEventListener("beforeinput", autocorrect, true); + if (message.type === AUTOCORRECT_CONTENT) { + ({ + enabled, + autocomplete, + autocompleteSelect, + autocorrections, + longest, + symbolpatterns, + antipatterns, + emojiShortcodes + } = message); + symbolpatterns = IS_CHROME ? new RegExp(symbolpatterns, "u") : symbolpatterns; + antipatterns = IS_CHROME ? new RegExp(antipatterns, "u") : antipatterns; + + if (enabled) { + addEventListener("beforeinput", undoAutocorrect, true); + addEventListener("beforeinput", autocorrect, true); + } else { + removeEventListener("beforeinput", undoAutocorrect, true); + removeEventListener("beforeinput", autocorrect, true); + } + } else if (message.type === INSERT) { + insertIntoPage(message.text); } } diff --git a/src/manifest.json b/src/manifest.json index edf919e..5a96c5e 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -9,7 +9,6 @@ "homepage_url": "https://github.com/rugk/awesome-emoji-picker", "browser_action": { - "browser_style": true, "default_icon": "icons/fa-grin-dark.svg", "default_title": "__MSG_browserActionButtonTitle__", "default_popup": "popup/index.html", @@ -27,12 +26,12 @@ }, "options_ui": { - "page": "options/options.html", - "browser_style": true + "page": "options/options.html" }, "background": { - "page": "background/background.html" + "scripts": ["background/modules/InstallUpgrade.js", "background/background.js"], + "type": "module" }, "content_scripts": [ { @@ -75,7 +74,7 @@ "browser_specific_settings": { "gecko": { "id": "awesome-emoji-picker@rugk.github.io", - "strict_min_version": "87.0" + "strict_min_version": "112.0" } } } diff --git a/src/options/modules/CustomOptionTriggers.js b/src/options/modules/CustomOptionTriggers.js index 0cc2173..9bd033e 100644 --- a/src/options/modules/CustomOptionTriggers.js +++ b/src/options/modules/CustomOptionTriggers.js @@ -115,7 +115,7 @@ function applyAutocorrectPermissions(optionValue, option, event) { // trigger update for current session browser.runtime.sendMessage({ type: COMMUNICATION_MESSAGE_TYPE.AUTOCORRECT_BACKGROUND, - optionValue: optionValue + optionValue }); return retPromise; @@ -134,7 +134,7 @@ function applyContextMenuSettings(optionValue, option, event) { // trigger update for current session browser.runtime.sendMessage({ type: COMMUNICATION_MESSAGE_TYPE.CONTEXT_MENU, - optionValue: optionValue + optionValue }); } diff --git a/src/options/options.html b/src/options/options.html index 9aab647..66565fc 100644 --- a/src/options/options.html +++ b/src/options/options.html @@ -6,7 +6,7 @@ - + diff --git a/src/popup/index.html b/src/popup/index.html index e3725ff..123a1a3 100644 --- a/src/popup/index.html +++ b/src/popup/index.html @@ -7,7 +7,7 @@ - + diff --git a/src/popup/index.js b/src/popup/index.js index b74a5b3..056cc95 100644 --- a/src/popup/index.js +++ b/src/popup/index.js @@ -46,7 +46,9 @@ async function createPicker() { * @returns {Promise} */ export async function focusElement(element, retries = 20, delay = 50) { - const wait = (ms) => new Promise((func) => setTimeout(func, ms)); + const wait = (ms) => new Promise((func) => { + setTimeout(func, ms); + }); element.focus();