mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-07 12:07:11 +03:00
Merge branch 'master' of https://github.com/ajayyy/SponsorBlock into feat/preview-bar-cleanup
# Conflicts: # src/content.ts # src/js-components/previewBar.ts
This commit is contained in:
24
src/utils.ts
24
src/utils.ts
@@ -54,18 +54,16 @@ class Utils {
|
||||
setupExtraSitePermissions(callback: (granted: boolean) => void): void {
|
||||
// Request permission
|
||||
let permissions = ["declarativeContent"];
|
||||
if (this.isFirefox()) permissions = [];
|
||||
|
||||
const self = this;
|
||||
if (this.isFirefox()) permissions = [];
|
||||
|
||||
chrome.permissions.request({
|
||||
origins: this.getInvidiousInstancesRegex(),
|
||||
permissions: permissions
|
||||
}, async function (granted) {
|
||||
}, async (granted) => {
|
||||
if (granted) {
|
||||
self.setupExtraSiteContentScripts();
|
||||
this.setupExtraSiteContentScripts();
|
||||
} else {
|
||||
self.removeExtraSiteRegistration();
|
||||
this.removeExtraSiteRegistration();
|
||||
}
|
||||
|
||||
callback(granted);
|
||||
@@ -80,7 +78,6 @@ class Utils {
|
||||
* For now, it is just SB.config.invidiousInstances.
|
||||
*/
|
||||
setupExtraSiteContentScripts(): void {
|
||||
const self = this;
|
||||
|
||||
if (this.isFirefox()) {
|
||||
const firefoxJS = [];
|
||||
@@ -107,9 +104,9 @@ class Utils {
|
||||
chrome.runtime.sendMessage(registration);
|
||||
}
|
||||
} else {
|
||||
chrome.declarativeContent.onPageChanged.removeRules(["invidious"], function() {
|
||||
chrome.declarativeContent.onPageChanged.removeRules(["invidious"], () => {
|
||||
const conditions = [];
|
||||
for (const regex of self.getInvidiousInstancesRegex()) {
|
||||
for (const regex of this.getInvidiousInstancesRegex()) {
|
||||
conditions.push(new chrome.declarativeContent.PageStateMatcher({
|
||||
pageUrl: { urlMatches: regex }
|
||||
}));
|
||||
@@ -119,11 +116,10 @@ class Utils {
|
||||
const rule = {
|
||||
id: "invidious",
|
||||
conditions,
|
||||
// This API is experimental and not visible by the TypeScript compiler
|
||||
actions: [new (<any> chrome.declarativeContent).RequestContentScript({
|
||||
actions: [new chrome.declarativeContent.RequestContentScript({
|
||||
allFrames: true,
|
||||
js: self.js,
|
||||
css: self.css
|
||||
js: this.js,
|
||||
css: this.css
|
||||
})]
|
||||
};
|
||||
|
||||
@@ -243,7 +239,7 @@ class Utils {
|
||||
|
||||
getLocalizedMessage(text: string): string | false {
|
||||
const valNewH = text.replace(/__MSG_(\w+)__/g, function(match, v1) {
|
||||
return v1 ? chrome.i18n.getMessage(v1) : "";
|
||||
return v1 ? chrome.i18n.getMessage(v1).replace("\n", "<br/>") : "";
|
||||
});
|
||||
|
||||
if(valNewH != text) {
|
||||
|
||||
Reference in New Issue
Block a user