Hook Ajax

it can hook all ajax

Tento skript by neměl být instalován přímo. Jedná se o knihovnu, kterou by měly jiné skripty využívat pomocí meta příkazu // @require https://update.greasyfork.org/scripts/426753/939010/Hook%20Ajax.js

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

Autor
Cangshi
Verze
0.0.1.20210609065437
Vytvořeno
20. 05. 2021
Aktualizováno
09. 06. 2021
Size
43,9 KB
Licence
neuvedeno

@hook-js/ajax

用于拦截 Javascript 中所有的 Ajax 请求

安装

npm install @hook-js/ajax

或者

yarn add @hook-js/ajax

简单 DEMO

import {AjaxInterceptor} from '@hook-js/ajax'

const intercept = new AjaxInterceptor()

intercept.register('.*',
    {
        onRequest({args}){
            // 查看当前 request 的 url
            console.log('url:', args[1])
            // 修改 url
            args[1] += 'test'
        },
        onSend({args}){
            // 查看当前请求体内容
            console.log('Post data:', args[0])
            // 可以在下面直接修改请求体
        },
        onResponse({response}){
            // 查看当前请求的响应内容,如果是 json 格式会自动转化
            console.log('response:', response)
            // 假设为 JSON 格式,修改其中属性 name
            response.name = 'test'
            // 发起该请求的地方获取到的响应值 name 属性会被篡改为 'test'
        }
    }
)

API文档

https://github.com/canguser/hook-js-ajax/tree/master/docs