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

51 lines
1.6 KiB
JavaScript
Raw Normal View History

/**
* 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}) => {
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 () {
2023-02-09 06:10:56 +01:00
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;
};
2023-02-09 06:10:56 +01:00
browser.permissions.onAdded.addListener(permission._added);
browser.permissions.onRemoved.addListener(permission._removed);
document.addEventListener('DOMContentLoaded', permission._onDocumentLoaded);