mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 19:47:04 +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.sendMessage(tabId, {
|
||||
message: 'update',
|
||||
@@ -6,38 +9,53 @@ chrome.tabs.onUpdated.addListener(function(tabId) {
|
||||
|
||||
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
||||
switch(request.message) {
|
||||
case "submitTimes":
|
||||
submitTimes(request.videoID, callback);
|
||||
case "submitTimes":
|
||||
submitTimes(request.videoID, callback);
|
||||
|
||||
//this allows the callback to be called later by the submitTimes function
|
||||
return true;
|
||||
case "addSponsorTime":
|
||||
addSponsorTime(request.time, request.videoID, callback);
|
||||
//this allows the callback to be called later by the submitTimes function
|
||||
return true;
|
||||
case "addSponsorTime":
|
||||
addSponsorTime(request.time, request.videoID, callback);
|
||||
|
||||
//this allows the callback to be called later
|
||||
return true;
|
||||
case "getSponsorTimes":
|
||||
getSponsorTimes(request.videoID, function(sponsorTimes) {
|
||||
callback({
|
||||
sponsorTimes: sponsorTimes
|
||||
})
|
||||
});
|
||||
//this allows the callback to be called later
|
||||
return true;
|
||||
case "getSponsorTimes":
|
||||
getSponsorTimes(request.videoID, function(sponsorTimes) {
|
||||
callback({
|
||||
sponsorTimes: sponsorTimes
|
||||
})
|
||||
});
|
||||
|
||||
//this allows the callback to be called later
|
||||
return true;
|
||||
case "submitVote":
|
||||
submitVote(request.type, request.UUID, callback);
|
||||
//this allows the callback to be called later
|
||||
return true;
|
||||
case "submitVote":
|
||||
submitVote(request.type, request.UUID, callback);
|
||||
|
||||
//this allows the callback to be called later
|
||||
return true;
|
||||
case "alertPrevious":
|
||||
chrome.notifications.create("stillThere" + Math.random(), {
|
||||
type: "basic",
|
||||
title: chrome.i18n.getMessage("wantToSubmit") + " " + request.previousVideoID + "?",
|
||||
message: chrome.i18n.getMessage("leftTimes"),
|
||||
iconUrl: "./icons/LogoSponsorBlocker256px.png"
|
||||
});
|
||||
}
|
||||
//this allows the callback to be called later
|
||||
return true;
|
||||
case "alertPrevious":
|
||||
chrome.notifications.create("stillThere" + Math.random(), {
|
||||
type: "basic",
|
||||
title: chrome.i18n.getMessage("wantToSubmit") + " " + request.previousVideoID + "?",
|
||||
message: chrome.i18n.getMessage("leftTimes"),
|
||||
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
|
||||
|
||||
@@ -2,7 +2,8 @@ window.addEventListener('DOMContentLoaded', init);
|
||||
|
||||
var invidiousInstancesRegex = [];
|
||||
for (const url of supportedInvidiousInstances) {
|
||||
invidiousInstancesRegex.push("*://*." + url + "/*");
|
||||
invidiousInstancesRegex.push("https://*." + url + "/*");
|
||||
invidiousInstancesRegex.push("http://*." + url + "/*");
|
||||
}
|
||||
|
||||
async function init() {
|
||||
@@ -19,6 +20,7 @@ async function init() {
|
||||
switch (optionsElements[i].getAttribute("option-type")) {
|
||||
case "toggle":
|
||||
let option = optionsElements[i].getAttribute("sync-option");
|
||||
|
||||
chrome.storage.sync.get([option], function(result) {
|
||||
let optionResult = result[option];
|
||||
let checkbox = optionsElements[i].querySelector("input");
|
||||
@@ -141,7 +143,9 @@ function invidiousOnClick(checkbox, option) {
|
||||
firefoxCSS.push({file});
|
||||
}
|
||||
|
||||
let registration = await browser.contentScripts.register({
|
||||
chrome.runtime.sendMessage({
|
||||
message: "registerContentScript",
|
||||
id: "invidious",
|
||||
allFrames: true,
|
||||
js: firefoxJS,
|
||||
css: firefoxCSS,
|
||||
@@ -178,7 +182,10 @@ function invidiousOnClick(checkbox, option) {
|
||||
});
|
||||
} else {
|
||||
if (isFirefox()) {
|
||||
// Nothing for now
|
||||
chrome.runtime.sendMessage({
|
||||
message: "unregisterContentScript",
|
||||
id: "invidious"
|
||||
});
|
||||
} else {
|
||||
chrome.declarativeContent.onPageChanged.removeRules(["invidious"]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user