Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
dom.innerHTML = `<strong>${k}</strong> - ${TogglOrigins[customs[k]].name}`;
li.appendChild(dom);
dom = document.createElement('a');
dom.className = 'remove-custom';
dom.textContent = 'delete';
li.appendChild(dom);
customHtml.appendChild(li);
}
}
replaceContent('#custom-perm-container', customHtml);
// Load permissions list
browser.permissions.getAll().then(function (results) {
let key;
try {
Settings.origins = [];
origins = results.origins;
for (i = 0; i < origins.length; i++) {
name = url = origins[i]
.replace('*://*.', '')
.replace('*://', '')
.replace('/*', '');
if (url.split('.').length > 2) {
name = url.substr(url.indexOf('.') + 1);
}
Settings.origins[name] = {
id: i,
origin: origins[i],
toggleOrigin: function (e) {
let target = e.target;
if (e.target.tagName !== 'INPUT') {
target = e.target.querySelector('input');
if (!target) target = e.target.parentElement.querySelector('input');
target.checked = !target.checked;
}
const permission = { origins: target.getAttribute('data-host').split(',') };
if (target.checked) {
browser.permissions.request(permission).then(function (result) {
if (result) {
target.parentNode.classList.remove('disabled');
} else {
target.checked = false;
}
});
} else {
browser.permissions.contains(permission).then(function (allowed) {
if (allowed) {
browser.permissions.remove(permission).then(function (result) {
if (result) {
target.parentNode.classList.add('disabled');
} else {
target.checked = true;
}
});
requestPermissions() {
if (navigator.userAgent.indexOf('Chrome') > -1) {
browser.permissions.request(permissions).then(granted => {
if (!granted) {
return;
}
this.create();
})
} else {
const width = 440;
const height = 220;
const left = Math.floor(screen.width / 2 - width / 2);
const top = Math.floor(screen.height / 2 - height / 2);
browser.windows.create({
url: browser.extension.getURL("prompt.html"),
type: 'popup',
export const checkPermission = async permission => {
if (await browser.permissions.contains({permissions: [permission]})) return true
return browser.permissions.request({permissions: [permission]})
}
export const readFile = file => new Promise((resolve, reject) => {
export const checkPermission = async permission => {
if (await browser.permissions.contains({permissions: [permission]})) return true
return browser.permissions.request({permissions: [permission]})
}
export const readFile = file => new Promise((resolve, reject) => {
browser.permissions.contains(permission).then(function (allowed) {
if (allowed) {
browser.permissions.remove(permission).then(function (result) {
if (result) {
removed = true;
db.removeOrigin(custom);
parent.remove();
} else {
alert('Fail');
}
});
} else {
alert('No "' + custom + '" host permission found.');
}
});
add() {
if (!this.$refs.form.validate()) {
return;
}
browser.permissions.contains(permissions).then(yes => {
if (yes) {
return this.create();
}
this.requestPermissions();
})
},
async create() {
removeCustomOrigin: function (e) {
let custom;
let domain;
let permission;
let parent;
let removed = false;
if (e.target.className === 'remove-custom') {
parent = e.target.parentNode;
custom = parent.querySelector('strong').textContent;
domain = '*://' + custom + '/';
permission = { origins: [domain] };
browser.permissions.contains(permission).then(function (allowed) {
if (allowed) {
browser.permissions.remove(permission).then(function (result) {
if (result) {
removed = true;
db.removeOrigin(custom);
parent.remove();
} else {
alert('Fail');
}
});
} else {
alert('No "' + custom + '" host permission found.');
}
});
if (!removed) {