mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 01:01:55 +01:00
Moved registration removal to a util function.
This commit is contained in:
parent
1f4c4c0901
commit
a5adf73b88
3 changed files with 30 additions and 29 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
1
popup.js
1
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) {
|
||||
|
|
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;
|
||||
|
|
Loading…
Reference in a new issue