Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (() => {
- const NI = getCookie('interface') === 'ni';
- // TODO: move this url to .env file or create whole account system
- const URI = 'webhook link';
- function getCookie(name) {
- const value = '; ' + document.cookie;
- const parts = value.split(`; ${name}=`);
- if (parts.length == 2) {
- return parts.pop().split(";").shift();
- }
- }
- function myNick() {
- return NI ? Engine.hero.d.nick : hero.nick;
- }
- function getMapProp(prop) {
- return NI ? Engine.map.d[prop] : map[prop];
- }
- function checkNpc(npc) {
- if (npc.wt > 79) {
- const type = npc.wt < 100 ? 'heros' : getMapProp('mode') !== 5 ? 'tytan' : 'kolos';
- const color = type === 'heros' ? 3448267 : type === 'tytan' ? 12718623 : 8037675;
- sendMessage({
- ...npc,
- color,
- imageURI: window.location.origin + (NI ? CFG.npath : '') + npc.icon,
- stringifiedType: type,
- });
- }
- }
- function sendMessage(mob) {
- const message = {
- username: mob.nick,
- avatar_url: mob.imageURI,
- content: '@everyone',
- embeds: [{
- color: mob.color,
- title: `${myNick()} znalazł ${mob.stringifiedType}a`,
- thumbnail: {
- url: mob.imageURI,
- },
- fields: [{
- inline: true,
- name: new Date().toLocaleString(),
- value: `\`${mob.nick} ${mob.lvl} lvl\n${getMapProp('name')} (${mob.x}, ${mob.y})\``,
- }],
- }],
- };
- fetch(URI, {
- method: 'POST',
- cache: 'no-cache',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify(message),
- })
- .catch((error) => {
- console.error(error);
- log('Błąd przy wysyłaniu danych do webhooka PEC', 2);
- log(error, 2);
- });
- }
- function start() {
- if (NI) {
- API.addCallbackToEvent('newNpc', (data) => {
- if (data && data.d) {
- checkNpc(data.d);
- }
- });
- } else {
- const oldNewNpc = newNpc;
- newNpc = (npcs) => {
- oldNewNpc(npcs);
- if (npcs) {
- for (const npc of Object.values(npcs)) {
- checkNpc(npc);
- }
- }
- };
- }
- }
- const oldSend = XMLHttpRequest.prototype.send;
- let loaded = false;
- let started = false;
- XMLHttpRequest.prototype.send = function () {
- const callback = this.onreadystatechange;
- this.onreadystatechange = function () {
- if (4 === this.readyState) {
- if (this.responseURL.includes('margonem.pl/engine?t=init&initlvl=4')) {
- loaded = true;
- }
- }
- if (callback !== null) {
- callback.apply(this, arguments);
- }
- };
- oldSend.apply(this, arguments);
- if (loaded && !started) {
- started = true;
- start();
- }
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement