HWM_Resource_Retabler

Меняет разметку вкладки ресурсов под нужды других скриптов

2022-07-06 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

بۇ قوليازمىنى بىۋاسىتە قاچىلاشقا بولمايدۇ. بۇ باشقا قوليازمىلارنىڭ ئىشلىتىشى ئۈچۈن تەمىنلەنگەن ئامبار بولۇپ، ئىشلىتىش ئۈچۈن مېتا كۆرسەتمىسىگە قىستۇرىدىغان كود: // @require https://update.greasyfork.org/scripts/447488/1067710/HWM_Resource_Retabler.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         HWM_Resource_Retabler
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Меняет разметку вкладки ресурсов под нужды других скриптов
// @author       Tags
// @include      /^https{0,1}:\/\/(www\.heroeswm\.ru|178\.248\.235\.15|my\.lordswm\.com)\/(pl_info.php*)/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=heroeswm.ru
// @grant        none
// ==/UserScript==

window.MercenaryElements = {
    "абразив":{
        id: "EL_42",
        art_type: "abrasive"
    }, "змеиный яд":{
        id: "EL_43",
        art_type: "snake_poison"
    }, "клык тигра":{
        id: "EL_46",
        art_type: "tiger_tusk"
    }, "ледяной кристалл":{
        id: "EL_44",
        art_type: "ice_crystal"
    }, "лунный камень":{
        id: "EL_45",
        art_type: "moon_stone"
    }, "огненный кристалл":{
        id: "EL_40",
        art_type: "fire_crystal"
    }, "осколок метеорита":{
        id: "EL_37",
        art_type: "meteorit"
    }, "цветок ведьм":{
        id: "EL_41",
        art_type: "witch_flower"
    }, "цветок ветров":{
        id: "EL_39",
        art_type: "wind_flower"
    }, "цветок папоротника":{
        id: "EL_78",
        art_type: "fern_flower"
    }, "ядовитый гриб":{
        id: "EL_38",
        art_type: "badgrib"
    },};

(function() {
    'use strict';

    const tables = Array.from(document.getElementsByClassName('wb'));
    const resourceTable = tables[tables.indexOf(tables.filter(e=>e.innerText=="Ресурсы")[0])+3]

    //Вытаскиваем все доступные элементы и превращаем в объекты.
    const items = resourceTable.innerHTML.split(/&nbsp;/).filter(e => e !== "").map(s => s.replaceAll("<b>", "").replaceAll("<br>", "").replaceAll("</b>", "")).map(e => ({
        name: e.split(':')[0],
        value: e.split(':')[1],
        isMercenary: window.MercenaryElements[e.split(':')[0]]!==undefined,
    }));

    const parts = items.filter(e=>!e.isMercenary);
    const mercenary = items.filter(e=>e.isMercenary);
    //Чистим табличку
    resourceTable.innerHTML = "";

    //Записываем новую разметку
    for (let item of parts) {
        const div = Object.assign(
            document.createElement('div'), {
                innerHTML: `<div>&nbsp;&nbsp;&nbsp;&nbsp;<b>${item.name}</b>:&nbsp;${item.value}</div>`,

            });;
        div.setAttribute('ismercenary', item.isMercenary);
        div.setAttribute('name', item.name);
        resourceTable.appendChild(div);
    }
    const splitter = Object.assign(
        document.createElement('div'), {
            innerHTML: `<div name="splitter"><br></div>`,

        });;
    if(parts.length>0){
        resourceTable.appendChild(splitter);
    }
    for (let item of mercenary) {
        const div = Object.assign(
            document.createElement('div'), {
                innerHTML: `<div">&nbsp;&nbsp;&nbsp;&nbsp;<b>${item.name}</b>:&nbsp;${item.value}</div>`,

            });;
        div.setAttribute('ismercenary', item.isMercenary);
        div.setAttribute('name', item.name);
        resourceTable.appendChild(div);
    }
})();