Skip to content

Commit

Permalink
Merge pull request #147 from tdulcet/mv3
Browse files Browse the repository at this point in the history
Removed use of `tabs.executeScript()` and updated manifest files
  • Loading branch information
rugk authored Oct 7, 2023
2 parents 7379aa2 + e3e92f1 commit 7dfb871
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"root": true,
"parserOptions": {
"ecmaVersion": 2017,
"ecmaVersion": 14,
"sourceType": "module",
"ecmaFeatures": {
"impliedStrict": true
Expand All @@ -10,7 +10,7 @@
"env": {
"browser": true,
"webextensions": true,
"es6": true
"es2023": true
},
"extends": "eslint:recommended",
"rules": {
Expand Down
9 changes: 3 additions & 6 deletions scripts/manifests/chromemanifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [
{
Expand Down
9 changes: 4 additions & 5 deletions scripts/manifests/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [
{
Expand Down Expand Up @@ -75,7 +74,7 @@
"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "87.0"
"strict_min_version": "112.0"
}
}
}
9 changes: 4 additions & 5 deletions scripts/manifests/firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [
{
Expand Down Expand Up @@ -74,7 +73,7 @@
"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "87.0"
"strict_min_version": "112.0"
}
}
}
9 changes: 4 additions & 5 deletions scripts/manifests/thunderbirdmanifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


"compose_action": {
"browser_style": true,
"default_area": "formattoolbar",
"default_icon": "icons/fa-grin-dark.svg",
"default_title": "__MSG_browserActionButtonTitle__",
Expand All @@ -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": {
Expand Down Expand Up @@ -63,7 +62,7 @@
"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "91.0"
"strict_min_version": "112.0"
}
}
}
2 changes: 1 addition & 1 deletion src/background/background.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<head>
<meta charset="utf-8">
<!-- async currently disabled, because of https://bugzilla.mozilla.org/show_bug.cgi?id=1506464 -->
<script type="application/javascript" src="../browser-polyfill.js"></script>
<script src="../browser-polyfill.js" type="module"></script>
<script src="./modules/InstallUpgrade.js" type="module" charset="utf-8"></script>
<script async src="background.js" type="module" charset="utf-8"></script>
</head>
Expand Down
4 changes: 1 addition & 3 deletions src/background/modules/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/background/modules/OmniboxSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
});
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/common/modules/AutocorrectHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/common/modules/EmojiInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions src/common/modules/PageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
*
*/

import { COMMUNICATION_MESSAGE_TYPE } from "/common/modules/data/BrowserCommunicationTypes.js";

/**
* Insert emoji into page.
*
* Returns a Promise that results in the text that has been modified.
*
* @public
* @param {string} text
* @returns {Promise}
* @returns {Promise[]}
*/
export async function insertIntoPage(text) {
const tabs = await browser.tabs.query({
Expand All @@ -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
});
});

Expand Down
3 changes: 2 additions & 1 deletion src/common/modules/data/BrowserCommunicationTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
});
46 changes: 24 additions & 22 deletions src/content_scripts/autocorrect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [
{
Expand Down Expand Up @@ -75,7 +74,7 @@
"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "87.0"
"strict_min_version": "112.0"
}
}
}
4 changes: 2 additions & 2 deletions src/options/modules/CustomOptionTriggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link rel="stylesheet" href="../common/common.css">
<link rel="stylesheet" href="options.css">

<script type="application/javascript" src="../browser-polyfill.js"></script>
<script src="../browser-polyfill.js" type="module"></script>
<script async src="./fastLoad.js" type="module"></script>
<script defer src="../common/common.js" type="module"></script>
<script defer src="./options.js" type="module"></script>
Expand Down
Loading

0 comments on commit 7dfb871

Please sign in to comment.