Advertisement
satiel7314

Untitled

Jul 20th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. (() => {
  2. const NI = getCookie('interface') === 'ni';
  3. const URI = 'link_do_webhooka';
  4. let ready = false;
  5.  
  6. function getCookie(name) {
  7. const value = '; ' + document.cookie;
  8. const parts = value.split(`; ${name}=`);
  9.  
  10. if (parts.length == 2) {
  11. return parts.pop().split(";")[0];
  12. }
  13. }
  14.  
  15. function myNick() {
  16. return NI ? Engine.hero.d.nick : hero.nick;
  17. }
  18.  
  19. function getMapProp(prop) {
  20. return NI ? Engine.map.d[prop] : map[prop];
  21. }
  22.  
  23. function checkNpc(npc) {
  24. if (npc.wt > 79) {
  25. const type = npc.wt < 100 ? 'heros' : getMapProp('mode') !== 5 ? 'tytan' : 'kolos';
  26. const color = type === 'heros' ? 3448267 : type === 'tytan' ? 12718623 : 8037675;
  27.  
  28. sendMessage({
  29. ...npc,
  30. color,
  31. imageURI: window.location.origin + (NI ? CFG.npath : '') + npc.icon,
  32. stringifiedType: type,
  33. });
  34. }
  35. }
  36.  
  37. function sendMessage(mob) {
  38. const message = {
  39. username: mob.nick,
  40. avatar_url: mob.imageURI,
  41. content: '@everyone',
  42. embeds: [{
  43. color: mob.color,
  44. title: `${myNick()} znalazł ${mob.stringifiedType}a`,
  45. thumbnail: {
  46. url: mob.imageURI,
  47. },
  48. fields: [{
  49. inline: true,
  50. name: new Date().toLocaleString(),
  51. value: `\`${mob.nick} ${mob.lvl} lvl\n${getMapProp('name')} (${mob.x}, ${mob.y})\``,
  52. }],
  53. }],
  54. };
  55.  
  56. fetch(URI, {
  57. method: 'POST',
  58. cache: 'no-cache',
  59. headers: { 'Content-Type': 'application/json' },
  60. body: JSON.stringify(message),
  61. }).catch((error) => {
  62. console.error(error);
  63.  
  64. log('Błąd przy wysyłaniu danych do webhooka PEC', 2);
  65. log(error, 2);
  66. });
  67. }
  68.  
  69. if (NI) {
  70. API.addCallbackToEvent('newNpc', (data) => {
  71. if (ready && data && data.d) {
  72. checkNpc(data.d);
  73. }
  74. });
  75. } else {
  76. const oldNewNpc = newNpc;
  77.  
  78. newNpc = (npcs) => {
  79. oldNewNpc(npcs);
  80.  
  81. if (ready && npcs) {
  82. for (const npc of Object.values(npcs)) {
  83. checkNpc(npc);
  84. }
  85. }
  86. };
  87. }
  88.  
  89. const oldSend = XMLHttpRequest.prototype.send;
  90.  
  91. XMLHttpRequest.prototype.send = function () {
  92. const callback = this.onreadystatechange;
  93.  
  94. this.onreadystatechange = function () {
  95. if (4 === this.readyState) {
  96. if (this.responseURL.includes('margonem.pl/engine?t=init&initlvl=3')) {
  97. ready = true;
  98. }
  99. }
  100.  
  101. if (callback !== null) {
  102. callback.apply(this, arguments);
  103. }
  104. };
  105.  
  106. oldSend.apply(this, arguments);
  107. };
  108. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement