mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 01:01:55 +01:00
Support invidious in mv3
This commit is contained in:
parent
a95020dda3
commit
98a4a076bc
7 changed files with 36 additions and 39 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 6212c29b9e86c9b06835f44882514fde454b357e
|
||||
Subproject commit 42888f800e38213f5e5d79dda953e790ada502eb
|
|
@ -9,7 +9,7 @@ import { generateUserID } from "../maze-utils/src/setup";
|
|||
|
||||
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";
|
||||
|
@ -138,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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ setupVideoModule({
|
|||
updateVisibilityOfPlayerControlsButton();
|
||||
},
|
||||
resetValues,
|
||||
documentScript
|
||||
documentScript: chrome.runtime.getManifest().manifest_version === 2 ? documentScript : undefined
|
||||
}, () => Config);
|
||||
setupThumbnailListener();
|
||||
|
||||
|
|
15
src/globals.d.ts
vendored
15
src/globals.d.ts
vendored
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
36
src/utils.ts
36
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(),
|
||||
|
|
|
@ -8,11 +8,15 @@ if (typeof (window) !== "undefined") {
|
|||
export function logDebug(message: string) {
|
||||
if (typeof (window) !== "undefined") {
|
||||
window["SBLogs"].debug.push(`[${new Date().toISOString()}] ${message}`);
|
||||
} else {
|
||||
console.log(`[${new Date().toISOString()}] ${message}`)
|
||||
}
|
||||
}
|
||||
|
||||
export function logWarn(message: string) {
|
||||
if (typeof (window) !== "undefined") {
|
||||
window["SBLogs"].warn.push(`[${new Date().toISOString()}] ${message}`);
|
||||
} else {
|
||||
console.warn(`[${new Date().toISOString()}] ${message}`)
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue