hwm_change_class

change class in one click

Versione datata 12/02/2025. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         hwm_change_class
// @namespace    http://tampermonkey.net/
// @version      2.4.1
// @author       SalmonGOD
// @description  change class in one click
// @match        /^https{0,1}:\/\/((www|qrator|my)\.(heroeswm|lordswm)\.(ru|com)|178\.248\.235\.15)\/(home|castle).php*/
// @include      /^https{0,1}:\/\/((www|qrator|my)\.(heroeswm|lordswm)\.(ru|com)|178\.248\.235\.15)\/(home|castle).php*/
// @license MIT
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    let myCode = localStorage.getItem('myCode');
    let currentId = document.cookie.match(/pl_id=\d*/gi).join('');
    let myId = localStorage.getItem('myId');

    if (!myId) {
        localStorage.setItem('myId', currentId);
        location.reload();
    }

    let links = ['https://my.lordswm.com', 'https://www.heroeswm.ru'];

    let link = location.href.slice(0,22) === 'https://my.lordswm.com' ? links[0] : links[1];

    let fetchCode = async () => {
        fetch(`${link}/castle.php?show_castle_f=1`)
            .then(function(response) {
            return response.text()
        })
            .then(function(html) {
            var parser = new DOMParser();
            var doc = parser.parseFromString(html, "text/html");
            var element = doc.getElementsByClassName('castle_yes_no_buttons')[0].getElementsByTagName('a')[0].href;
            var code = element.slice(-32);
            var plId = document.cookie.match(/pl_id=\d*/gi);
            localStorage.setItem('myCode', code);
        })
            .catch(function(err) {
        });
    }

    if (!myCode) fetchCode();

    if (myId !== currentId) {
        fetchCode();
        localStorage.setItem('myId', currentId);
    }

    let newInterface = document.getElementsByClassName('home_pers_block')[0];

    let oldInterface = [...document.getElementsByTagName('b')];
    oldInterface = oldInterface.filter(el => el.textContent === 'Ваш Персонаж')[0];

    var parentNewInterface = document.getElementsByClassName('home_container_block')[4];

    let block = document.createElement('div');
        block.style = 'display: flex; justify-content: center;'

    if (oldInterface) {
       if (location.href === `${link}/home.php`) {
        oldInterface.appendChild(block);
       }
    }
    if (newInterface) {
       if (location.href === `${link}/home.php`) {
           newInterface.insertBefore(block, newInterface.firstChild);
       }
    }

    const classes = [
        {name: 'knight', imgHref: 'https://cfcdn.lordswm.com/i/f/r1.png?v=1.1', href: `${link}/castle.php?change_clr_to=1&sign=${myCode}`},
        {name: 'light_knight', imgHref: 'https://cfcdn.lordswm.com/i/f/r101.png?v=1.1', href: `${link}/castle.php?change_clr_to=101&sign=${myCode}`},
        {name: 'necr', imgHref: 'https://cfcdn.lordswm.com/i/f/r2.png?v=1.1', href: `${link}/castle.php?change_clr_to=2&sign=${myCode}`},
        {name: 'nps', imgHref: 'https://cfcdn.lordswm.com/i/f/r102.png?v=1.1', href: `${link}/castle.php?change_clr_to=102&sign=${myCode}`},
        {name: 'mage', imgHref: 'https://cfcdn.lordswm.com/i/f/r3.png?v=1.1', href: `${link}/castle.php?change_clr_to=3&sign=${myCode}`},
        {name: 'mage_destroyer', imgHref: 'https://cfcdn.lordswm.com/i/f/r103.png?v=1.1', href: `${link}/castle.php?change_clr_to=103&sign=${myCode}`},
        {name: 'elf', imgHref: 'https://cfcdn.lordswm.com/i/f/r4.png?v=1.1', href: `${link}/castle.php?change_clr_to=4&sign=${myCode}`},
        {name: 'blue_elf', imgHref: 'https://cfcdn.lordswm.com/i/f/r104.png?v=1.1', href: `${link}/castle.php?change_clr_to=104&sign=${myCode}`},
        {name: 'barb', imgHref: 'https://cfcdn.lordswm.com/i/f/r5.png?v=1.1', href: `${link}/castle.php?change_clr_to=5&sign=${myCode}`},
        {name: 'blood_barb', imgHref: 'https://cfcdn.lordswm.com/i/f/r105.png?v=1.1', href: `${link}/castle.php?change_clr_to=105&sign=${myCode}`},
        {name: 'witch_barb', imgHref: 'https://cfcdn.lordswm.com/i/f/r205.png?v=1.1', href: `${link}/castle.php?change_clr_to=205&sign=${myCode}`},
        {name: 'dark_elf', imgHref: 'https://cfcdn.lordswm.com/i/f/r6.png?v=1.1', href: `${link}/castle.php?change_clr_to=6&sign=${myCode}`},
        {name: 'dark_elf_tamer', imgHref: 'https://cfcdn.lordswm.com/i/f/r106.png?v=1.1', href: `${link}/castle.php?change_clr_to=106&sign=${myCode}`},
        {name: 'demon', imgHref: 'https://cfcdn.lordswm.com/i/f/r7.png?v=1.1', href: `${link}/castle.php?change_clr_to=7&sign=${myCode}`},
        {name: 'dark_demon', imgHref: 'https://cfcdn.lordswm.com/i/f/r107.png?v=1.1', href: `${link}/castle.php?change_clr_to=107&sign=${myCode}`},
        {name: 'dwarf', imgHref: 'https://cfcdn.lordswm.com/i/f/r8.png?v=1.1', href: `${link}/castle.php?change_clr_to=8&sign=${myCode}`},
        {name: 'flame_dwarf', imgHref: 'https://cfcdn.lordswm.com/i/f/r108.png?v=1.1', href: `${link}/castle.php?change_clr_to=108&sign=${myCode}`},
        {name: 'steppe_barb', imgHref: 'https://cfcdn.lordswm.com/i/f/r9.png?v=1.1', href: `${link}/castle.php?change_clr_to=9&sign=${myCode}`},
        {name: 'rage_steppe_barb', imgHref: 'https://cfcdn.lordswm.com/i/f/r109.png?v=1.1', href: `${link}/castle.php?change_clr_to=109&sign=${myCode}`},
        {name: 'pharaon', imgHref: 'https://cfcdn.lordswm.com/i/f/r10.png?v=1.1', href: `${link}/castle.php?change_clr_to=10&sign=${myCode}`},

    ];
    classes.forEach(el => {
        let link = document.createElement('div');
        link.innerHTML = `<div title=${el.name}><img style='width: 19px; height: 19px; cursor: pointer;' src=${el.imgHref} alt=${el.name}/></div>`;
        link.addEventListener('click', () => {
            let fetchChange = async() => {
                fetch(el.href).then(response => {
                    if (response.status === 200) {
                        location.reload();
                    }
                });
            }
            fetchChange();

        })
        block.appendChild(link);
    });
})();