mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 04:27:15 +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',
|
||||||
@@ -6,38 +9,53 @@ chrome.tabs.onUpdated.addListener(function(tabId) {
|
|||||||
|
|
||||||
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
||||||
switch(request.message) {
|
switch(request.message) {
|
||||||
case "submitTimes":
|
case "submitTimes":
|
||||||
submitTimes(request.videoID, callback);
|
submitTimes(request.videoID, callback);
|
||||||
|
|
||||||
//this allows the callback to be called later by the submitTimes function
|
//this allows the callback to be called later by the submitTimes function
|
||||||
return true;
|
return true;
|
||||||
case "addSponsorTime":
|
case "addSponsorTime":
|
||||||
addSponsorTime(request.time, request.videoID, callback);
|
addSponsorTime(request.time, request.videoID, callback);
|
||||||
|
|
||||||
//this allows the callback to be called later
|
//this allows the callback to be called later
|
||||||
return true;
|
return true;
|
||||||
case "getSponsorTimes":
|
case "getSponsorTimes":
|
||||||
getSponsorTimes(request.videoID, function(sponsorTimes) {
|
getSponsorTimes(request.videoID, function(sponsorTimes) {
|
||||||
callback({
|
callback({
|
||||||
sponsorTimes: sponsorTimes
|
sponsorTimes: sponsorTimes
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
//this allows the callback to be called later
|
//this allows the callback to be called later
|
||||||
return true;
|
return true;
|
||||||
case "submitVote":
|
case "submitVote":
|
||||||
submitVote(request.type, request.UUID, callback);
|
submitVote(request.type, request.UUID, callback);
|
||||||
|
|
||||||
//this allows the callback to be called later
|
//this allows the callback to be called later
|
||||||
return true;
|
return true;
|
||||||
case "alertPrevious":
|
case "alertPrevious":
|
||||||
chrome.notifications.create("stillThere" + Math.random(), {
|
chrome.notifications.create("stillThere" + Math.random(), {
|
||||||
type: "basic",
|
type: "basic",
|
||||||
title: chrome.i18n.getMessage("wantToSubmit") + " " + request.previousVideoID + "?",
|
title: chrome.i18n.getMessage("wantToSubmit") + " " + request.previousVideoID + "?",
|
||||||
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
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
"permissions": [
|
"permissions": [
|
||||||
"storage",
|
"storage",
|
||||||
"notifications",
|
"notifications",
|
||||||
"https://sponsor.ajay.app/*"
|
"https://sponsor.ajay.app/*"
|
||||||
],
|
],
|
||||||
"optional_permissions": [
|
"optional_permissions": [
|
||||||
"*://*/*",
|
"*://*/*",
|
||||||
|
|||||||
@@ -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