diff options
author | Ajay Ramachandran <[email protected]> | 2024-06-22 16:29:43 +0530 |
---|---|---|
committer | GitHub <[email protected]> | 2024-06-22 16:29:43 +0530 |
commit | d86dd37ec074dca000d978bc83400a0feec4014a (patch) | |
tree | 1dc44c52f80cc12cac0e9f54a61a31426f929f54 | |
parent | 5e179cf9ff3177f760cfbbfd87af17248f0902db (diff) | |
parent | fae7d921a7f74da5df4420ba169ecc16b79aeb82 (diff) | |
download | SponsorBlock-d86dd37ec074dca000d978bc83400a0feec4014a.tar.gz SponsorBlock-d86dd37ec074dca000d978bc83400a0feec4014a.zip |
Merge pull request #2046 from ajayyy/mv3
Support mv3
-rw-r--r-- | manifest/chrome-manifest-extra.json | 158 | ||||
-rw-r--r-- | manifest/firefox-manifest-extra.json | 3 | ||||
-rw-r--r-- | manifest/manifest-v2-extra.json | 136 | ||||
-rw-r--r-- | manifest/manifest.json | 141 | ||||
-rw-r--r-- | manifest/safari-manifest-extra.json | 3 | ||||
m--------- | maze-utils | 0 | ||||
-rw-r--r-- | src/background.ts | 17 | ||||
-rw-r--r-- | src/content.ts | 2 | ||||
-rw-r--r-- | src/globals.d.ts | 15 | ||||
-rw-r--r-- | src/utils.ts | 38 | ||||
-rw-r--r-- | src/utils/logger.ts | 22 | ||||
-rw-r--r-- | webpack/webpack.manifest.js | 3 |
12 files changed, 340 insertions, 198 deletions
diff --git a/manifest/chrome-manifest-extra.json b/manifest/chrome-manifest-extra.json index 9cb5082d..4fa0fed7 100644 --- a/manifest/chrome-manifest-extra.json +++ b/manifest/chrome-manifest-extra.json @@ -1,12 +1,156 @@ { - "optional_permissions": [ - "declarativeContent", - "webNavigation" + "host_permissions": [ + "https://*.youtube.com/*", + "https://sponsor.ajay.app/*" ], + "optional_host_permissions": [ + "*://*/*" + ], + "web_accessible_resources": [{ + "resources": [ + "icons/LogoSponsorBlocker256px.png", + "icons/IconSponsorBlocker256px.png", + "icons/PlayerStartIconSponsorBlocker.svg", + "icons/PlayerStopIconSponsorBlocker.svg", + "icons/PlayerUploadIconSponsorBlocker.svg", + "icons/PlayerUploadFailedIconSponsorBlocker.svg", + "icons/PlayerCancelSegmentIconSponsorBlocker.svg", + "icons/clipboard.svg", + "icons/settings.svg", + "icons/pencil.svg", + "icons/check.svg", + "icons/check-smaller.svg", + "icons/upvote.png", + "icons/downvote.png", + "icons/thumbs_down.svg", + "icons/thumbs_down_locked.svg", + "icons/thumbs_up.svg", + "icons/help.svg", + "icons/report.png", + "icons/close.png", + "icons/skipIcon.svg", + "icons/refresh.svg", + "icons/beep.ogg", + "icons/pause.svg", + "icons/stop.svg", + "icons/skip.svg", + "icons/heart.svg", + "icons/visible.svg", + "icons/not_visible.svg", + "icons/sort.svg", + "icons/money.svg", + "icons/segway.png", + "icons/close-smaller.svg", + "icons/right-arrow.svg", + "icons/campaign.svg", + "icons/star.svg", + "icons/lightbulb.svg", + "icons/bolt.svg", + "icons/stopwatch.svg", + "icons/music-note.svg", + "icons/import.svg", + "icons/export.svg", + "icons/PlayerInfoIconSponsorBlocker.svg", + "icons/PlayerDeleteIconSponsorBlocker.svg", + "icons/dearrow.svg", + "popup.html", + "popup.css", + "content.css", + "shared.css", + "js/document.js", + "libs/Source+Sans+Pro.css", + "libs/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwlxdu.woff2", + "libs/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwmRduz8A.woff2", + "libs/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwmBduz8A.woff2", + "libs/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwlBduz8A.woff2" + ], + "matches": ["<all_urls>"] + }], + "content_scripts": [ + { + "world": "MAIN", + "js": [ + "./js/document.js" + ], + "matches": [ + "https://*.youtube.com/*", + "https://www.youtube-nocookie.com/embed/*" + ], + "exclude_matches": [ + "https://accounts.youtube.com/RotateCookiesPage*" + ], + "all_frames": true, + "run_at": "document_start" + }, + { + "world": "ISOLATED", + "js": [ + "./js/content.js" + ], + "css": [ + "content.css", + "shared.css" + ], + "matches": [ + "https://*.youtube.com/*", + "https://www.youtube-nocookie.com/embed/*" + ], + "exclude_matches": [ + "https://accounts.youtube.com/RotateCookiesPage*" + ], + "all_frames": true, + "run_at": "document_start" + } + ], + "action": { + "default_title": "SponsorBlock", + "default_popup": "popup.html", + "default_icon": { + "16": "icons/IconSponsorBlocker16px.png", + "32": "icons/IconSponsorBlocker32px.png", + "64": "icons/IconSponsorBlocker64px.png", + "128": "icons/IconSponsorBlocker128px.png" + }, + "theme_icons": [ + { + "light": "icons/IconSponsorBlocker16px.png", + "dark": "icons/IconSponsorBlocker16px.png", + "size": 16 + }, + { + "light": "icons/IconSponsorBlocker32px.png", + "dark": "icons/IconSponsorBlocker32px.png", + "size": 32 + }, + { + "light": "icons/IconSponsorBlocker64px.png", + "dark": "icons/IconSponsorBlocker64px.png", + "size": 64 + }, + { + "light": "icons/IconSponsorBlocker128px.png", + "dark": "icons/IconSponsorBlocker128px.png", + "size": 128 + }, + { + "light": "icons/IconSponsorBlocker256px.png", + "dark": "icons/IconSponsorBlocker256px.png", + "size": 256 + }, + { + "light": "icons/IconSponsorBlocker512px.png", + "dark": "icons/IconSponsorBlocker512px.png", + "size": 512 + }, + { + "light": "icons/IconSponsorBlocker1024px.png", + "dark": "icons/IconSponsorBlocker1024px.png", + "size": 1024 + } + ] + }, "background": { - "persistent": false + "service_worker": "./js/background.js" }, - "permissions": [ - "https://*.youtube.com/*" - ] + "manifest_version": 3 } diff --git a/manifest/firefox-manifest-extra.json b/manifest/firefox-manifest-extra.json index 9f9468bc..d7788721 100644 --- a/manifest/firefox-manifest-extra.json +++ b/manifest/firefox-manifest-extra.json @@ -11,9 +11,6 @@ "background": { "persistent": false }, - "permissions": [ - "scripting" - ], "browser_action": { "default_area": "navbar" } diff --git a/manifest/manifest-v2-extra.json b/manifest/manifest-v2-extra.json new file mode 100644 index 00000000..1c33efe7 --- /dev/null +++ b/manifest/manifest-v2-extra.json @@ -0,0 +1,136 @@ +{ + "web_accessible_resources": [ + "icons/LogoSponsorBlocker256px.png", + "icons/IconSponsorBlocker256px.png", + "icons/PlayerStartIconSponsorBlocker.svg", + "icons/PlayerStopIconSponsorBlocker.svg", + "icons/PlayerUploadIconSponsorBlocker.svg", + "icons/PlayerUploadFailedIconSponsorBlocker.svg", + "icons/PlayerCancelSegmentIconSponsorBlocker.svg", + "icons/clipboard.svg", + "icons/settings.svg", + "icons/pencil.svg", + "icons/check.svg", + "icons/check-smaller.svg", + "icons/upvote.png", + "icons/downvote.png", + "icons/thumbs_down.svg", + "icons/thumbs_down_locked.svg", + "icons/thumbs_up.svg", + "icons/help.svg", + "icons/report.png", + "icons/close.png", + "icons/skipIcon.svg", + "icons/refresh.svg", + "icons/beep.ogg", + "icons/pause.svg", + "icons/stop.svg", + "icons/skip.svg", + "icons/heart.svg", + "icons/visible.svg", + "icons/not_visible.svg", + "icons/sort.svg", + "icons/money.svg", + "icons/segway.png", + "icons/close-smaller.svg", + "icons/right-arrow.svg", + "icons/campaign.svg", + "icons/star.svg", + "icons/lightbulb.svg", + "icons/bolt.svg", + "icons/stopwatch.svg", + "icons/music-note.svg", + "icons/import.svg", + "icons/export.svg", + "icons/PlayerInfoIconSponsorBlocker.svg", + "icons/PlayerDeleteIconSponsorBlocker.svg", + "icons/dearrow.svg", + "popup.html", + "popup.css", + "content.css", + "shared.css", + "js/document.js", + "libs/Source+Sans+Pro.css", + "libs/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwlxdu.woff2", + "libs/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwmRduz8A.woff2", + "libs/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwmBduz8A.woff2", + "libs/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwlBduz8A.woff2" + ], + "permissions": [ + "https://sponsor.ajay.app/*" + ], + "optional_permissions": [ + "*://*/*" + ], + "browser_action": { + "default_title": "SponsorBlock", + "default_popup": "popup.html", + "default_icon": { + "16": "icons/IconSponsorBlocker16px.png", + "32": "icons/IconSponsorBlocker32px.png", + "64": "icons/IconSponsorBlocker64px.png", + "128": "icons/IconSponsorBlocker128px.png" + }, + "theme_icons": [ + { + "light": "icons/IconSponsorBlocker16px.png", + "dark": "icons/IconSponsorBlocker16px.png", + "size": 16 + }, + { + "light": "icons/IconSponsorBlocker32px.png", + "dark": "icons/IconSponsorBlocker32px.png", + "size": 32 + }, + { + "light": "icons/IconSponsorBlocker64px.png", + "dark": "icons/IconSponsorBlocker64px.png", + "size": 64 + }, + { + "light": "icons/IconSponsorBlocker128px.png", + "dark": "icons/IconSponsorBlocker128px.png", + "size": 128 + }, + { + "light": "icons/IconSponsorBlocker256px.png", + "dark": "icons/IconSponsorBlocker256px.png", + "size": 256 + }, + { + "light": "icons/IconSponsorBlocker512px.png", + "dark": "icons/IconSponsorBlocker512px.png", + "size": 512 + }, + { + "light": "icons/IconSponsorBlocker1024px.png", + "dark": "icons/IconSponsorBlocker1024px.png", + "size": 1024 + } + ] + }, + "background": { + "scripts":[ + "./js/background.js" + ] + }, + "content_scripts": [{ + "run_at": "document_start", + "matches": [ + "https://*.youtube.com/*", + "https://www.youtube-nocookie.com/embed/*" + ], + "exclude_matches": [ + "https://accounts.youtube.com/RotateCookiesPage*" + ], + "all_frames": true, + "js": [ + "./js/content.js" + ], + "css": [ + "content.css", + "shared.css" + ] + }], + "manifest_version": 2 +} diff --git a/manifest/manifest.json b/manifest/manifest.json index 2ebf3cd3..a30bfb64 100644 --- a/manifest/manifest.json +++ b/manifest/manifest.json @@ -5,140 +5,6 @@ "default_locale": "en", "description": "__MSG_Description__", "homepage_url": "https://sponsor.ajay.app", - "content_scripts": [{ - "run_at": "document_start", - "matches": [ - "https://*.youtube.com/*", - "https://www.youtube-nocookie.com/embed/*" - ], - "exclude_matches": [ - "https://accounts.youtube.com/RotateCookiesPage*" - ], - "all_frames": true, - "js": [ - "./js/content.js" - ], - "css": [ - "content.css", - "shared.css" - ] - }], - "web_accessible_resources": [ - "icons/LogoSponsorBlocker256px.png", - "icons/IconSponsorBlocker256px.png", - "icons/PlayerStartIconSponsorBlocker.svg", - "icons/PlayerStopIconSponsorBlocker.svg", - "icons/PlayerUploadIconSponsorBlocker.svg", - "icons/PlayerUploadFailedIconSponsorBlocker.svg", - "icons/PlayerCancelSegmentIconSponsorBlocker.svg", - "icons/clipboard.svg", - "icons/settings.svg", - "icons/pencil.svg", - "icons/check.svg", - "icons/check-smaller.svg", - "icons/upvote.png", - "icons/downvote.png", - "icons/thumbs_down.svg", - "icons/thumbs_down_locked.svg", - "icons/thumbs_up.svg", - "icons/help.svg", - "icons/report.png", - "icons/close.png", - "icons/skipIcon.svg", - "icons/refresh.svg", - "icons/beep.ogg", - "icons/pause.svg", - "icons/stop.svg", - "icons/skip.svg", - "icons/heart.svg", - "icons/visible.svg", - "icons/not_visible.svg", - "icons/sort.svg", - "icons/money.svg", - "icons/segway.png", - "icons/close-smaller.svg", - "icons/right-arrow.svg", - "icons/campaign.svg", - "icons/star.svg", - "icons/lightbulb.svg", - "icons/bolt.svg", - "icons/stopwatch.svg", - "icons/music-note.svg", - "icons/import.svg", - "icons/export.svg", - "icons/PlayerInfoIconSponsorBlocker.svg", - "icons/PlayerDeleteIconSponsorBlocker.svg", - "icons/dearrow.svg", - "popup.html", - "popup.css", - "content.css", - "shared.css", - "js/document.js", - "libs/Source+Sans+Pro.css", - "libs/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwlxdu.woff2", - "libs/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwmRduz8A.woff2", - "libs/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwmBduz8A.woff2", - "libs/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwlBduz8A.woff2" - ], - "permissions": [ - "storage", - "https://sponsor.ajay.app/*" - ], - "optional_permissions": [ - "*://*/*" - ], - "browser_action": { - "default_title": "SponsorBlock", - "default_popup": "popup.html", - "default_icon": { - "16": "icons/IconSponsorBlocker16px.png", - "32": "icons/IconSponsorBlocker32px.png", - "64": "icons/IconSponsorBlocker64px.png", - "128": "icons/IconSponsorBlocker128px.png" - }, - "theme_icons": [ - { - "light": "icons/IconSponsorBlocker16px.png", - "dark": "icons/IconSponsorBlocker16px.png", - "size": 16 - }, - { - "light": "icons/IconSponsorBlocker32px.png", - "dark": "icons/IconSponsorBlocker32px.png", - "size": 32 - }, - { - "light": "icons/IconSponsorBlocker64px.png", - "dark": "icons/IconSponsorBlocker64px.png", - "size": 64 - }, - { - "light": "icons/IconSponsorBlocker128px.png", - "dark": "icons/IconSponsorBlocker128px.png", - "size": 128 - }, - { - "light": "icons/IconSponsorBlocker256px.png", - "dark": "icons/IconSponsorBlocker256px.png", - "size": 256 - }, - { - "light": "icons/IconSponsorBlocker512px.png", - "dark": "icons/IconSponsorBlocker512px.png", - "size": 512 - }, - { - "light": "icons/IconSponsorBlocker1024px.png", - "dark": "icons/IconSponsorBlocker1024px.png", - "size": 1024 - } - ] - }, - "background": { - "scripts":[ - "./js/background.js" - ] - }, "icons": { "16": "icons/IconSponsorBlocker16px.png", "32": "icons/IconSponsorBlocker32px.png", @@ -148,9 +14,12 @@ "512": "icons/IconSponsorBlocker512px.png", "1024": "icons/IconSponsorBlocker1024px.png" }, + "permissions": [ + "storage", + "scripting" + ], "options_ui": { "page": "options/options.html", "open_in_tab": true - }, - "manifest_version": 2 + } } diff --git a/manifest/safari-manifest-extra.json b/manifest/safari-manifest-extra.json index 1706b2c3..902381c9 100644 --- a/manifest/safari-manifest-extra.json +++ b/manifest/safari-manifest-extra.json @@ -2,9 +2,6 @@ "background": { "persistent": false }, - "permissions": [ - "scripting" - ], "optional_permissions": [ "webNavigation" ] diff --git a/maze-utils b/maze-utils -Subproject 6212c29b9e86c9b06835f44882514fde454b357 +Subproject 42888f800e38213f5e5d79dda953e790ada502e diff --git a/src/background.ts b/src/background.ts index 23914f46..a5a70219 100644 --- a/src/background.ts +++ b/src/background.ts @@ -7,13 +7,9 @@ import { sendRealRequestToCustomServer, setupBackgroundRequestProxy } from "../m import { setupTabUpdates } from "../maze-utils/src/tab-updates"; import { generateUserID } from "../maze-utils/src/setup"; -// Make the config public for debugging purposes - -window.SB = Config; - import Utils from "./utils"; import { getExtensionIdsToImportFrom } from "./utils/crossExtension"; -import { isFirefoxOrSafari } from "../maze-utils/src"; +import { isFirefoxOrSafari, waitFor } from "../maze-utils/src"; import { injectUpdatedScripts } from "../maze-utils/src/cleanup"; import { logWarn } from "./utils/logger"; import { chromeP } from "../maze-utils/src/browserApi"; @@ -142,9 +138,16 @@ chrome.runtime.onInstalled.addListener(function () { } }, 1500); - // Only do this once the old version understands how to clean itself up - if (!isFirefoxOrSafari() && chrome.runtime.getManifest().version !== "5.4.13") { + if (!isFirefoxOrSafari()) { injectUpdatedScripts().catch(logWarn); + + waitFor(() => Config.isReady()).then(() => { + if (Config.config.supportInvidious) { + injectUpdatedScripts([ + utils.getExtraSiteRegistration() + ]) + } + }).catch(logWarn); } }); diff --git a/src/content.ts b/src/content.ts index 2218aa61..fa06b25f 100644 --- a/src/content.ts +++ b/src/content.ts @@ -127,7 +127,7 @@ setupVideoModule({ updateVisibilityOfPlayerControlsButton(); }, resetValues, - documentScript + documentScript: chrome.runtime.getManifest().manifest_version === 2 ? documentScript : undefined }, () => Config); setupThumbnailListener(); diff --git a/src/globals.d.ts b/src/globals.d.ts index aaaab851..b420496a 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -1,19 +1,4 @@ import { SBObject } from "./config"; declare global { interface Window { SB: SBObject } - // Remove this once the API becomes stable and types are shipped in @types/chrome - namespace chrome { - namespace declarativeContent { - export interface RequestContentScriptOptions { - allFrames?: boolean; - css?: string[]; - instanceType?: "declarativeContent.RequestContentScript"; - js?: string[]; - matchAboutBlanck?: boolean; - } - export class RequestContentScript { - constructor(options: RequestContentScriptOptions); - } - } - } } diff --git a/src/utils.ts b/src/utils.ts index 7c3f985e..c1887119 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,7 +2,7 @@ import Config, { VideoDownvotes } from "./config"; import { CategorySelection, SponsorTime, BackgroundScriptContainer, Registration, VideoID, SponsorHideType, CategorySkipOption } from "./types"; import { getHash, HashedValue } from "../maze-utils/src/hash"; -import { isFirefoxOrSafari, waitFor } from "../maze-utils/src"; +import { waitFor } from "../maze-utils/src"; import { findValidElementFromSelector } from "../maze-utils/src/dom"; import { isSafari } from "../maze-utils/src/config"; @@ -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(), diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 2d3a1b92..8e9928b5 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -1,12 +1,22 @@ -window["SBLogs"] = { - debug: [], - warn: [] -}; +if (typeof (window) !== "undefined") { + window["SBLogs"] = { + debug: [], + warn: [] + }; +} export function logDebug(message: string) { - window["SBLogs"].debug.push(`[${new Date().toISOString()}] ${message}`); + if (typeof (window) !== "undefined") { + window["SBLogs"].debug.push(`[${new Date().toISOString()}] ${message}`); + } else { + console.log(`[${new Date().toISOString()}] ${message}`) + } } export function logWarn(message: string) { - window["SBLogs"].warn.push(`[${new Date().toISOString()}] ${message}`); + if (typeof (window) !== "undefined") { + window["SBLogs"].warn.push(`[${new Date().toISOString()}] ${message}`); + } else { + console.warn(`[${new Date().toISOString()}] ${message}`) + } }
\ No newline at end of file diff --git a/webpack/webpack.manifest.js b/webpack/webpack.manifest.js index 3041fe6d..a7a5ffcb 100644 --- a/webpack/webpack.manifest.js +++ b/webpack/webpack.manifest.js @@ -11,6 +11,7 @@ const chromeManifestExtra = require("../manifest/chrome-manifest-extra.json"); const safariManifestExtra = require("../manifest/safari-manifest-extra.json"); const betaManifestExtra = require("../manifest/beta-manifest-extra.json"); const firefoxBetaManifestExtra = require("../manifest/firefox-beta-manifest-extra.json"); +const manifestV2ManifestExtra = require("../manifest/manifest-v2-extra.json"); // schema for options object const schema = { @@ -41,12 +42,14 @@ class BuildManifest { // Add missing manifest elements if (this.options.browser.toLowerCase() === "firefox") { + mergeObjects(manifest, manifestV2ManifestExtra); mergeObjects(manifest, firefoxManifestExtra); } else if (this.options.browser.toLowerCase() === "chrome" || this.options.browser.toLowerCase() === "chromium" || this.options.browser.toLowerCase() === "edge") { mergeObjects(manifest, chromeManifestExtra); } else if (this.options.browser.toLowerCase() === "safari") { + mergeObjects(manifest, manifestV2ManifestExtra); mergeObjects(manifest, safariManifestExtra); } |