// ==UserScript==
// @name hwm_change_class
// @namespace http://tampermonkey.net/
// @version 2.0
// @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('global_container_block_header')];
newInterface = newInterface.filter(el => el.textContent === 'Персонаж')[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`) {
parentNewInterface.insertBefore(block, parentNewInterface.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 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`);
}
})();