Moved registration removal to a util function.

This commit is contained in:
Ajay Ramachandran 2020-01-09 22:32:20 -05:00
parent 1f4c4c0901
commit a5adf73b88
3 changed files with 30 additions and 29 deletions

View file

@ -192,18 +192,7 @@ function invidiousOnClick(checkbox, option) {
}
});
} else {
if (isFirefox()) {
chrome.runtime.sendMessage({
message: "unregisterContentScript",
id: "invidious"
});
} else {
chrome.declarativeContent.onPageChanged.removeRules(["invidious"]);
}
chrome.permissions.remove({
origins: getInvidiousInstancesRegex()
});
removeExtraSiteRegistration();
}
}

View file

@ -231,7 +231,6 @@ async function runThePopup() {
}
//load video times for this video
console.log( SB.config.sponsorTimes.set)
setTimeout(()=> console.log( SB.config.sponsorTimes.set), 200 )
let sponsorTimesStorage = SB.config.sponsorTimes.get(currentVideoID);
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {

View file

@ -81,21 +81,7 @@ function setupExtraSitePermissions(callback) {
if (granted) {
setupExtraSiteContentScripts();
} else {
if (isFirefox()) {
if (isBackgroundScript) {
if (contentScriptRegistrations[request.id]) {
contentScriptRegistrations[request.id].unregister();
delete contentScriptRegistrations[request.id];
}
} else {
chrome.runtime.sendMessage({
message: "unregisterContentScript",
id: "invidious"
});
}
} else {
chrome.declarativeContent.onPageChanged.removeRules(["invidious"]);
}
removeExtraSiteRegistration();
}
callback(granted);
@ -157,7 +143,7 @@ function setupExtraSiteContentScripts() {
pageUrl: { urlMatches: regex }
}));
}
// Add page rule
let rule = {
id: "invidious",
@ -174,6 +160,33 @@ function setupExtraSiteContentScripts() {
}
}
/**
* Removes the permission and content script registration.
*/
function removeExtraSiteRegistration() {
if (isFirefox()) {
let id = "invidious";
if (isBackgroundScript) {
if (contentScriptRegistrations[id]) {
contentScriptRegistrations[id].unregister();
delete contentScriptRegistrations[id];
}
} else {
chrome.runtime.sendMessage({
message: "unregisterContentScript",
id: id
});
}
} else {
chrome.declarativeContent.onPageChanged.removeRules(["invidious"]);
}
chrome.permissions.remove({
origins: getInvidiousInstancesRegex()
});
}
function localizeHtmlPage() {
//Localize by replacing __MSG_***__ meta tags
var objects = document.getElementsByClassName("sponsorBlockPageBody")[0].children;