2022-12-30 08:07:11 +01:00
|
|
|
/**
|
|
|
|
* 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 () {
|
2023-02-09 06:10:56 +01:00
|
|
|
browser.permissions.getAll(({origins}) => {
|
2022-12-30 08:07:11 +01:00
|
|
|
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;
|
2022-12-30 08:13:40 +01:00
|
|
|
console.error('[ LocalCDN ] missing permission');
|
2022-12-30 08:07:11 +01:00
|
|
|
document.getElementById('grant-permission').addEventListener('click', function () {
|
2023-02-09 06:10:56 +01:00
|
|
|
browser.permissions.request({'origins': ['<all_urls>']});
|
2022-12-30 08:07:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2023-02-09 06:10:56 +01:00
|
|
|
browser.permissions.onAdded.addListener(permission._added);
|
|
|
|
browser.permissions.onRemoved.addListener(permission._removed);
|
2022-12-30 08:07:11 +01:00
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', permission._onDocumentLoaded);
|