diff --git a/main.ts b/main.ts index c870432..99fb9bf 100644 --- a/main.ts +++ b/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 => [...document.querySelectorAll(targetSelector)]