Skip to content

Commit da39b7b

Browse files
authored
Improvements for Username Switch (#15)
1 parent 9161bc3 commit da39b7b

5 files changed

Lines changed: 22 additions & 56 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"build": "npm run build:chrome && npm run build:firefox",
1717
"prettier:check": "npx prettier --check .",
1818
"prettier:write": "npx prettier --write .",
19-
"actionlint": "actionlint",
2019
"yamllint": "yamllint -c .github/yamllint.yaml ."
2120
},
2221
"dependencies": {

src/js/export.js

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ export function showHidePassword(event) {
130130
export async function copyInput(event) {
131131
console.debug('copyInput:', event)
132132
const el = event.currentTarget || event.target.closest('button')
133-
console.debug('el.dataset.copyInput:', el.dataset.copyInput)
134133
const input = document.querySelector(el.dataset.copyInput)
135134
console.debug('input:', input)
136135
if (!input.value) {
@@ -180,8 +179,11 @@ export async function saveOptions(event) {
180179
} else {
181180
value = event.target.value
182181
}
182+
183183
if (value === undefined) {
184-
console.warn(`No Value for key: ${key}`)
184+
console.warn(`No value for key: ${key}`)
185+
} else if (value === options[key]) {
186+
console.log(`No value change for key: ${key}:`, value)
185187
} else {
186188
options[key] = value
187189
console.log(`Set %c${key}:`, 'color: Khaki', value)
@@ -222,7 +224,6 @@ export function updateOptions(options) {
222224
hideShowElement(`#${el.dataset.related}`, value)
223225
}
224226
if (el.dataset.warning) {
225-
// addWarningClass(el.nextElementSibling, value, el.dataset.warning)
226227
el.nextElementSibling.classList.toggle(el.dataset.warning, !!value)
227228
}
228229
}
@@ -245,27 +246,11 @@ function hideShowElement(selector, show, speed = 'fast') {
245246
}
246247
}
247248

248-
// /**
249-
// * Add Warning Class to Element
250-
// * @function addWarningClass
251-
// * @param {HTMLElement} element
252-
// * @param {Boolean} value
253-
// * @param {String} warning
254-
// */
255-
// function addWarningClass(element, value, warning) {
256-
// // console.debug('addWarningClass:', value, element)
257-
// if (value) {
258-
// element.classList.add(warning)
259-
// } else {
260-
// element.classList.remove(warning)
261-
// }
262-
// }
263-
264249
/**
265250
* Link Click Callback
266251
* Note: Firefox popup requires a call to window.close()
267252
* @function linkClick
268-
* @param {MouseEvent} event
253+
* @param {Event|MouseEvent} event
269254
* @param {Boolean} [close]
270255
*/
271256
export async function linkClick(event, close = false) {
@@ -402,10 +387,10 @@ export async function checkPerms() {
402387
origins: ['*://*/*'],
403388
})
404389
console.debug('checkPerms:', hasPerms)
390+
405391
// Firefox still uses DOM Based Background Scripts
406-
if (typeof document === 'undefined') {
407-
return hasPerms
408-
}
392+
if (typeof document === 'undefined') return hasPerms
393+
409394
const hasPermsEl = document.querySelectorAll('.has-perms')
410395
const grantPermsEl = document.querySelectorAll('.grant-perms')
411396
if (hasPerms) {
@@ -421,16 +406,14 @@ export async function checkPerms() {
421406
/**
422407
* Grant Permissions Click Callback
423408
* @function grantPerms
424-
* @param {MouseEvent} event
409+
* @param {Event} event
425410
* @param {Boolean} [close]
426411
*/
427412
export async function grantPerms(event, close = false) {
428413
console.debug('grantPerms:', event)
429414
// noinspection ES6MissingAwait
430415
requestPerms()
431-
if (close) {
432-
window.close()
433-
}
416+
if (close) window.close()
434417
}
435418

436419
/**

src/js/options.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,10 @@ $('.form-control').on('change input', function () {
131131
*/
132132
async function initOptions() {
133133
console.debug('initOptions')
134-
// noinspection ES6MissingAwait
135-
updateManifest()
136-
// noinspection ES6MissingAwait
137-
updateBrowser()
138-
// noinspection ES6MissingAwait
139-
updatePlatform()
140-
// noinspection ES6MissingAwait
141-
setShortcuts()
134+
updateManifest().catch((e) => console.log(e))
135+
updateBrowser().catch((e) => console.log(e))
136+
updatePlatform().catch((e) => console.log(e))
137+
setShortcuts().catch((e) => console.log(e))
142138

143139
checkPerms().then((hasPerms) => {
144140
if (!hasPerms) console.log('%cMissing Host Permissions', 'color: Red')
@@ -223,10 +219,11 @@ function updateTable(data) {
223219
*/
224220
async function deleteHost(event) {
225221
console.debug('deleteHost:', event)
222+
const target = event.currentTarget
226223
try {
227-
const host = event.currentTarget?.dataset?.value
224+
const host = target?.dataset?.value
228225
console.debug('host:', host)
229-
const confirm = event.currentTarget?.id !== 'confirm-delete'
226+
const confirm = target?.id !== 'confirm-delete'
230227
const { options } = await chrome.storage.sync.get(['options'])
231228
if (options.confirmDelete && !!confirm) {
232229
console.debug('Show Delete Modal')
@@ -249,12 +246,13 @@ async function deleteHost(event) {
249246
* @param {MouseEvent} event
250247
*/
251248
async function editClick(event) {
249+
console.debug('editClick:', event)
252250
const target = event.currentTarget
253-
console.debug('editClick:', target)
254251
const inputs = editModalEl.querySelectorAll('input')
255252
if (target.dataset.action === 'add') {
256253
// Process Add
257254
usernameSwitch.checked = false
255+
editUsername.required = true
258256
console.debug('%c Add Host editClick', 'color: Lime')
259257
document.getElementById('edit-modal-label').textContent = 'Add Host'
260258
editForm.dataset.action = 'add'
@@ -281,6 +279,7 @@ async function editClick(event) {
281279
editPassword.dataset.original = password
282280
editPassword.type = 'password'
283281
usernameSwitch.checked = username === ''
282+
editUsername.required = username !== ''
284283
editModal.show()
285284
}
286285

@@ -594,17 +593,6 @@ async function onChanged(changes, namespace) {
594593
updateTable(hosts)
595594
}
596595
}
597-
// for (const [key, { newValue }] of Object.entries(changes)) {
598-
// if (namespace === 'sync') {
599-
// if (key === 'options') {
600-
// updateOptions(newValue)
601-
// } else {
602-
// const hosts = await Hosts.all()
603-
// console.debug('hosts:', hosts)
604-
// updateTable(hosts)
605-
// }
606-
// }
607-
// }
608596
}
609597

610598
/**

src/js/permissions.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ document
1919
*/
2020
async function domContentLoaded() {
2121
console.debug('domContentLoaded')
22-
// noinspection ES6MissingAwait
23-
updateManifest()
22+
updateManifest().catch((e) => console.log(e))
2423
checkPerms().then((hasPerms) => {
2524
if (!hasPerms) console.log('%cMissing Host Permissions', 'color: Red')
2625
})

src/js/popup.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ import {
1414
chrome.storage.onChanged.addListener(onChanged)
1515

1616
document.addEventListener('DOMContentLoaded', initPopup)
17-
// noinspection JSCheckFunctionSignatures
1817
document
1918
.querySelectorAll('.grant-permissions')
2019
.forEach((el) => el.addEventListener('click', (e) => grantPerms(e, true)))
21-
// noinspection JSCheckFunctionSignatures
2220
document
2321
.querySelectorAll('a[href]')
2422
.forEach((el) => el.addEventListener('click', (e) => linkClick(e, true)))
@@ -44,8 +42,7 @@ const usernameEl = document.getElementById('username')
4442
*/
4543
async function initPopup() {
4644
console.debug('initPopup')
47-
// noinspection ES6MissingAwait
48-
updateManifest()
45+
updateManifest().catch((e) => console.log(e))
4946
checkPerms().then((hasPerms) => {
5047
if (!hasPerms) console.log('%cMissing Host Permissions', 'color: Red')
5148
})

0 commit comments

Comments
 (0)