aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts/autofill-otps/grievance-application.ts
blob: 140504c3c7fc9d5bd080c7a86a8272970cc5338c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
document.addEventListener("DOMContentLoaded", () => {
	const proxiedPost = $.post;

	$.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);
	};
});