mirror of
https://github.com/ItsVipra/ProToots
synced 2024-11-22 19:43:03 +00:00
Request permissions for page on first invocation
This commit is contained in:
parent
f5993c4636
commit
65e949ae77
3 changed files with 19 additions and 2 deletions
|
@ -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
14
src/background/worker.js
Normal 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" });
|
||||
});
|
|
@ -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": [
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue