diff --git a/options/options.js b/options/options.js index 837cfe18..d2f3b440 100644 --- a/options/options.js +++ b/options/options.js @@ -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(); } } diff --git a/popup.js b/popup.js index cd3cf7b5..9e9ccaeb 100644 --- a/popup.js +++ b/popup.js @@ -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) { diff --git a/utils.js b/utils.js index 0b7ca6ad..3ded0c96 100644 --- a/utils.js +++ b/utils.js @@ -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;