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 { } else {
if (isFirefox()) { removeExtraSiteRegistration();
chrome.runtime.sendMessage({
message: "unregisterContentScript",
id: "invidious"
});
} else {
chrome.declarativeContent.onPageChanged.removeRules(["invidious"]);
}
chrome.permissions.remove({
origins: getInvidiousInstancesRegex()
});
} }
} }

View File

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

View File

@@ -81,21 +81,7 @@ function setupExtraSitePermissions(callback) {
if (granted) { if (granted) {
setupExtraSiteContentScripts(); setupExtraSiteContentScripts();
} else { } else {
if (isFirefox()) { removeExtraSiteRegistration();
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"]);
}
} }
callback(granted); callback(granted);
@@ -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() { function localizeHtmlPage() {
//Localize by replacing __MSG_***__ meta tags //Localize by replacing __MSG_***__ meta tags
var objects = document.getElementsByClassName("sponsorBlockPageBody")[0].children; var objects = document.getElementsByClassName("sponsorBlockPageBody")[0].children;