From 404a33b91fc03a91828a72af698df39a7d16c169 Mon Sep 17 00:00:00 2001 From: HanYaodong Date: Fri, 12 Apr 2024 23:02:22 +0800 Subject: [PATCH] Update Chrome Manifest to v3 --- manifest/chrome-manifest-extra.json | 128 ++++++++++++++++++++++- manifest/firefox-manifest-extra.json | 134 +++++++++++++++++++++--- manifest/manifest.json | 148 +++------------------------ maze-utils | 2 +- package-lock.json | 14 +-- src/background.ts | 10 +- webpack/webpack.common.js | 8 +- 7 files changed, 271 insertions(+), 173 deletions(-) diff --git a/manifest/chrome-manifest-extra.json b/manifest/chrome-manifest-extra.json index e56748d6..7e20356c 100644 --- a/manifest/chrome-manifest-extra.json +++ b/manifest/chrome-manifest-extra.json @@ -1,12 +1,132 @@ { + "manifest_version": 3, + "permissions": [ + "storage", + "scripting" + ], "optional_permissions": [ "declarativeContent", "webNavigation" ], + "host_permissions": [ + "https://*.bilibili.com/*", + "http://47.103.74.95:9876/*" + ], + "optional_host_permissions": [ + "*://*/*" + ], "background": { - "persistent": false + "service_worker": "./js/background.js", + "type": "module" }, - "permissions": [ - "https://*.bilibili.com/*" + "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 + } + ] + }, + "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", + "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": [ + "*://*/*" + ] + } ] -} +} \ No newline at end of file diff --git a/manifest/firefox-manifest-extra.json b/manifest/firefox-manifest-extra.json index 9f9468bc..11915465 100644 --- a/manifest/firefox-manifest-extra.json +++ b/manifest/firefox-manifest-extra.json @@ -1,20 +1,128 @@ { + "manifest_version": 2, + "permissions": [ + "storage", + "scripting", + "https://*.bilibili.com/*", + "http://47.103.74.95:9876/*" + ], + "optional_permissions": [ + "*://*/*" + ], + "background": { + "scripts": [ + "./js/background.js" + ], + "persistent": false + }, + "browser_action": { + "default_title": "SponsorBlock", + "default_area": "navbar", + "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 + } + ] + }, + "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", + "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" + ], "browser_specific_settings": { "gecko": { "id": "sponsorBlocker@ajay.app", "strict_min_version": "56.0" - }, - "gecko_android": { - "strict_min_version": "113.0" } - }, - "background": { - "persistent": false - }, - "permissions": [ - "scripting" - ], - "browser_action": { - "default_area": "navbar" } -} +} \ No newline at end of file diff --git a/manifest/manifest.json b/manifest/manifest.json index fcd3783a..10279df5 100644 --- a/manifest/manifest.json +++ b/manifest/manifest.json @@ -4,135 +4,22 @@ "version": "0.1.0", "default_locale": "zh_CN", "description": "__MSG_Description__", - "content_scripts": [{ - "run_at": "document_start", - "matches": [ - "https://*.bilibili.com/*" - ], - "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", - "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" + "content_scripts": [ + { + "run_at": "document_start", + "matches": [ + "https://*.bilibili.com/*" + ], + "all_frames": true, + "js": [ + "./js/content.js" + ], + "css": [ + "content.css", + "shared.css" + ] + } ], - "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", @@ -145,6 +32,5 @@ "options_ui": { "page": "options/options.html", "open_in_tab": true - }, - "manifest_version": 2 -} + } +} \ No newline at end of file diff --git a/maze-utils b/maze-utils index b050c4fa..bdea5808 160000 --- a/maze-utils +++ b/maze-utils @@ -1 +1 @@ -Subproject commit b050c4fad91e1ff17b3c45ac8668019f82ea69c9 +Subproject commit bdea58085dec738a0ebc1b07ce1438ddfef6b87f diff --git a/package-lock.json b/package-lock.json index 19c07108..aedbb880 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,21 +8,9 @@ "name": "bilibilisponsorblock", "version": "0.1.0", "funding": [ - { - "type": "individual", - "url": "https://sponsor.ajay.app/donate" - }, - { - "type": "github", - "url": "https://github.com/sponsors/ajayyy-org" - }, { "type": "patreon", - "url": "https://www.patreon.com/ajayyy" - }, - { - "type": "individual", - "url": "https://paypal.me/ajayyy" + "url": "https://www.patreon.com/hanyd" } ], "license": "GPL-3.0", diff --git a/src/background.ts b/src/background.ts index 97aa3f9f..6b4958eb 100644 --- a/src/background.ts +++ b/src/background.ts @@ -6,11 +6,6 @@ import "content-scripts-register-polyfill"; import { sendRealRequestToCustomServer, setupBackgroundRequestProxy } from "../maze-utils/src/background-request-proxy"; 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 { isFirefoxOrSafari } from "../maze-utils/src"; import { injectUpdatedScripts } from "../maze-utils/src/cleanup"; @@ -129,7 +124,8 @@ chrome.runtime.onInstalled.addListener(function () { // Only do this once the old version understands how to clean itself up if (!isFirefoxOrSafari() && chrome.runtime.getManifest().version !== "5.4.13") { - injectUpdatedScripts().catch(logWarn); + // TODO: Add logging back on error + injectUpdatedScripts().catch(); } }); @@ -245,4 +241,4 @@ async function asyncRequestToServer(type: string, address: string, data = {}) { const serverAddress = Config.config.testingServer ? CompileConfig.testingServerAddress : Config.config.serverAddress; return await (sendRealRequestToCustomServer(type, serverAddress + address, data)); -} \ No newline at end of file +} diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index 189681c6..f9366627 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -63,8 +63,8 @@ module.exports = env => { currentWatching = null; /** - * - * @param {webpack.Compiler} compiler + * + * @param {webpack.Compiler} compiler */ apply(compiler) { compiler.hooks.beforeCompile.tapAsync({ name: 'DocumentScriptCompiler' }, (compiler, callback) => { @@ -143,7 +143,7 @@ module.exports = env => { context: './public', filter: async (path) => { if (path.match(/(\/|\\)_locales(\/|\\).+/)) { - if (env.browser.toLowerCase() === "edge" + if (env.browser.toLowerCase() === "edge" && !edgeLanguages.includes(path.match(/(?<=\/_locales\/)[^/]+(?=\/[^/]+$)/)[0])) { return false; } @@ -170,7 +170,7 @@ module.exports = env => { parsed.Description.message = parsed.Description.message.slice(0, 77) + "..."; } } - + return Buffer.from(JSON.stringify(parsed)); }