refactor(browser-extension): make necessary changes to work on Mozilla Mobile

This commit is contained in:
wanhose 2024-11-11 20:32:05 +01:00
parent 781511be3c
commit f87d7da8b8
4 changed files with 9 additions and 82 deletions

View File

@ -1,6 +1,6 @@
{ {
"manifest_version": 3, "manifest_version": 3,
"name": "Cookie Dialog Monster", "name": "Cookie Dialog Monster Mobile",
"version": "8.0.5", "version": "8.0.5",
"default_locale": "en", "default_locale": "en",
"description": "__MSG_appDesc__", "description": "__MSG_appDesc__",
@ -12,19 +12,18 @@
"action": { "action": {
"default_icon": "assets/icons/off.png", "default_icon": "assets/icons/off.png",
"default_popup": "popup.html", "default_popup": "popup.html",
"default_title": "Cookie Dialog Monster" "default_title": "Cookie Dialog Monster Mobile"
}, },
"options_page": "options.html", "options_page": "options.html",
"author": "wanhose", "author": "wanhose",
"background": { "background": {
"scripts": ["scripts/background.js"], "scripts": ["scripts/background.js"]
"service_worker": "scripts/background.js"
}, },
"browser_specific_settings": { "browser_specific_settings": {
"gecko": { "gecko": {
"id": "{77e2c00b-e173-4604-863d-01645d8d2826}", "id": "{108d0aea-9bbd-4719-a793-0bc73c1d0064}",
"strict_min_version": "126.0", "strict_min_version": "126.0",
"update_url": "https://www.cookie-dialog-monster.com/releases/mozilla/updates.json" "update_url": "https://www.cookie-dialog-monster.com/releases/mozilla-mobile/updates.json"
} }
}, },
"content_scripts": [ "content_scripts": [
@ -36,7 +35,7 @@
} }
], ],
"host_permissions": ["http://*/*", "https://*/*"], "host_permissions": ["http://*/*", "https://*/*"],
"permissions": ["contextMenus", "declarativeNetRequest", "scripting", "storage", "webRequest"], "permissions": ["declarativeNetRequest", "scripting", "storage", "webRequest"],
"web_accessible_resources": [ "web_accessible_resources": [
{ {
"matches": ["http://*/*", "https://*/*"], "matches": ["http://*/*", "https://*/*"],

View File

@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cookie Dialog Monster > Exclusion List</title> <title>Cookie Dialog Monster Mobile > Exclusion List</title>
<link rel="stylesheet" href="/styles/reset.css" /> <link rel="stylesheet" href="/styles/reset.css" />
<link rel="stylesheet" href="/styles/options.css" /> <link rel="stylesheet" href="/styles/options.css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inter" /> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inter" />
@ -13,7 +13,7 @@
<header> <header>
<div> <div>
<h1 class="header-title"> <h1 class="header-title">
Cookie Dialog Monster > <span data-i18n="options_exclusionListTitle"></span> Cookie Dialog Monster Mobile > <span data-i18n="options_exclusionListTitle"></span>
</h1> </h1>
</div> </div>
</header> </header>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<header> <header>
<h1 class="header-title">Cookie Dialog Monster</h1> <h1 class="header-title">Cookie Dialog Monster Mobile</h1>
<div class="header-actions"> <div class="header-actions">
<button <button
class="header-button" class="header-button"

View File

@ -49,35 +49,11 @@ class RequestManager {
*/ */
const apiUrl = 'https://api.cookie-dialog-monster.com/rest/v6'; const apiUrl = 'https://api.cookie-dialog-monster.com/rest/v6';
/**
* @description Context menu identifier
* @type {string}
*/
const extensionMenuItemId = 'CDM-MENU';
/**
* @description Context menu identifier
* @type {string}
*/
const reportMenuItemId = 'CDM-REPORT';
/** /**
* @description Request manager instance * @description Request manager instance
*/ */
const requestManager = new RequestManager(); const requestManager = new RequestManager();
/**
* @description Context menu identifier
* @type {string}
*/
const settingsMenuItemId = 'CDM-SETTINGS';
/**
* @description A shortcut for browser.scripting
* @type {browser.scripting}
*/
const script = browser.scripting;
/** /**
* @description Default value for extension state * @description Default value for extension state
* @type {ExtensionState} * @type {ExtensionState}
@ -251,22 +227,6 @@ async function updateStore(key, value) {
} }
} }
/**
* @description Listen to context menus clicked
*/
browser.contextMenus.onClicked.addListener((info) => {
switch (info.menuItemId) {
case reportMenuItemId:
browser.action.openPopup();
break;
case settingsMenuItemId:
browser.runtime.openOptionsPage();
break;
default:
break;
}
});
/** /**
* @description Listens to messages * @description Listens to messages
*/ */
@ -334,38 +294,6 @@ browser.runtime.onMessage.addListener((message, sender, callback) => {
* @description Listens to extension installed * @description Listens to extension installed
*/ */
browser.runtime.onInstalled.addListener((details) => { browser.runtime.onInstalled.addListener((details) => {
const documentUrlPatterns = browser.runtime.getManifest().content_scripts[0].matches;
browser.contextMenus.create(
{
contexts: ['all'],
documentUrlPatterns,
id: extensionMenuItemId,
title: 'Cookie Dialog Monster',
},
suppressLastError
);
browser.contextMenus.create(
{
contexts: ['all'],
documentUrlPatterns,
id: settingsMenuItemId,
parentId: extensionMenuItemId,
title: browser.i18n.getMessage('contextMenu_settingsOption'),
},
suppressLastError
);
browser.contextMenus.create(
{
contexts: ['all'],
documentUrlPatterns,
id: reportMenuItemId,
parentId: extensionMenuItemId,
title: browser.i18n.getMessage('contextMenu_reportOption'),
},
suppressLastError
);
if (details.reason === 'update') { if (details.reason === 'update') {
refreshData(); refreshData();
} }