forked from SevenTV/Extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanifest.config.ts
More file actions
128 lines (109 loc) · 3.51 KB
/
manifest.config.ts
File metadata and controls
128 lines (109 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { description, displayName, name } from "./package.json";
import type { Manifest } from "webextension-polyfill-ts";
interface MV3HostPermissions {
host_permissions?: string[];
optional_host_permissions?: string[];
}
interface ManifestOptions {
mv2?: boolean;
branch?: BranchName;
dev?: boolean;
mozillaID?: string;
version: string;
}
export type BranchName = "nightly" | "dev";
export async function getManifest(opt: ManifestOptions): Promise<Manifest.WebExtensionManifest> {
const iconName = "".concat(opt.branch ? opt.branch + "-" : "", "icon-%s.png").replace(/\s+/g, "");
const extensionName = (displayName || name)
.concat(
opt.branch ? ` ${opt.branch.charAt(0).toUpperCase() + opt.branch.slice(1)}` : "",
opt.dev ? " (Dev)" : "",
)
.trim();
const versionName = (opt.version + (opt.branch ? ` ${opt.branch}` : "")).trim();
const manifest = {
manifest_version: 3,
name: extensionName,
version: opt.version,
version_name: versionName,
description: description,
action: {
default_icon: `./icon/${iconName.replace("%s", "128")}`,
default_popup: "index.html#/popup?noheader=1",
default_area: "navbar",
},
...(opt.mozillaID
? {
browser_specific_settings: {
gecko: {
id:
typeof opt.mozillaID === "string"
? opt.mozillaID.trim().replace(/^"+|"+$/g, "")
: undefined,
data_collection_permissions: {
required: ["browsingActivity", "websiteContent"],
},
},
},
}
: {}),
background: {
service_worker: "background.js",
},
content_scripts: [
{
matches: ["*://*.twitch.tv/*"],
js: ["content.js"],
},
],
options_ui: {
page: "index.html",
open_in_tab: true,
},
icons: {
16: `./icon/${iconName.replace("%s", "16")}`,
48: `./icon/${iconName.replace("%s", "48")}`,
128: `./icon/${iconName.replace("%s", "128")}`,
},
// By default the extension is enabled only on Twitch
host_permissions: ["*://*.twitch.tv/*"],
permissions: ["scripting", "storage", "activeTab"],
optional_permissions: ["management"],
// Declare YouTube as an optional host permission
optional_host_permissions: ["*://*.youtube.com/*", "*://*.kick.com/*", "*://*.7tv.app/*", "*://*.7tv.io/*"],
web_accessible_resources: [
{
resources: ["site.js", "site.js.map", "content.js.map", "worker.js", "index.html", "assets/*"],
matches: ["*://*.twitch.tv/*", "*://*.youtube.com/*", "*://*.kick.com/*"],
},
],
} as Manifest.WebExtensionManifest & MV3HostPermissions;
if (opt.mv2) {
// if dev set manifest to version 2
manifest.manifest_version = 2;
manifest.background = {
scripts: ["background.js"],
};
manifest.browser_action = manifest.action;
// Host permissions -> permissions
manifest.permissions = [...(manifest.permissions ?? []), ...(manifest.host_permissions ?? [])];
manifest.optional_permissions = [
...(manifest.optional_permissions ?? []),
...(manifest.optional_host_permissions ?? []),
];
// web accessible resources
manifest.web_accessible_resources = (
manifest.web_accessible_resources as Manifest.WebExtensionManifestWebAccessibleResourcesC2ItemType[]
)
.map((v) => v.resources)
.reduce((a, b) => [...(a ?? []), ...(b ?? [])]);
// this is required on dev for Vite script to load
if (opt.dev) {
manifest.content_security_policy = `script-src-elem 'self' 'unsafe-eval' http://localhost:${4777}; object-src 'self'`;
}
delete manifest.host_permissions;
delete manifest.optional_host_permissions;
delete manifest.action;
}
return manifest;
}