feat: add implicit target finder

This commit is contained in:
Minhyeok Park 2024-10-04 08:30:15 +09:00
parent 01bccd9332
commit 1a7e70272c
Signed by: pmh_only
SSH Key Fingerprint: SHA256:g/OyGvi2pcd8ub9mqge/ohmDP0fZX/xOPWPIcM+9XpI

31
main.ts
View File

@ -1,7 +1,7 @@
class ForceDeleteExtension { class ForceDeleteExtension {
private readonly LOOP_INTERVAL_TIME = 500 private readonly LOOP_INTERVAL_TIME = 500
private readonly TARGET_SELECTORS = [ private readonly EXPLICIT_TARGET_SELECTORS = [
// S3 --- // S3 ---
'.empty-bucket-actions__input>input', '.empty-bucket-actions__input>input',
@ -12,21 +12,30 @@ class ForceDeleteExtension {
] ]
private readonly IMPLICIT_TARGET_PLACEHOLDERS = [
'delete',
'delete me',
'confirm'
]
public readonly startLoop = (): void => { public readonly startLoop = (): void => {
setInterval( setInterval(
this.process.bind(this), this.process.bind(this),
this.LOOP_INTERVAL_TIME) this.LOOP_INTERVAL_TIME)
} }
private readonly process = (): void => { private readonly process = (): void =>
this.applyDeleteMessages(this.findTargets()) this.applyDeleteMessages(this.findTargets())
}
// //
// Target Element Finder --- // Target Element Finder ---
private readonly findTargets = (): HTMLInputElement[] => [
...this.findExplicitTargets(),
...this.findImplicitTargets()
]
private readonly findTargets = (): HTMLInputElement[] => private readonly findExplicitTargets = (): HTMLInputElement[] =>
this.TARGET_SELECTORS this.EXPLICIT_TARGET_SELECTORS
.map(this.findTargetElements.bind(this)) .map(this.findTargetElements.bind(this))
.reduce((prev, curr) => ([...prev, ...curr]), []) .reduce((prev, curr) => ([...prev, ...curr]), [])
.filter((v) => .filter((v) =>
@ -38,6 +47,18 @@ class ForceDeleteExtension {
v.value.length < 1 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> => private readonly findTargetElements = (targetSelector: string): Array<Element | null> =>
[...document.querySelectorAll(targetSelector)] [...document.querySelectorAll(targetSelector)]