diff options
| author | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2024-03-09 08:57:59 +0530 |
|---|---|---|
| committer | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2024-03-09 08:57:59 +0530 |
| commit | f4a94bed13a8595ec8a15e3ea8315aeb5aecc744 (patch) | |
| tree | e563f1a74a657348f13999c125f5ca12d200f8e6 /src/shared/intercept-jquery-ajax.ts | |
| parent | 435b16e29080f49e1ec373f5b0f552559ca04686 (diff) | |
| download | banglar-bhumi-utils-f4a94bed13a8595ec8a15e3ea8315aeb5aecc744.tar.gz banglar-bhumi-utils-f4a94bed13a8595ec8a15e3ea8315aeb5aecc744.zip | |
A lot of changes :)
Diffstat (limited to 'src/shared/intercept-jquery-ajax.ts')
| -rw-r--r-- | src/shared/intercept-jquery-ajax.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/shared/intercept-jquery-ajax.ts b/src/shared/intercept-jquery-ajax.ts new file mode 100644 index 0000000..efcb555 --- /dev/null +++ b/src/shared/intercept-jquery-ajax.ts @@ -0,0 +1,41 @@ +type InterceptJqueryAjaxCallback = (args: any) => void; + +interface InterceptJqueryEntry { + url: string; + callback: InterceptJqueryAjaxCallback; +}; + +const postIntercepts: InterceptJqueryEntry[] = []; +const getIntercepts: InterceptJqueryEntry[] = []; + +document.addEventListener("DOMContentLoaded", () => { + const proxiedPost = $.post; + const proxiedGet = $.get; + + $.post = function() { + for (const { url, callback } of postIntercepts) { + if (arguments[0].endsWith(url)) { + callback(arguments); + } + } + + return proxiedPost.apply(this, Array.from(arguments) as any); + }; + $.get = function() { + for (const { url, callback } of getIntercepts) { + if (arguments[0].endsWith(url)) { + callback(arguments); + } + } + + return proxiedGet.apply(this, Array.from(arguments) as any); + }; +}); + +export const interceptPost = (url: string, callback: InterceptJqueryAjaxCallback) => { + postIntercepts.push({ url, callback }); +}; + +export const interceptGet = (url: string, callback: InterceptJqueryAjaxCallback) => { + getIntercepts.push({ url, callback }); +}; |
