mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-12 14:37:23 +03:00
Add page for refreshing invidious permissions if it was revoked
Fixes #1354
This commit is contained in:
@@ -107,7 +107,7 @@ chrome.runtime.onMessage.addListener(function (request, _, callback) {
|
||||
chrome.runtime.onInstalled.addListener(function () {
|
||||
// This let's the config sync to run fully before checking.
|
||||
// This is required on Firefox
|
||||
setTimeout(function() {
|
||||
setTimeout(async () => {
|
||||
const userID = Config.config.userID;
|
||||
|
||||
// If there is no userID, then it is the first install.
|
||||
@@ -123,6 +123,12 @@ chrome.runtime.onInstalled.addListener(function () {
|
||||
// Don't show update notification
|
||||
Config.config.categoryPillUpdate = true;
|
||||
}
|
||||
|
||||
if (Config.config.supportInvidious) {
|
||||
if (!(await utils.containsInvidiousPermission())) {
|
||||
chrome.tabs.create({url: chrome.extension.getURL("/permissions/index.html")});
|
||||
}
|
||||
}
|
||||
}, 1500);
|
||||
});
|
||||
|
||||
|
||||
@@ -452,13 +452,7 @@ function invidiousInstanceAddInit(element: HTMLElement, option: string) {
|
||||
* @param option
|
||||
*/
|
||||
function invidiousInit(checkbox: HTMLInputElement, option: string) {
|
||||
let permissions = ["declarativeContent"];
|
||||
if (utils.isFirefox()) permissions = [];
|
||||
|
||||
chrome.permissions.contains({
|
||||
origins: utils.getPermissionRegex(),
|
||||
permissions: permissions
|
||||
}, function (result) {
|
||||
utils.containsInvidiousPermission().then((result) => {
|
||||
if (result != checkbox.checked) {
|
||||
Config.config[option] = result;
|
||||
|
||||
@@ -474,22 +468,8 @@ function invidiousInit(checkbox: HTMLInputElement, option: string) {
|
||||
* @param option
|
||||
*/
|
||||
async function invidiousOnClick(checkbox: HTMLInputElement, option: string): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
if (checkbox.checked) {
|
||||
utils.setupExtraSitePermissions(function (granted) {
|
||||
if (!granted) {
|
||||
Config.config[option] = false;
|
||||
checkbox.checked = false;
|
||||
} else {
|
||||
checkbox.checked = true;
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
} else {
|
||||
utils.removeExtraSiteRegistration();
|
||||
}
|
||||
});
|
||||
const enabled = await utils.applyInvidiousPermissions(checkbox.checked, option);
|
||||
checkbox.checked = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,25 +12,17 @@ window.addEventListener('DOMContentLoaded', init);
|
||||
async function init() {
|
||||
localizeHtmlPage();
|
||||
|
||||
const domains = document.location.hash.replace("#", "").split(",");
|
||||
|
||||
const acceptButton = document.getElementById("acceptPermissionButton");
|
||||
acceptButton.addEventListener("click", () => {
|
||||
chrome.permissions.request({
|
||||
origins: utils.getPermissionRegex(domains),
|
||||
permissions: []
|
||||
}, (granted) => {
|
||||
if (granted) {
|
||||
utils.applyInvidiousPermissions(Config.config.supportInvidious).then((enabled) => {
|
||||
Config.config.supportInvidious = enabled;
|
||||
|
||||
if (enabled) {
|
||||
alert(chrome.i18n.getMessage("permissionRequestSuccess"));
|
||||
|
||||
Config.config.ytInfoPermissionGranted = true;
|
||||
|
||||
chrome.tabs.getCurrent((tab) => {
|
||||
chrome.tabs.remove(tab.id);
|
||||
});
|
||||
window.close();
|
||||
} else {
|
||||
alert(chrome.i18n.getMessage("permissionRequestFailed"));
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
31
src/utils.ts
31
src/utils.ts
@@ -210,6 +210,37 @@ export default class Utils {
|
||||
});
|
||||
}
|
||||
|
||||
applyInvidiousPermissions(enable: boolean, option = "supportInvidious"): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
if (enable) {
|
||||
this.setupExtraSitePermissions((granted) => {
|
||||
if (!granted) {
|
||||
Config.config[option] = false;
|
||||
}
|
||||
|
||||
resolve(granted);
|
||||
});
|
||||
} else {
|
||||
this.removeExtraSiteRegistration();
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
containsInvidiousPermission(): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
let permissions = ["declarativeContent"];
|
||||
if (this.isFirefox()) permissions = [];
|
||||
|
||||
chrome.permissions.contains({
|
||||
origins: this.getPermissionRegex(),
|
||||
permissions: permissions
|
||||
}, function (result) {
|
||||
resolve(result);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges any overlapping timestamp ranges into single segments and returns them as a new array.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user