Request permissions for page on first invocation

This commit is contained in:
nachtjasmin 2023-07-05 00:04:44 +02:00
parent f5993c4636
commit 65e949ae77
No known key found for this signature in database
3 changed files with 19 additions and 2 deletions

View file

@ -10,6 +10,7 @@ const { copyPlugin } = copyPluginPkg; // js and your fucking mess of imports, si
*/
const files = [
path.join("src", "content_scripts", "protoots.js"),
path.join("src", "background", "worker.js"),
path.join("src", "options", "options.js"),
];

14
src/background/worker.js Normal file
View file

@ -0,0 +1,14 @@
import { action, permissions, tabs } from "webextension-polyfill";
action.onClicked.addListener(async (tab) => {
const u = new URL(tab.url);
const perms = { origins: [`${u.origin}/*`] };
const hasPermissions = await permissions.contains(perms);
if (!hasPermissions) {
await permissions.request(perms);
await tabs.reload(tab.id);
}
action.setPopup({ popup: "options/options.html" });
action.setTitle({ title: "Configure ProToots" });
});

View file

@ -14,8 +14,10 @@
"action": {
"default_icon": "icons/icon small_size/icon small_size.png",
"default_title": "ProToots",
"default_popup": "options/options.html"
"default_title": "Enable ProToots on this page"
},
"background": {
"scripts": ["background/worker.js"]
},
"content_scripts": [
{