Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"build": "npm run build:chrome && npm run build:firefox",
"prettier:check": "npx prettier --check .",
"prettier:write": "npx prettier --write .",
"actionlint": "actionlint",
"yamllint": "yamllint -c .github/yamllint.yaml ."
},
"dependencies": {
Expand Down
37 changes: 10 additions & 27 deletions src/js/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@
export async function copyInput(event) {
console.debug('copyInput:', event)
const el = event.currentTarget || event.target.closest('button')
console.debug('el.dataset.copyInput:', el.dataset.copyInput)
const input = document.querySelector(el.dataset.copyInput)
console.debug('input:', input)
if (!input.value) {
Expand All @@ -150,7 +149,7 @@
* @function saveOptions
* @param {UIEvent} event
*/
export async function saveOptions(event) {

Check failure on line 152 in src/js/export.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=cssnr_auto-auth&issues=AZzFjj9CTzgRrYV1fVev&open=AZzFjj9CTzgRrYV1fVev&pullRequest=15
console.debug('saveOptions:', event)
const { options } = await chrome.storage.sync.get(['options'])
let key = event.target.id
Expand Down Expand Up @@ -180,8 +179,11 @@
} else {
value = event.target.value
}

if (value === undefined) {
console.warn(`No Value for key: ${key}`)
console.warn(`No value for key: ${key}`)
} else if (value === options[key]) {
console.log(`No value change for key: ${key}:`, value)
} else {
options[key] = value
console.log(`Set %c${key}:`, 'color: Khaki', value)
Expand Down Expand Up @@ -222,7 +224,6 @@
hideShowElement(`#${el.dataset.related}`, value)
}
if (el.dataset.warning) {
// addWarningClass(el.nextElementSibling, value, el.dataset.warning)
el.nextElementSibling.classList.toggle(el.dataset.warning, !!value)
}
}
Expand All @@ -245,27 +246,11 @@
}
}

// /**
// * Add Warning Class to Element
// * @function addWarningClass
// * @param {HTMLElement} element
// * @param {Boolean} value
// * @param {String} warning
// */
// function addWarningClass(element, value, warning) {
// // console.debug('addWarningClass:', value, element)
// if (value) {
// element.classList.add(warning)
// } else {
// element.classList.remove(warning)
// }
// }

/**
* Link Click Callback
* Note: Firefox popup requires a call to window.close()
* @function linkClick
* @param {MouseEvent} event
* @param {Event|MouseEvent} event
* @param {Boolean} [close]
*/
export async function linkClick(event, close = false) {
Expand Down Expand Up @@ -402,10 +387,10 @@
origins: ['*://*/*'],
})
console.debug('checkPerms:', hasPerms)

// Firefox still uses DOM Based Background Scripts
if (typeof document === 'undefined') {
return hasPerms
}
if (typeof document === 'undefined') return hasPerms

const hasPermsEl = document.querySelectorAll('.has-perms')
const grantPermsEl = document.querySelectorAll('.grant-perms')
if (hasPerms) {
Expand All @@ -421,16 +406,14 @@
/**
* Grant Permissions Click Callback
* @function grantPerms
* @param {MouseEvent} event
* @param {Event} event
* @param {Boolean} [close]
*/
export async function grantPerms(event, close = false) {
console.debug('grantPerms:', event)
// noinspection ES6MissingAwait
requestPerms()
if (close) {
window.close()
}
if (close) window.close()
}

/**
Expand Down
32 changes: 10 additions & 22 deletions src/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,10 @@ $('.form-control').on('change input', function () {
*/
async function initOptions() {
console.debug('initOptions')
// noinspection ES6MissingAwait
updateManifest()
// noinspection ES6MissingAwait
updateBrowser()
// noinspection ES6MissingAwait
updatePlatform()
// noinspection ES6MissingAwait
setShortcuts()
updateManifest().catch((e) => console.log(e))
updateBrowser().catch((e) => console.log(e))
updatePlatform().catch((e) => console.log(e))
setShortcuts().catch((e) => console.log(e))

checkPerms().then((hasPerms) => {
if (!hasPerms) console.log('%cMissing Host Permissions', 'color: Red')
Expand Down Expand Up @@ -223,10 +219,11 @@ function updateTable(data) {
*/
async function deleteHost(event) {
console.debug('deleteHost:', event)
const target = event.currentTarget
try {
const host = event.currentTarget?.dataset?.value
const host = target?.dataset?.value
console.debug('host:', host)
const confirm = event.currentTarget?.id !== 'confirm-delete'
const confirm = target?.id !== 'confirm-delete'
const { options } = await chrome.storage.sync.get(['options'])
if (options.confirmDelete && !!confirm) {
console.debug('Show Delete Modal')
Expand All @@ -249,12 +246,13 @@ async function deleteHost(event) {
* @param {MouseEvent} event
*/
async function editClick(event) {
console.debug('editClick:', event)
const target = event.currentTarget
console.debug('editClick:', target)
const inputs = editModalEl.querySelectorAll('input')
if (target.dataset.action === 'add') {
// Process Add
usernameSwitch.checked = false
editUsername.required = true
console.debug('%c Add Host editClick', 'color: Lime')
document.getElementById('edit-modal-label').textContent = 'Add Host'
editForm.dataset.action = 'add'
Expand All @@ -281,6 +279,7 @@ async function editClick(event) {
editPassword.dataset.original = password
editPassword.type = 'password'
usernameSwitch.checked = username === ''
editUsername.required = username !== ''
editModal.show()
}

Expand Down Expand Up @@ -594,17 +593,6 @@ async function onChanged(changes, namespace) {
updateTable(hosts)
}
}
// for (const [key, { newValue }] of Object.entries(changes)) {
// if (namespace === 'sync') {
// if (key === 'options') {
// updateOptions(newValue)
// } else {
// const hosts = await Hosts.all()
// console.debug('hosts:', hosts)
// updateTable(hosts)
// }
// }
// }
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/js/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ document
*/
async function domContentLoaded() {
console.debug('domContentLoaded')
// noinspection ES6MissingAwait
updateManifest()
updateManifest().catch((e) => console.log(e))
checkPerms().then((hasPerms) => {
if (!hasPerms) console.log('%cMissing Host Permissions', 'color: Red')
})
Expand Down
5 changes: 1 addition & 4 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import {
chrome.storage.onChanged.addListener(onChanged)

document.addEventListener('DOMContentLoaded', initPopup)
// noinspection JSCheckFunctionSignatures
document
.querySelectorAll('.grant-permissions')
.forEach((el) => el.addEventListener('click', (e) => grantPerms(e, true)))
// noinspection JSCheckFunctionSignatures
document
.querySelectorAll('a[href]')
.forEach((el) => el.addEventListener('click', (e) => linkClick(e, true)))
Expand All @@ -44,8 +42,7 @@ const usernameEl = document.getElementById('username')
*/
async function initPopup() {
console.debug('initPopup')
// noinspection ES6MissingAwait
updateManifest()
updateManifest().catch((e) => console.log(e))
checkPerms().then((hasPerms) => {
if (!hasPerms) console.log('%cMissing Host Permissions', 'color: Red')
})
Expand Down