Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function update_eqine(mutations, observer) {
  2. // console.log("try update_eginv");
  3.  
  4.     var cont = $(".eqinv-container");
  5.  
  6.     if (cont.length) {
  7.         let newcont;
  8.         let content = cont.text().trimLeft();
  9.         if (content.startsWith("Inventario")) {
  10.             console.log("update inventory");
  11.             newcont = $(cont.clone());
  12.             newcont.find(".eqinv-switch-action").remove();
  13.             $global_handler.overlay_inv.html(newcont.html());
  14.             $global_handler.overlay_inv.find("h3").remove();
  15.             var ch = $global_handler.overlay_inv.find(".eqinv-caption");
  16.             ch.find("div:nth-child(2)").remove();
  17.             ch.find("div:nth-child(1)").css("min-width", "80%");
  18.             $global_handler.overlay_inv.find(".eqinv-item").each(function () {
  19.                 const elem = $(this);
  20.                 const node_quantity = elem.next();
  21.                 const obj_quantity = node_quantity.text();
  22.                 elem.css("min-width", "80%");
  23.                 const obj_name = elem.find("span");
  24.                 obj_name.text(obj_name.text() + " x" + obj_quantity);
  25.                 $(node_quantity).remove();
  26.             });
  27.             return
  28.         }
  29.         if (content.startsWith("Equipaggiamento")) {
  30.             console.log("update equip");
  31.             newcont = $(cont.clone());
  32.             newcont.find(".eqinv-switch-action").remove();
  33.             $global_handler.overlay_eq.html(newcont.html());
  34.             $global_handler.overlay_eq.find(".eqinv-totalweight-label").remove();
  35.             $global_handler.overlay_eq.find("h3").remove();
  36.             return;
  37.         }
  38.  
  39.     }
  40.  
  41.     cont = $(".skill-list");
  42.  
  43.     if (cont.length) {
  44.         let newcont;
  45.         let content = cont.text().trimLeft();
  46.  
  47.         if (content.indexOf("Abilità") !== -1) {
  48.             console.log("update skill");
  49.             newcont = $(cont.clone());
  50.             $global_handler.overlay_skill.html(newcont.html());
  51.             $global_handler.overlay_skill.find(".skill-detail").each(function () {
  52.                 var elem = $(this);
  53.                 var skillLevel = elem.find("span");
  54.                 var tt = skillLevel[0].style.width;
  55.                 var dd = '<div fxflex="0 1 100%" style="flex: 0 1 100%; box-sizing: border-box; max-width: 100%;"><span style="width:100%">' + tt.replace("%", "") + ' </span></div>';
  56.                 console.log("skill-level: " + tt);
  57.                 var toDelete = skillLevel.parent();
  58.                 console.log("would like to delete this: " + toDelete);
  59.                 var skillName = toDelete.prev();
  60.                 console.log("skill-name: " + skillName.text());
  61.                 $(skillName).after(dd);
  62.                 skillName.css({"min-width": "130px", "max-width": "130px"});
  63.                 toDelete.remove();
  64.             });
  65.             return;
  66.         }
  67.     }
  68.  
  69. }
  70.  
  71.  
  72. function _prepare_css() {
  73.     $("<style type='text/css'> .overlay_custom{position:fixed;top:0;left:0;width:19%;height:30%;background-color:#000;z-index:999; min-width:300px} </style>").appendTo("head");
  74.     $("tg-right-sidebar").css("zoom", "0.7");
  75. }
  76.  
  77.  
  78. function _add_overlay() {
  79.  
  80.     var overlay = jQuery('<div class="b-ironlight-mini tg-box overlay_custom">' +
  81.         ' <div id="overlay_custom_content_inv" class="tg-dialog-content-nopadding tg-shadow-inset"> </div><div class="tg-border-box"><div class="tg-border tg-border-top"></div><div class="tg-border tg-border-left"></div><div class="tg-border tg-border-right"></div><div class="tg-border tg-border-bottom"></div></div>' +
  82.         '</div>' +
  83.         '<div class="b-ironlight-mini tg-box overlay_custom">' +
  84.         ' <div id="overlay_custom_content_eq" class="tg-dialog-content-nopadding tg-shadow-inset"> </div><div class="tg-border-box"><div class="tg-border tg-border-top"></div><div class="tg-border tg-border-left"></div><div class="tg-border tg-border-right"></div><div class="tg-border tg-border-bottom"></div></div>' +
  85.         '</div>' +
  86.         '<div class="b-ironlight-mini tg-box overlay_custom" style="max-width: 200px;min-width: 200px;">' +
  87.         ' <div id="overlay_custom_content_skill" class="tg-dialog-content-nopadding tg-shadow-inset"> </div><div class="tg-border-box"><div class="tg-border tg-border-top"></div><div class="tg-border tg-border-left"></div><div class="tg-border tg-border-right"></div><div class="tg-border tg-border-bottom"></div></div>' +
  88.         '</div>');
  89.     overlay.appendTo(document.body);
  90.  
  91.     $global_handler.overlay_inv = $("#overlay_custom_content_inv");
  92.     $global_handler.overlay_eq = $("#overlay_custom_content_eq");
  93.     $global_handler.overlay_skill = $("#overlay_custom_content_skill");
  94.  
  95.     var ov_inv_p = $global_handler.overlay_inv.parent();
  96.     var ov_eq_p = $global_handler.overlay_eq.parent();
  97.     var ov_skill_p = $global_handler.overlay_skill.parent();
  98.  
  99.     // non li mostro all'inizio
  100.     ov_inv_p.hide();
  101.     ov_eq_p.hide();
  102.     ov_skill_p.hide();
  103.  
  104.     // draggable
  105.     ov_inv_p.draggable();
  106.     ov_eq_p.draggable();
  107.     ov_skill_p.draggable();
  108. }
  109.  
  110.  
  111. function _prepare_listeners() {
  112.     MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
  113.  
  114.     const mutation_inveq_temp = new MutationObserver(function (mutations, observer) {
  115.  
  116.         var overlay_equip_container = $(".cdk-overlay-container");
  117.  
  118.         // scarto qualunque evento finche trovo il contenitore
  119.         if (!overlay_equip_container.length)
  120.             return;
  121.  
  122.         // console.log("trovato eqinv...");
  123.  
  124.         // mi disconnetto
  125.         this.disconnect();
  126.  
  127.         // mi attacco al nuovo
  128.         $global_handler.mutation_inveq = new MutationObserver(update_eqine);
  129.  
  130.         //console.log("attaching observer");
  131.  
  132.         overlay_equip_container.each(function () {
  133.  
  134.             console.log("attacching DOM listeners..");
  135.  
  136.             $global_handler.mutation_inveq.observe(this, {
  137.                 subtree: true,
  138.                 childList: true
  139.             });
  140.  
  141.             console.log("attacching button listeners..");
  142.  
  143.             // attacco i nuovi listeners
  144.             var mainButtons = $(".tg-main-buttons button");
  145.  
  146.             $global_handler.pg_button = mainButtons[0];
  147.             $global_handler.equip_button = mainButtons[1];
  148.             $global_handler.inventory_button = mainButtons[2];
  149.             $global_handler.skill_button = mainButtons[3];
  150.             $global_handler.pref_button = mainButtons[5];
  151.  
  152.             var last_clicked;
  153.             var elem_dialogs = $(".cdk-overlay-container");
  154.             var update_dialogs = function (button) {
  155.                 if (elem_dialogs.is(":visible")) {
  156.                     if (last_clicked === button) {
  157.                         elem_dialogs.hide();
  158.                         elem_dialogs.css("z-index", "-1");
  159.                     }
  160.                 } else {
  161.                     elem_dialogs.show();
  162.                     elem_dialogs.css("z-index", "1000");
  163.                 }
  164.                 last_clicked = button;
  165.             };
  166.             var update_overlays = function (overlay, button) {
  167.                 if (overlay.is(":visible")) {
  168.                     if (last_clicked === button) {
  169.                         overlay.hide();
  170.                     }
  171.                 } else {
  172.                     overlay.show();
  173.                 }
  174.                 last_clicked = button;
  175.             };
  176.  
  177.             $($global_handler.pg_button).click(function () {
  178.                 console.log("clicked pg");
  179.                 update_dialogs(this);
  180.             });
  181.             $($global_handler.equip_button).click(function () {
  182.                 console.log("clicked equip");
  183.                 update_overlays($global_handler.overlay_eq.parent(), this);
  184.             });
  185.             $($global_handler.inventory_button).click(function () {
  186.                 console.log("clicked inventory");
  187.                 update_overlays($global_handler.overlay_inv.parent(), this);
  188.             });
  189.             $($global_handler.skill_button).click(function () {
  190.                 console.log("clicked skill");
  191.                 update_overlays($global_handler.overlay_skill.parent(), this);
  192.             });
  193.             $($global_handler.pref_button).click(function () {
  194.                 console.log("clicked preference");
  195.                 elem_dialogs.show();
  196.                 last_clicked = this;
  197.             });
  198.         });
  199.  
  200.         overlay_equip_container.hide();
  201.         // overlay_equip_container.css("z-index", "0");
  202.  
  203.  
  204.     });
  205.  
  206.     // partiamo ascoltando su body fino a che non compare il container, poi ci stacchiamo e riattacchiamo al nuovo
  207.     $("body").each(function () {
  208.         mutation_inveq_temp.observe(this, {
  209.             subtree: true,
  210.             childList: true
  211.         });
  212.     });
  213.  
  214.  
  215. }
  216.  
  217. function prepare_everything() {
  218.     $global_handler = {};
  219.     _prepare_css();
  220.     _add_overlay();
  221.     _prepare_listeners();
  222.  
  223.     // var regex_rimuovi = /(ri\s)|(rim\s)|(rimuovi\s) \d+/g;
  224.     //
  225.     // var input_word = "";
  226.     // $('input[name="sendinput"]').keypress(function (event) {
  227.     //
  228.     //     if (event.which === 13) {
  229.     //
  230.     //         if (input_word.match(regex_rimuovi)) {
  231.     //             // è comando rimuovi
  232.     //             console.log("comando rimuovi individuato");
  233.     //             $(this).val("eq;inv;");
  234.     //             $(this).trigger(jQuery.Event("keypress", {which: 13}));
  235.     //             input_word = "";
  236.     //         }
  237.     //         return;
  238.     //     }
  239.     //     input_word = $(this).val();
  240.     //
  241.     // });
  242.  
  243. }
  244.  
  245. (
  246.  
  247.     function () {
  248.  
  249.         if (window.global_handler !== undefined) {
  250.             return;
  251.         }
  252.  
  253.         var get$ = function () {
  254.             if (window.jQuery) {
  255.                 get$UI();
  256.             } else {
  257.                 var s = document.createElement('script');
  258.                 s.onload = get$UI;
  259.                 s.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js');
  260.                 document.body.appendChild(s);
  261.             }
  262.         };
  263.  
  264.         var get$UI = function () {
  265.             if (window.jQuery.ui) {
  266.                 onReady();
  267.             } else {
  268.                 var s = document.createElement('script');
  269.                 s.onload = onReady;
  270.                 s.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js');
  271.                 document.body.appendChild(s);
  272.             }
  273.         };
  274.  
  275.         var onReady = function () {
  276.             console.log("creo engine");
  277.             prepare_everything();
  278.         };
  279.  
  280.         get$();
  281.     }
  282.  
  283. )();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement