Czogista

HerosInfo NI|SI

Jan 13th, 2022 (edited)
1,425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         HerosInfo
  3. // @namespace    https://czogi.usermd.net/
  4. // @version      0.2
  5. // @description  Info na webhook o herosach NI|SI
  6. // @author       Czogi
  7. // @include      /https:\/\/([^forum][^www][a-z]{4,15})\.margonem\.pl/
  8. // @noframes
  9. // @icon         https://www.google.com/s2/favicons?domain=margonem.pl
  10. // @grant        none
  11. // ==/UserScript==
  12. const whData = {
  13.   url: "",
  14.   content:
  15.     "Heros **%npc.nick%(%npc.lvl%)** zrespił się na mapie **%map.name%** na kordach **%hero.x%.%hero.y%**",
  16.   everyone: true
  17. };
  18. (async (window, isSi, sleep, whData) => {
  19.   "use strict";
  20.   const setStringProperties = (string, objects) => {
  21.     let slicesString = string.split("%");
  22.     for (let i = 0; i < slicesString.length; i++) {
  23.       const currString = slicesString[i];
  24.       if (currString === "." || !currString.includes(".")) {
  25.         continue;
  26.       }
  27.       const path = currString.split(".");
  28.       const obj = objects[path[0]];
  29.       const data = obj[path[1]];
  30.       slicesString[i] = data ? data : "";
  31.     }
  32.     return slicesString.join("");
  33.   };
  34.   const overwriteFunc = async (path, newFunc) => {
  35.     let currPath = window,
  36.       prevPath = window;
  37.     for (const key of path) {
  38.       while (!currPath.hasOwnProperty(key)) {
  39.         await sleep(100);
  40.       }
  41.       prevPath = currPath;
  42.       currPath = currPath[key];
  43.     }
  44.     const old = currPath;
  45.     prevPath[path.slice(-1).pop()] = function () {
  46.       newFunc.apply(prevPath, arguments);
  47.       old.apply(prevPath, arguments);
  48.     };
  49.   };
  50.   await overwriteFunc(
  51.     isSi ? ["parseInput"] : ["Engine", "communication", "parseJSON"],
  52.     (data) => {
  53.       if (!data.hasOwnProperty("npc")) {
  54.         return;
  55.       }
  56.       for (const [id, npc] of Object.entries(data.npc)) {
  57.         if (
  58.           npc.hasOwnProperty("del") ||
  59.           !npc.hasOwnProperty("wt") ||
  60.           npc.wt > 99 ||
  61.           npc.wt <= 79
  62.         ) {
  63.           continue;
  64.         }
  65.         const request = new XMLHttpRequest();
  66.         request.open("POST", whData.url);
  67.         request.setRequestHeader("Content-type", "application/json");
  68.         request.send(
  69.           JSON.stringify({
  70.             username: npc.nick,
  71.             avatar_url: `https://micc.garmory-cdn.cloud/obrazki/npc/${npc.icon}`,
  72.             content:
  73.               (whData.everyone ? "@everyone " : "") +
  74.               setStringProperties(whData.content, {
  75.                 npc: npc,
  76.                 map: isSi ? window.map : window.Engine.map.d,
  77.                 hero: isSi ? window.hero : window.Engine.hero.d
  78.               })
  79.           })
  80.         );
  81.       }
  82.     }
  83.   );
  84.   console.log(`[HerosInfo] Script Initiated.`);
  85. })(
  86.   typeof unsafeWindow !== "undefined" ? unsafeWindow : window,
  87.   /interface=si/.test(document.cookie),
  88.   (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
  89.   whData
  90. );
  91.  
  92. /* parseInput({
  93.   npc: {
  94.     99992: {
  95.       nick: "Opętany paladyn",
  96.       icon: "https://micc.garmory-cdn.cloud/obrazki/npc/woj/opetanypaladyn02.gif",
  97.       qm: 0,
  98.       x: hero.x - 1,
  99.       y: hero.y - 1,
  100.       lvl: 83,
  101.       type: 3,
  102.       wt: 80,
  103.       grp: 0
  104.     }
  105.   }
  106. });
  107.  */
  108. /*
  109. 0.1 - Publikacja.
  110. 0.2 - Poprawa wysyłania ikonki na si.
  111. */
  112.  
Add Comment
Please, Sign In to add comment