force_delete/main.ts

84 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-10-03 00:09:46 +00:00
class ForceDeleteExtension {
private readonly LOOP_INTERVAL_TIME = 500
2024-10-03 23:30:15 +00:00
private readonly EXPLICIT_TARGET_SELECTORS = [
2024-10-03 00:09:46 +00:00
// S3 ---
'.empty-bucket-actions__input>input',
'.delete-bucket-actions__input>input',
// VPC ---
'div[data-id="confirmation-modal-input"]>input'
]
2024-10-03 23:30:15 +00:00
private readonly IMPLICIT_TARGET_PLACEHOLDERS = [
'delete',
'delete me',
'confirm'
]
2024-10-03 00:09:46 +00:00
public readonly startLoop = (): void => {
setInterval(
this.process.bind(this),
this.LOOP_INTERVAL_TIME)
}
2024-10-03 23:30:15 +00:00
private readonly process = (): void =>
2024-10-03 00:09:46 +00:00
this.applyDeleteMessages(this.findTargets())
//
// Target Element Finder ---
2024-10-03 23:30:15 +00:00
private readonly findTargets = (): HTMLInputElement[] => [
...this.findExplicitTargets(),
...this.findImplicitTargets()
]
2024-10-03 00:09:46 +00:00
2024-10-03 23:30:15 +00:00
private readonly findExplicitTargets = (): HTMLInputElement[] =>
this.EXPLICIT_TARGET_SELECTORS
2024-10-03 00:09:46 +00:00
.map(this.findTargetElements.bind(this))
.reduce((prev, curr) => ([...prev, ...curr]), [])
.filter((v) =>
v !== null &&
v instanceof HTMLInputElement
)
.filter((v) =>
!v.disabled &&
v.value.length < 1
)
2024-10-03 23:30:15 +00:00
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())
)
2024-10-03 00:09:46 +00:00
private readonly findTargetElements = (targetSelector: string): Array<Element | null> =>
[...document.querySelectorAll(targetSelector)]
//
// Delete-safe Message Applier ---
private readonly applyDeleteMessages = (elements: HTMLInputElement[]): void =>
elements.forEach(this.applyDeleteMessage.bind(this))
private readonly applyDeleteMessage = (element: HTMLInputElement): void => {
element.value = element.placeholder
element.dispatchEvent(new Event('input', {
bubbles: true
}))
}
}
//
// Main ---
new ForceDeleteExtension()
.startLoop()