mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 12:37:05 +03:00
Fixed firefox support.
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
// Used only on Firefox, which does not support non persistent background pages.
|
||||||
|
var contentScriptRegistrations = {};
|
||||||
|
|
||||||
chrome.tabs.onUpdated.addListener(function(tabId) {
|
chrome.tabs.onUpdated.addListener(function(tabId) {
|
||||||
chrome.tabs.sendMessage(tabId, {
|
chrome.tabs.sendMessage(tabId, {
|
||||||
message: 'update',
|
message: 'update',
|
||||||
@@ -37,7 +40,22 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
|||||||
message: chrome.i18n.getMessage("leftTimes"),
|
message: chrome.i18n.getMessage("leftTimes"),
|
||||||
iconUrl: "./icons/LogoSponsorBlocker256px.png"
|
iconUrl: "./icons/LogoSponsorBlocker256px.png"
|
||||||
});
|
});
|
||||||
}
|
return false;
|
||||||
|
case "registerContentScript":
|
||||||
|
browser.contentScripts.register({
|
||||||
|
allFrames: request.allFrames,
|
||||||
|
js: request.js,
|
||||||
|
css: request.css,
|
||||||
|
matches: request.matches
|
||||||
|
}).then(() => void (contentScriptRegistrations[request.id] = registration));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
case "unregisterContentScript":
|
||||||
|
contentScriptRegistrations[request.id].unregister();
|
||||||
|
delete contentScriptRegistrations[request.id];
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//add help page on install
|
//add help page on install
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ window.addEventListener('DOMContentLoaded', init);
|
|||||||
|
|
||||||
var invidiousInstancesRegex = [];
|
var invidiousInstancesRegex = [];
|
||||||
for (const url of supportedInvidiousInstances) {
|
for (const url of supportedInvidiousInstances) {
|
||||||
invidiousInstancesRegex.push("*://*." + url + "/*");
|
invidiousInstancesRegex.push("https://*." + url + "/*");
|
||||||
|
invidiousInstancesRegex.push("http://*." + url + "/*");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
@@ -19,6 +20,7 @@ async function init() {
|
|||||||
switch (optionsElements[i].getAttribute("option-type")) {
|
switch (optionsElements[i].getAttribute("option-type")) {
|
||||||
case "toggle":
|
case "toggle":
|
||||||
let option = optionsElements[i].getAttribute("sync-option");
|
let option = optionsElements[i].getAttribute("sync-option");
|
||||||
|
|
||||||
chrome.storage.sync.get([option], function(result) {
|
chrome.storage.sync.get([option], function(result) {
|
||||||
let optionResult = result[option];
|
let optionResult = result[option];
|
||||||
let checkbox = optionsElements[i].querySelector("input");
|
let checkbox = optionsElements[i].querySelector("input");
|
||||||
@@ -141,7 +143,9 @@ function invidiousOnClick(checkbox, option) {
|
|||||||
firefoxCSS.push({file});
|
firefoxCSS.push({file});
|
||||||
}
|
}
|
||||||
|
|
||||||
let registration = await browser.contentScripts.register({
|
chrome.runtime.sendMessage({
|
||||||
|
message: "registerContentScript",
|
||||||
|
id: "invidious",
|
||||||
allFrames: true,
|
allFrames: true,
|
||||||
js: firefoxJS,
|
js: firefoxJS,
|
||||||
css: firefoxCSS,
|
css: firefoxCSS,
|
||||||
@@ -178,7 +182,10 @@ function invidiousOnClick(checkbox, option) {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (isFirefox()) {
|
if (isFirefox()) {
|
||||||
// Nothing for now
|
chrome.runtime.sendMessage({
|
||||||
|
message: "unregisterContentScript",
|
||||||
|
id: "invidious"
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
chrome.declarativeContent.onPageChanged.removeRules(["invidious"]);
|
chrome.declarativeContent.onPageChanged.removeRules(["invidious"]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user