-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathantybot.js
194 lines (177 loc) · 5.94 KB
/
antybot.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
(() => {
const globalAddon = "http://addons2.margonem.pl/get/127/127954dev.js";
const globalAddonDwa = "http://addons2.margonem.pl/get/127/127964dev.js";
const hasBotE2Wilk = document.querySelector(".adi-bot-box") || getCookie("adi-bot-timer");
const hasBotExpWilk = typeof window.adiwilkTestBot === "object" || document.querySelector("#adi-bot_box");
const hasMenogram = typeof window.___g === "object";
const antyBot = {
log: window.log,
setCookie: window.setCookie,
consoleParse: window.consoleParse,
_g: window._g,
};
let lastEventTs = 0;
const getTs = () => Date.now() / 1000;
const resetEventTs = () => {
lastEventTs = getTs();
};
const checkUrl = (url) => ["fight", "a=attack", "id="].every((el) => url.includes(el));
const checkLink = (url) => [globalAddon, globalAddonDwa].some((link) => String(url).includes(link));
const checkTime = () => getTs() - lastEventTs > 5;
const clearConsole = () => {
const globalLog = Array.from(document.querySelectorAll("#contxt > div")).find((el) => !el.classList.value && checkLink(el.innerText));
if (globalLog) globalLog.remove();
};
const log = (txt, lvl) => {
clearConsole();
if (checkLink(txt)) return;
if (lvl) return antyBot.log(txt, lvl);
antyBot.log(txt);
};
const consoleParse = (txt) => {
if (typeof txt !== "string" || !txt.length) return;
const [command, value] = txt.split(" ");
if (command !== "gadblock") {
return antyBot.consoleParse(txt);
}
if (value === "off") {
return antyBot.log("Global addon unblocked ('gadblock on' to block)");
}
return antyBot.log("Global addon blocked ('gadblock off' to unblock)");
};
const _g = (url, clb) => {
if (typeof url !== "string") return;
if (!checkUrl(url)) return antyBot._g(url, clb);
if (checkTime()) url = "_";
antyBot._g(url, clb);
};
const getCookie = (cookie_name) => {
const [, value] = document.cookie.split("; ").map((el) => el.split("=")).find(([name]) => name === cookie_name) || [];
return value ? String(value).replace(/%2C/g, ",") : false;
};
const setCookie = (name, ...args) => {
if (name !== "__nga") return antyBot.setCookie(name, ...args);
};
const setCookiee = (name, value) => {
if ([name, value].some((el) => typeof el === "undefined")) return;
const d = new Date();
d.setTime(d.getTime() + 360000 * 24 * 30);
document.cookie = `${name}=${value}; expires=${d.toGMTString()};`;
};
const setAddonsCookie = () => {
const allAddons = getCookie("__mExts");
const antybotAddon = "d127964";
const separator = ",";
if (!allAddons) return setCookiee("__mExts", antybotAddon);
const hasAddon = /(^|,)d127964(,|$)/.test(allAddons);
if (hasAddon) return;
setCookie("__mExts", allAddons + separator + antybotAddon);
};
const setListeners = (events, element, callback) => {
events.forEach((event) => element.addEventListener(event, callback));
};
const changeDisabled = (input) => {
input.value = "";
input.setAttribute("disabled", true);
};
const clearInput = (input) => {
if (!input) return;
changeDisabled(input);
setListeners(["change", "keyup"], input, () => changeDisabled(input));
};
const changeStorage = (name, value) => {
const lsValue = localStorage.getItem(name);
if (lsValue && lsValue !== value) {
localStorage.setItem(name, value);
}
};
const changeCookie = (name, value) => {
const cookieValue = getCookie(name);
if ((name === "__nga" || cookieValue) && cookieValue !== value) {
setCookiee(name, value);
}
};
const getMenogramStorageName = (name) =>
[getCookie("user_id"), name, getCookie("mchar_id")].join("");
const menogram = () => {
if (!hasMenogram) return;
changeStorage(getMenogramStorageName("myMin"), "-1");
changeStorage(getMenogramStorageName("myMax"), "-1");
changeStorage(getMenogramStorageName("stan"), "off");
changeStorage(`start${getCookie("mchar_id")}`, "0");
if (window.___g) {
if (window.___g.twojstary) {
window.___g.twojstary.socketconnected = false;
}
}
};
const botE2Wilk = () => {
if (!hasBotE2Wilk) return;
const input = document.querySelector(".adi-bot-input-text");
clearInput(input);
changeCookie("adi-bot-timer", "dupa");
};
const botExpWilk = () => {
if (!hasBotExpWilk) return;
const inputs = Array.from(document.querySelectorAll("#bot_box > input, #adi-bot_box > input"));
const inputsdwa = Array.from(document.querySelectorAll("input"))
.filter((el) => el.getAttribute("tip"))
.filter((el) =>
["Wprowadź lvl mobków", "Wprowadź nazwy map"].some((tip) =>
el.getAttribute("tip").includes(tip)
)
);
const id = getCookie("mchar_id");
const storages = [
"adi-bot-storage",
`adi-bot_maps${id}`,
`adi-bot_mobs${id}`,
"bot_mobs",
"bot_maps",
"adi-bot_mobs",
"adi-bot_maps",
];
storages.forEach((storage) => localStorage.removeItem(storage));
inputs.forEach(clearInput);
inputsdwa.forEach(clearInput);
};
const obsraneMargoFunkcje = () => {
window.log = (txt, lvl) => log(txt, lvl);
window.setCookie = (name, ...args) => setCookie(name, ...args);
window.consoleParse = (txt) => consoleParse(txt);
window._g = (url, clb) => _g(url, clb);
};
const boty = () => {
menogram();
botE2Wilk();
botExpWilk();
};
const main = () => {
if (!location.host.includes("nyras")) return;
setListeners(
[
"keypress",
"keydown",
"keyup",
"click",
"mousedown",
"mouseup",
"contextmenu",
"touchstart",
"touchend",
],
window,
resetEventTs
);
obsraneMargoFunkcje();
setInterval(() => {
setAddonsCookie();
changeCookie("__nga", "0");
}, 300);
if (hasBotE2Wilk || hasBotExpWilk || hasMenogram) {
boty();
setInterval(boty, 5000);
}
};
main();
})();