LocalCDN-Firefox-Chrome-Brave/modules/internal/permission.js

51 lines
1.6 KiB
JavaScript

/**
* Internal permission Module
* Belongs to LocalCDN (since 2020-02-26)
*
* @author nobody
* @since 2022-12-30
*
* @license MPL 2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
'use strict';
var permission = {};
permission._onDocumentLoaded = function () {
browser.permissions.getAll(({origins}) => {
if (origins.includes('<all_urls>')) {
document.getElementById('div-permission').hidden = true;
document.getElementById('div-content').hidden = false;
} else {
document.getElementById('div-permission').hidden = false;
document.getElementById('div-content').hidden = true;
console.error('[ LocalCDN ] missing permission');
document.getElementById('grant-permission').addEventListener('click', function () {
browser.permissions.request({'origins': ['<all_urls>']});
});
}
});
};
permission._added = function (e) {
if (e.permissions.includes('<all_urls>')) {
document.getElementById('div-permission').hidden = true;
document.getElementById('div-content').hidden = false;
}
};
permission._removed = function () {
document.getElementById('div-permission').hidden = false;
document.getElementById('div-content').hidden = true;
};
browser.permissions.onAdded.addListener(permission._added);
browser.permissions.onRemoved.addListener(permission._removed);
document.addEventListener('DOMContentLoaded', permission._onDocumentLoaded);