aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/background.ts17
-rw-r--r--src/content.ts2
-rw-r--r--src/globals.d.ts15
-rw-r--r--src/utils.ts38
-rw-r--r--src/utils/logger.ts22
5 files changed, 45 insertions, 49 deletions
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