Compare commits

...

7 Commits

Author SHA1 Message Date
Ajay
0cdfd68239 bump version 2023-02-07 17:42:38 -05:00
Ajay
bbb234e498 Make invidious instances work on safari 2023-02-07 17:42:22 -05:00
Ajay Ramachandran
3716c8aa80 chrome limitation gone 2023-02-07 02:54:06 -05:00
Ajay
92e156834b Use pollyfill for invidious registration
Fix #798
2023-02-06 21:22:34 -05:00
Ajay
b2e6e4f076 Fix tests 2023-02-01 19:55:01 -05:00
Ajay
6348bdccde bump version 2023-02-01 19:51:50 -05:00
Ajay
c3213eb040 Add invidious instances by default for safari
https://github.com/ajayyy/SponsorBlock/issues/798
2023-02-01 19:48:24 -05:00
10 changed files with 151 additions and 76 deletions

View File

@@ -1,7 +1,7 @@
{
"name": "__MSG_fullName__",
"short_name": "SponsorBlock",
"version": "5.1.13",
"version": "5.2.0",
"default_locale": "en",
"description": "__MSG_Description__",
"homepage_url": "https://sponsor.ajay.app",
@@ -84,7 +84,8 @@
"https://sponsor.ajay.app/*"
],
"optional_permissions": [
"*://*/*"
"*://*/*",
"webNavigation"
],
"browser_action": {
"default_title": "SponsorBlock",

95
package-lock.json generated
View File

@@ -28,6 +28,7 @@
"license": "LGPL-3.0-or-later",
"dependencies": {
"@ajayyy/maze-utils": "^1.0.3",
"content-scripts-register-polyfill": "^4.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
@@ -4286,6 +4287,19 @@
"url": "https://github.com/yeoman/configstore?sponsor=1"
}
},
"node_modules/content-scripts-register-polyfill": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/content-scripts-register-polyfill/-/content-scripts-register-polyfill-4.0.2.tgz",
"integrity": "sha512-8hDm+tu3BkxHZP7EUIIIo/495F6QNXF7cI9Lwr4PQaiohw2wWmi9k2SE4W4kNrAaLnFw6RZ2ev8EmrQb+sCoGQ==",
"dependencies": {
"webext-content-scripts": "^2.5.2",
"webext-patterns": "^1.3.0",
"webext-polyfill-kinda": "^1.0.0"
},
"funding": {
"url": "https://github.com/sponsors/fregante"
}
},
"node_modules/convert-source-map": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.8.0.tgz",
@@ -12811,6 +12825,48 @@
"node": ">= 8"
}
},
"node_modules/webext-content-scripts": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/webext-content-scripts/-/webext-content-scripts-2.5.2.tgz",
"integrity": "sha512-N1Xq/E8dx0lVAOyPquuo+2Vj9Fx1GoqCFo79lWeJHbemaBJ53N3BHBmbJJYsQ8FOP1xiwN4bPRQY2dpSjHAD3Q==",
"dependencies": {
"webext-patterns": "^1.3.0",
"webext-polyfill-kinda": "^1.0.0"
},
"funding": {
"url": "https://github.com/sponsors/fregante"
}
},
"node_modules/webext-patterns": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/webext-patterns/-/webext-patterns-1.3.0.tgz",
"integrity": "sha512-X9HMnic9ZtvSFKi2cdh0l+sxyj7f9oLedaa2JfxjnyEqGBz8OJjaHQ40jmraX1DJLTHOpqr+rCz1r3MW2+doUg==",
"dependencies": {
"escape-string-regexp": "^5.0.0"
},
"funding": {
"url": "https://github.com/sponsors/fregante"
}
},
"node_modules/webext-patterns/node_modules/escape-string-regexp": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz",
"integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/webext-polyfill-kinda": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/webext-polyfill-kinda/-/webext-polyfill-kinda-1.0.0.tgz",
"integrity": "sha512-Py/d3w/bC0KntuO60ePSWHsdrebZ3uYBLeFUjyPkDV3yTEQib0MRFvPh57t8XjImu4ylBoEAsFjzh/r22UtxMw==",
"funding": {
"url": "https://github.com/sponsors/fregante"
}
},
"node_modules/webidl-conversions": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz",
@@ -16550,6 +16606,16 @@
"xdg-basedir": "^5.0.1"
}
},
"content-scripts-register-polyfill": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/content-scripts-register-polyfill/-/content-scripts-register-polyfill-4.0.2.tgz",
"integrity": "sha512-8hDm+tu3BkxHZP7EUIIIo/495F6QNXF7cI9Lwr4PQaiohw2wWmi9k2SE4W4kNrAaLnFw6RZ2ev8EmrQb+sCoGQ==",
"requires": {
"webext-content-scripts": "^2.5.2",
"webext-patterns": "^1.3.0",
"webext-polyfill-kinda": "^1.0.0"
}
},
"convert-source-map": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.8.0.tgz",
@@ -22820,6 +22886,35 @@
"integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==",
"dev": true
},
"webext-content-scripts": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/webext-content-scripts/-/webext-content-scripts-2.5.2.tgz",
"integrity": "sha512-N1Xq/E8dx0lVAOyPquuo+2Vj9Fx1GoqCFo79lWeJHbemaBJ53N3BHBmbJJYsQ8FOP1xiwN4bPRQY2dpSjHAD3Q==",
"requires": {
"webext-patterns": "^1.3.0",
"webext-polyfill-kinda": "^1.0.0"
}
},
"webext-patterns": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/webext-patterns/-/webext-patterns-1.3.0.tgz",
"integrity": "sha512-X9HMnic9ZtvSFKi2cdh0l+sxyj7f9oLedaa2JfxjnyEqGBz8OJjaHQ40jmraX1DJLTHOpqr+rCz1r3MW2+doUg==",
"requires": {
"escape-string-regexp": "^5.0.0"
},
"dependencies": {
"escape-string-regexp": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz",
"integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw=="
}
}
},
"webext-polyfill-kinda": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/webext-polyfill-kinda/-/webext-polyfill-kinda-1.0.0.tgz",
"integrity": "sha512-Py/d3w/bC0KntuO60ePSWHsdrebZ3uYBLeFUjyPkDV3yTEQib0MRFvPh57t8XjImu4ylBoEAsFjzh/r22UtxMw=="
},
"webidl-conversions": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz",

View File

@@ -4,9 +4,10 @@
"description": "",
"main": "background.js",
"dependencies": {
"@ajayyy/maze-utils": "^1.0.3",
"content-scripts-register-polyfill": "^4.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"@ajayyy/maze-utils": "^1.0.3"
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/chrome": "^0.0.199",

View File

@@ -442,7 +442,7 @@
"message": "Support 3rd Party YouTube-Sites"
},
"supportOtherSitesDescription": {
"message": "Support third party YouTube clients. To enable support, you must accept the extra permissions. This does NOT work in incognito on Chrome and other Chromium variants.",
"message": "Support third party YouTube clients. To enable support, you must accept the extra permissions.",
"description": "This replaces the 'supports Invidious' option because it now works on other YouTube sites such as Cloudtube"
},
"supportedSites": {

View File

@@ -442,7 +442,7 @@
<div id="advanced" class="option-group hidden">
<div id="support-invidious" data-type="toggle" data-sync="supportInvidious" data-no-safari="true">
<div id="support-invidious" data-type="toggle" data-sync="supportInvidious">
<div class="switch-container">
<label class="switch">
<input id="supportInvidious" type="checkbox">
@@ -457,7 +457,7 @@
<div class="small-description">__MSG_supportOtherSitesDescription__ </div>
</div>
<div data-type="private-text-change" data-sync="invidiousInstances" data-no-safari="true" data-dependent-on="supportInvidious">
<div data-type="private-text-change" data-sync="invidiousInstances" data-dependent-on="supportInvidious">
<div class="option-button trigger-button">
__MSG_addInvidiousInstance__
</div>

View File

@@ -2,6 +2,7 @@ import * as CompileConfig from "../config.json";
import Config from "./config";
import { Registration } from "./types";
import registerContentScript from 'content-scripts-register-polyfill/ponyfill.js';
// Make the config public for debugging purposes
@@ -20,11 +21,9 @@ const popupPort: Record<string, chrome.runtime.Port> = {};
const contentScriptRegistrations = {};
// Register content script if needed
if (utils.isFirefox()) {
utils.wait(() => Config.config !== null).then(function() {
if (Config.config.supportInvidious) utils.setupExtraSiteContentScripts();
});
}
utils.wait(() => Config.config !== null).then(function() {
if (Config.config.supportInvidious) utils.setupExtraSiteContentScripts();
});
function onTabUpdatedListener(tabId: number) {
chrome.tabs.sendMessage(tabId, {
@@ -167,7 +166,7 @@ function registerFirefoxContentScript(options: Registration) {
const oldRegistration = contentScriptRegistrations[options.id];
if (oldRegistration) oldRegistration.unregister();
browser.contentScripts.register({
registerContentScript({
allFrames: options.allFrames,
js: options.js,
css: options.css,
@@ -181,8 +180,10 @@ function registerFirefoxContentScript(options: Registration) {
*
*/
function unregisterFirefoxContentScript(id: string) {
contentScriptRegistrations[id].unregister();
delete contentScriptRegistrations[id];
if (contentScriptRegistrations[id]) {
contentScriptRegistrations[id].unregister();
delete contentScriptRegistrations[id];
}
}
async function submitVote(type: number, UUID: string, category: string) {

View File

@@ -1,7 +1,7 @@
import * as CompileConfig from "../config.json";
import * as invidiousList from "../ci/invidiouslist.json";
import { Category, CategorySelection, CategorySkipOption, NoticeVisbilityMode, PreviewBarOption, SponsorTime, StorageChangesObject, Keybind, HashedValue, VideoID, SponsorHideType } from "./types";
import { keybindEquals } from "./utils/configUtils";
import { isSafari, keybindEquals } from "./utils/configUtils";
export interface Permission {
canSubmit: boolean;
@@ -550,7 +550,8 @@ function migrateOldSyncFormats(config: SBConfig) {
}
// populate invidiousInstances with new instances if 3p support is **DISABLED**
if (!config["supportInvidious"] && config["invidiousInstances"].length !== invidiousList.length) {
// for safari, update it immediately
if ((isSafari() || !config["supportInvidious"]) && config["invidiousInstances"].length !== invidiousList.length) {
config["invidiousInstances"] = invidiousList;
}

View File

@@ -4,6 +4,7 @@ import { CategorySelection, SponsorTime, FetchResponse, BackgroundScriptContaine
import * as CompileConfig from "../config.json";
import { findValidElement, findValidElementFromSelector } from "./utils/pageUtils";
import { waitFor } from "@ajayyy/maze-utils";
import { isSafari } from "./utils/configUtils";
export default class Utils {
@@ -118,9 +119,9 @@ export default class Utils {
* @param {CallableFunction} callback
*/
setupExtraSitePermissions(callback: (granted: boolean) => void): void {
// Request permission
let permissions = ["declarativeContent"];
if (this.isFirefox()) permissions = [];
let permissions = ["webNavigation"];
if (!isSafari()) permissions.push("declarativeContent");
if (this.isFirefox() && !isSafari()) permissions = [];
chrome.permissions.request({
origins: this.getPermissionRegex(),
@@ -144,52 +145,28 @@ export default class Utils {
* For now, it is just SB.config.invidiousInstances.
*/
setupExtraSiteContentScripts(): void {
if (this.isFirefox()) {
const firefoxJS = [];
for (const file of this.js) {
firefoxJS.push({file});
}
const firefoxCSS = [];
for (const file of this.css) {
firefoxCSS.push({file});
}
const firefoxJS = [];
for (const file of this.js) {
firefoxJS.push({file});
}
const firefoxCSS = [];
for (const file of this.css) {
firefoxCSS.push({file});
}
const registration: Registration = {
message: "registerContentScript",
id: "invidious",
allFrames: true,
js: firefoxJS,
css: firefoxCSS,
matches: this.getPermissionRegex()
};
const registration: Registration = {
message: "registerContentScript",
id: "invidious",
allFrames: true,
js: firefoxJS,
css: firefoxCSS,
matches: this.getPermissionRegex()
};
if (this.backgroundScriptContainer) {
this.backgroundScriptContainer.registerFirefoxContentScript(registration);
} else {
chrome.runtime.sendMessage(registration);
}
if (this.backgroundScriptContainer) {
this.backgroundScriptContainer.registerFirefoxContentScript(registration);
} else {
chrome.declarativeContent.onPageChanged.removeRules(["invidious"], () => {
const conditions = [];
for (const regex of this.getPermissionRegex()) {
conditions.push(new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlMatches: regex }
}));
}
// Add page rule
const rule = {
id: "invidious",
conditions,
actions: [new chrome.declarativeContent.RequestContentScript({
allFrames: true,
js: this.js,
css: this.css
})]
};
chrome.declarativeContent.onPageChanged.addRules([rule]);
});
chrome.runtime.sendMessage(registration);
}
}
@@ -197,18 +174,18 @@ export default class Utils {
* Removes the permission and content script registration.
*/
removeExtraSiteRegistration(): void {
if (this.isFirefox()) {
const id = "invidious";
const id = "invidious";
if (this.backgroundScriptContainer) {
this.backgroundScriptContainer.unregisterFirefoxContentScript(id);
} else {
chrome.runtime.sendMessage({
message: "unregisterContentScript",
id: id
});
}
} else if (chrome.declarativeContent) {
if (this.backgroundScriptContainer) {
this.backgroundScriptContainer.unregisterFirefoxContentScript(id);
} else {
chrome.runtime.sendMessage({
message: "unregisterContentScript",
id: id
});
}
if (!this.isFirefox() && chrome.declarativeContent) {
// Only if we have permission
chrome.declarativeContent.onPageChanged.removeRules(["invidious"]);
}

View File

@@ -6,7 +6,7 @@ export function showDonationLink(): boolean {
}
export function isSafari(): boolean {
return navigator.vendor === "Apple Computer, Inc.";
return typeof(navigator) !== "undefined" && navigator.vendor === "Apple Computer, Inc.";
}
export function keybindEquals(first: Keybind, second: Keybind): boolean {

View File

@@ -3,7 +3,6 @@
const webpack = require("webpack");
const path = require('path');
const { validate } = require('schema-utils');
const fs = require('fs');
const manifest = require("../manifest/manifest.json");