forked from peko-bot/liver-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject.ts
52 lines (47 loc) · 1.46 KB
/
inject.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const dispatchInjectToContentScript = detail =>
document.getElementById('inject_window')?.dispatchEvent(new CustomEvent('inject_to_content_script', { detail }));
const ajax = params => {
const defaultOptions = {
cache: false,
global: false,
dataType: 'json',
contentType: 'application/json',
error: error => {
dispatchInjectToContentScript({ message: 'inject_ajax_error', error });
},
};
$.ajax(Object.assign({}, defaultOptions, params));
};
document.getElementById('inject_window')?.addEventListener('content_script_to_inject', (e: any) => {
const { message, data: battleId } = e.detail;
switch (message) {
case 'getBattleRoomHref':
ajax({
url: '/quest/battle_key_check',
data: JSON.stringify({ special_token: null, battle_key: battleId }),
method: 'POST',
success: result => {
const redirect = result.redirect;
if (redirect) {
dispatchInjectToContentScript({ message: 'getBattleRoomHref', url: redirect });
}
},
});
break;
default:
break;
}
});
// 创建一个用于粘贴 battle id 的文本框
const initInputForBattle = () => {
let input = document.getElementById('battle_input');
if (!input) {
input = document.createElement('input');
input.id = 'battle_input';
input.style.width = '0px';
input.style.height = '0px';
document.body.appendChild(input);
}
};
// 初始化舔婊配置
initInputForBattle();