hwm_change_class

change class in one click

Stan na 07-12-2023. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         hwm_change_class
// @namespace    http://tampermonkey.net/
// @version      2.1
// @author       Лосось
// @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://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: '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('a');
        link.innerHTML = `<a title=${el.name} href='${el.href}'><img style='width: 20px; height: 20px;' src=${el.imgHref} alt=${el.name}/></a>`;
        block.appendChild(link);
    })

    if (location.href.match(/fr_changed_to/gi) !== null && location.href.match(/fr_changed_to/gi).length !== 0) {
        location.replace(`${link}/home.php`);
    }
})();