feat: add implicit target finder
This commit is contained in:
parent
01bccd9332
commit
1a7e70272c
31
main.ts
31
main.ts
@ -1,7 +1,7 @@
|
||||
class ForceDeleteExtension {
|
||||
private readonly LOOP_INTERVAL_TIME = 500
|
||||
|
||||
private readonly TARGET_SELECTORS = [
|
||||
private readonly EXPLICIT_TARGET_SELECTORS = [
|
||||
|
||||
// S3 ---
|
||||
'.empty-bucket-actions__input>input',
|
||||
@ -12,21 +12,30 @@ class ForceDeleteExtension {
|
||||
|
||||
]
|
||||
|
||||
private readonly IMPLICIT_TARGET_PLACEHOLDERS = [
|
||||
'delete',
|
||||
'delete me',
|
||||
'confirm'
|
||||
]
|
||||
|
||||
public readonly startLoop = (): void => {
|
||||
setInterval(
|
||||
this.process.bind(this),
|
||||
this.LOOP_INTERVAL_TIME)
|
||||
}
|
||||
|
||||
private readonly process = (): void => {
|
||||
private readonly process = (): void =>
|
||||
this.applyDeleteMessages(this.findTargets())
|
||||
}
|
||||
|
||||
//
|
||||
// Target Element Finder ---
|
||||
private readonly findTargets = (): HTMLInputElement[] => [
|
||||
...this.findExplicitTargets(),
|
||||
...this.findImplicitTargets()
|
||||
]
|
||||
|
||||
private readonly findTargets = (): HTMLInputElement[] =>
|
||||
this.TARGET_SELECTORS
|
||||
private readonly findExplicitTargets = (): HTMLInputElement[] =>
|
||||
this.EXPLICIT_TARGET_SELECTORS
|
||||
.map(this.findTargetElements.bind(this))
|
||||
.reduce((prev, curr) => ([...prev, ...curr]), [])
|
||||
.filter((v) =>
|
||||
@ -38,6 +47,18 @@ class ForceDeleteExtension {
|
||||
v.value.length < 1
|
||||
)
|
||||
|
||||
private readonly findImplicitTargets = (): HTMLInputElement[] =>
|
||||
this.findTargetElements('input')
|
||||
.filter((v) =>
|
||||
v !== null &&
|
||||
v instanceof HTMLInputElement
|
||||
)
|
||||
.filter((v) =>
|
||||
!v.disabled &&
|
||||
v.value.length < 1 &&
|
||||
this.IMPLICIT_TARGET_PLACEHOLDERS.includes(v.placeholder.toLowerCase())
|
||||
)
|
||||
|
||||
private readonly findTargetElements = (targetSelector: string): Array<Element | null> =>
|
||||
[...document.querySelectorAll(targetSelector)]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user