diff options
author | Ajay <[email protected]> | 2024-06-19 23:14:27 +0530 |
---|---|---|
committer | Ajay <[email protected]> | 2024-06-19 23:14:27 +0530 |
commit | 98a4a076bc1d8b2d3a9b64355b9aaf84e2a4b685 (patch) | |
tree | 5671c0a2dcd6109a780809ed36d273a95a440d2a /src/utils.ts | |
parent | a95020dda3d3f05691f5277e69688f05ac59dc1e (diff) | |
download | SponsorBlock-98a4a076bc1d8b2d3a9b64355b9aaf84e2a4b685.tar.gz SponsorBlock-98a4a076bc1d8b2d3a9b64355b9aaf84e2a4b685.zip |
Support invidious in mv3
Diffstat (limited to 'src/utils.ts')
-rw-r--r-- | src/utils.ts | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/src/utils.ts b/src/utils.ts index 7c3f985e..610e93c6 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -46,10 +46,7 @@ export default class Utils { */ setupExtraSitePermissions(callback: (granted: boolean) => void): void { const permissions = []; - if (!isFirefoxOrSafari()) { - permissions.push("declarativeContent"); - } - if (!isFirefoxOrSafari() || isSafari()) { + if (isSafari()) { permissions.push("webNavigation"); } @@ -67,6 +64,17 @@ export default class Utils { }); } + getExtraSiteRegistration(): Registration { + return { + message: "registerContentScript", + id: "invidious", + allFrames: true, + js: this.js, + css: this.css, + matches: this.getPermissionRegex() + }; + } + /** * Registers the content scripts for the extra sites. * Will use a different method depending on the browser. @@ -75,14 +83,7 @@ export default class Utils { * For now, it is just SB.config.invidiousInstances. */ setupExtraSiteContentScripts(): void { - const registration: Registration = { - message: "registerContentScript", - id: "invidious", - allFrames: true, - js: this.js, - css: this.css, - matches: this.getPermissionRegex() - }; + const registration = this.getExtraSiteRegistration(); if (this.backgroundScriptContainer) { this.backgroundScriptContainer.registerFirefoxContentScript(registration); @@ -106,11 +107,6 @@ export default class Utils { }); } - if (!isFirefoxOrSafari() && chrome.declarativeContent) { - // Only if we have permission - chrome.declarativeContent.onPageChanged.removeRules(["invidious"]); - } - chrome.permissions.remove({ origins: this.getPermissionRegex() }); @@ -135,8 +131,10 @@ export default class Utils { containsInvidiousPermission(): Promise<boolean> { return new Promise((resolve) => { - let permissions = ["declarativeContent"]; - if (isFirefoxOrSafari()) permissions = []; + const permissions = []; + if (isSafari()) { + permissions.push("webNavigation"); + } chrome.permissions.contains({ origins: this.getPermissionRegex(), |