diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/scripts.json | 1 | ||||
| -rw-r--r-- | src/scripts/otps/grievance-application.ts | 26 | ||||
| -rw-r--r-- | src/scripts/otps/mutation-application.ts | 6 | ||||
| -rw-r--r-- | src/shared/autofill-otp.ts | 31 |
4 files changed, 43 insertions, 21 deletions
diff --git a/src/scripts.json b/src/scripts.json index 5fb63e6..a2e48fd 100644 --- a/src/scripts.json +++ b/src/scripts.json @@ -8,6 +8,7 @@ "injected": { "login.ts": "*", "otps/grievance-application.ts": "GrievAppViewAction.action", + "otps/mutation-application.ts": "MuteApplication.action", "functionality/view-khatian.ts": "KnowYourProperty.action" }, "loaded": { diff --git a/src/scripts/otps/grievance-application.ts b/src/scripts/otps/grievance-application.ts index 140504c..10d38ef 100644 --- a/src/scripts/otps/grievance-application.ts +++ b/src/scripts/otps/grievance-application.ts @@ -1,22 +1,6 @@ -document.addEventListener("DOMContentLoaded", () => { - const proxiedPost = $.post; +import { addAutofillOtps } from "@/shared/autofill-otp"; - $.post = function() { - let element: HTMLInputElement | null = null; - if (arguments[0].endsWith("MISPetitionSmsSend.action")) { - element = document.querySelector("input[name=mobile_Code]") as HTMLInputElement; - } else if (arguments[0].endsWith("MISPetitionEmailSend.action")) { - element = document.querySelector("input[name=txtemail_Code]") as HTMLInputElement; - } - - if (element) { - const callback = arguments[2]; - arguments[2] = (data: any) => { - element!.value = data?.messageShow || ""; - callback(data); - }; - } - - return proxiedPost.apply(this, Array.from(arguments) as any); - }; -}); +addAutofillOtps([ + ["MISPetitionSmsSend.action", "input[name=mobile_Code]"], + ["MISPetitionEmailSend.action", "input[name=txtemail_Code]"] +]); diff --git a/src/scripts/otps/mutation-application.ts b/src/scripts/otps/mutation-application.ts new file mode 100644 index 0000000..ecf6aaa --- /dev/null +++ b/src/scripts/otps/mutation-application.ts @@ -0,0 +1,6 @@ +import { addAutofillOtps } from "@/shared/autofill-otp"; + +addAutofillOtps([ + ["muteSmsSend.action", "#mobile_CodeMute"], + ["muteEmailSend.action", "#txtemail_CodeMute"] +]); diff --git a/src/shared/autofill-otp.ts b/src/shared/autofill-otp.ts new file mode 100644 index 0000000..e05ea7c --- /dev/null +++ b/src/shared/autofill-otp.ts @@ -0,0 +1,31 @@ +type AutofillOTPRule = readonly [string, string] + +let otpAutofillList: AutofillOTPRule[] = []; + +document.addEventListener("DOMContentLoaded", () => { + const proxiedPost = $.post; + + $.post = function() { + for (const rule of otpAutofillList) { + if (arguments[0].endsWith(rule[0])) { + const element: HTMLInputElement | null = document.querySelector(rule[1]) as HTMLInputElement | null; + + if (element) { + const callback = arguments[2]; + arguments[2] = (data: any) => { + element!.value = data?.messageShow || ""; + callback(data); + }; + } + + break; + } + } + + return proxiedPost.apply(this, Array.from(arguments) as any); + }; +}); + +export const addAutofillOtps = (addedOTPAutofillList: AutofillOTPRule[]) => { + otpAutofillList = otpAutofillList.concat(addedOTPAutofillList); +}; |
