From 1a7e70272c7ca6d1e8344be839061a9be19c4277 Mon Sep 17 00:00:00 2001 From: Minhyeok Park Date: Fri, 4 Oct 2024 08:30:15 +0900 Subject: [PATCH] feat: add implicit target finder --- main.ts | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) 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)]