Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function update_eqine(mutations, observer) {
- // console.log("try update_eginv");
- var cont = $(".eqinv-container");
- if (cont.length) {
- let newcont;
- let content = cont.text().trimLeft();
- if (content.startsWith("Inventario")) {
- console.log("update inventory");
- newcont = $(cont.clone());
- newcont.find(".eqinv-switch-action").remove();
- $global_handler.overlay_inv.html(newcont.html());
- $global_handler.overlay_inv.find("h3").remove();
- var ch = $global_handler.overlay_inv.find(".eqinv-caption");
- ch.find("div:nth-child(2)").remove();
- ch.find("div:nth-child(1)").css("min-width", "80%");
- $global_handler.overlay_inv.find(".eqinv-item").each(function () {
- const elem = $(this);
- const node_quantity = elem.next();
- const obj_quantity = node_quantity.text();
- elem.css("min-width", "80%");
- const obj_name = elem.find("span");
- obj_name.text(obj_name.text() + " x" + obj_quantity);
- $(node_quantity).remove();
- });
- return
- }
- if (content.startsWith("Equipaggiamento")) {
- console.log("update equip");
- newcont = $(cont.clone());
- newcont.find(".eqinv-switch-action").remove();
- $global_handler.overlay_eq.html(newcont.html());
- $global_handler.overlay_eq.find(".eqinv-totalweight-label").remove();
- $global_handler.overlay_eq.find("h3").remove();
- return;
- }
- }
- cont = $(".skill-list");
- if (cont.length) {
- let newcont;
- let content = cont.text().trimLeft();
- if (content.indexOf("Abilità") !== -1) {
- console.log("update skill");
- newcont = $(cont.clone());
- $global_handler.overlay_skill.html(newcont.html());
- $global_handler.overlay_skill.find(".skill-detail").each(function () {
- var elem = $(this);
- var skillLevel = elem.find("span");
- var tt = skillLevel[0].style.width;
- 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>';
- console.log("skill-level: " + tt);
- var toDelete = skillLevel.parent();
- console.log("would like to delete this: " + toDelete);
- var skillName = toDelete.prev();
- console.log("skill-name: " + skillName.text());
- $(skillName).after(dd);
- skillName.css({"min-width": "130px", "max-width": "130px"});
- toDelete.remove();
- });
- return;
- }
- }
- }
- function _prepare_css() {
- $("<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");
- $("tg-right-sidebar").css("zoom", "0.7");
- }
- function _add_overlay() {
- var overlay = jQuery('<div class="b-ironlight-mini tg-box overlay_custom">' +
- ' <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>' +
- '</div>' +
- '<div class="b-ironlight-mini tg-box overlay_custom">' +
- ' <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>' +
- '</div>' +
- '<div class="b-ironlight-mini tg-box overlay_custom" style="max-width: 200px;min-width: 200px;">' +
- ' <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>' +
- '</div>');
- overlay.appendTo(document.body);
- $global_handler.overlay_inv = $("#overlay_custom_content_inv");
- $global_handler.overlay_eq = $("#overlay_custom_content_eq");
- $global_handler.overlay_skill = $("#overlay_custom_content_skill");
- var ov_inv_p = $global_handler.overlay_inv.parent();
- var ov_eq_p = $global_handler.overlay_eq.parent();
- var ov_skill_p = $global_handler.overlay_skill.parent();
- // non li mostro all'inizio
- ov_inv_p.hide();
- ov_eq_p.hide();
- ov_skill_p.hide();
- // draggable
- ov_inv_p.draggable();
- ov_eq_p.draggable();
- ov_skill_p.draggable();
- }
- function _prepare_listeners() {
- MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
- const mutation_inveq_temp = new MutationObserver(function (mutations, observer) {
- var overlay_equip_container = $(".cdk-overlay-container");
- // scarto qualunque evento finche trovo il contenitore
- if (!overlay_equip_container.length)
- return;
- // console.log("trovato eqinv...");
- // mi disconnetto
- this.disconnect();
- // mi attacco al nuovo
- $global_handler.mutation_inveq = new MutationObserver(update_eqine);
- //console.log("attaching observer");
- overlay_equip_container.each(function () {
- console.log("attacching DOM listeners..");
- $global_handler.mutation_inveq.observe(this, {
- subtree: true,
- childList: true
- });
- console.log("attacching button listeners..");
- // attacco i nuovi listeners
- var mainButtons = $(".tg-main-buttons button");
- $global_handler.pg_button = mainButtons[0];
- $global_handler.equip_button = mainButtons[1];
- $global_handler.inventory_button = mainButtons[2];
- $global_handler.skill_button = mainButtons[3];
- $global_handler.pref_button = mainButtons[5];
- var last_clicked;
- var elem_dialogs = $(".cdk-overlay-container");
- var update_dialogs = function (button) {
- if (elem_dialogs.is(":visible")) {
- if (last_clicked === button) {
- elem_dialogs.hide();
- elem_dialogs.css("z-index", "-1");
- }
- } else {
- elem_dialogs.show();
- elem_dialogs.css("z-index", "1000");
- }
- last_clicked = button;
- };
- var update_overlays = function (overlay, button) {
- if (overlay.is(":visible")) {
- if (last_clicked === button) {
- overlay.hide();
- }
- } else {
- overlay.show();
- }
- last_clicked = button;
- };
- $($global_handler.pg_button).click(function () {
- console.log("clicked pg");
- update_dialogs(this);
- });
- $($global_handler.equip_button).click(function () {
- console.log("clicked equip");
- update_overlays($global_handler.overlay_eq.parent(), this);
- });
- $($global_handler.inventory_button).click(function () {
- console.log("clicked inventory");
- update_overlays($global_handler.overlay_inv.parent(), this);
- });
- $($global_handler.skill_button).click(function () {
- console.log("clicked skill");
- update_overlays($global_handler.overlay_skill.parent(), this);
- });
- $($global_handler.pref_button).click(function () {
- console.log("clicked preference");
- elem_dialogs.show();
- last_clicked = this;
- });
- });
- overlay_equip_container.hide();
- // overlay_equip_container.css("z-index", "0");
- });
- // partiamo ascoltando su body fino a che non compare il container, poi ci stacchiamo e riattacchiamo al nuovo
- $("body").each(function () {
- mutation_inveq_temp.observe(this, {
- subtree: true,
- childList: true
- });
- });
- }
- function prepare_everything() {
- $global_handler = {};
- _prepare_css();
- _add_overlay();
- _prepare_listeners();
- // var regex_rimuovi = /(ri\s)|(rim\s)|(rimuovi\s) \d+/g;
- //
- // var input_word = "";
- // $('input[name="sendinput"]').keypress(function (event) {
- //
- // if (event.which === 13) {
- //
- // if (input_word.match(regex_rimuovi)) {
- // // è comando rimuovi
- // console.log("comando rimuovi individuato");
- // $(this).val("eq;inv;");
- // $(this).trigger(jQuery.Event("keypress", {which: 13}));
- // input_word = "";
- // }
- // return;
- // }
- // input_word = $(this).val();
- //
- // });
- }
- (
- function () {
- if (window.global_handler !== undefined) {
- return;
- }
- var get$ = function () {
- if (window.jQuery) {
- get$UI();
- } else {
- var s = document.createElement('script');
- s.onload = get$UI;
- s.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js');
- document.body.appendChild(s);
- }
- };
- var get$UI = function () {
- if (window.jQuery.ui) {
- onReady();
- } else {
- var s = document.createElement('script');
- s.onload = onReady;
- s.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js');
- document.body.appendChild(s);
- }
- };
- var onReady = function () {
- console.log("creo engine");
- prepare_everything();
- };
- get$();
- }
- )();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement