mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2026-01-28 05:10:50 +03:00
Moved registration removal to a util function.
This commit is contained in:
45
utils.js
45
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;
|
||||
|
||||
Reference in New Issue
Block a user