hwm_change_class

change class in one click

  1. // ==UserScript==
  2. // @name hwm_change_class
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.5.1
  5. // @author SalmonGOD
  6. // @description change class in one click
  7. // @match /^https{0,1}:\/\/((www|qrator|my)\.(heroeswm|lordswm)\.(ru|com)|178\.248\.235\.15)\/(home|castle).php*/
  8. // @include /^https{0,1}:\/\/((www|qrator|my)\.(heroeswm|lordswm)\.(ru|com)|178\.248\.235\.15)\/(home|castle).php*/
  9. // @license MIT
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. let myCode = localStorage.getItem('myCode');
  17. let currentId = document.cookie.match(/pl_id=\d*/gi).join('');
  18. let myId = localStorage.getItem('myId');
  19. let updates_popup_changeClass_toogle = JSON.parse(localStorage.getItem('updates_popup_changeClass_toogle'));
  20.  
  21. if (!myId) {
  22. localStorage.setItem('myId', currentId);
  23. location.reload();
  24. }
  25.  
  26. if (updates_popup_changeClass_toogle === null) {
  27. localStorage.setItem('updates_popup_changeClass_toogle', JSON.stringify(true));
  28. location.reload();
  29. }
  30.  
  31. let links = ['https://my.lordswm.com', 'https://www.heroeswm.ru'];
  32.  
  33. let link = location.href.slice(0,22) === 'https://my.lordswm.com' ? links[0] : links[1];
  34.  
  35. let fetchCode = async () => {
  36. fetch(`${link}/castle.php?show_castle_f=1`)
  37. .then(function(response) {
  38. return response.text()
  39. })
  40. .then(function(html) {
  41. var parser = new DOMParser();
  42. var doc = parser.parseFromString(html, "text/html");
  43. var element = doc.getElementsByClassName('castle_yes_no_buttons')[0].getElementsByTagName('a')[0].href;
  44. var code = element.slice(-32);
  45. var plId = document.cookie.match(/pl_id=\d*/gi);
  46. localStorage.setItem('myCode', code);
  47. })
  48. .catch(function(err) {
  49. });
  50. }
  51.  
  52. if (!myCode) fetchCode();
  53.  
  54. if (myId !== currentId) {
  55. fetchCode();
  56. localStorage.setItem('myId', currentId);
  57. }
  58.  
  59. let newInterface = document.getElementsByClassName('home_pers_block')[0];
  60.  
  61. let oldInterface = [...document.getElementsByTagName('b')];
  62. oldInterface = oldInterface.filter(el => el.textContent === 'Ваш Персонаж')[0];
  63.  
  64. var parentNewInterface = document.getElementsByClassName('home_container_block')[4];
  65.  
  66. let block = document.createElement('div');
  67. block.style = 'display: flex; justify-content: center;'
  68.  
  69. if (oldInterface) {
  70. if (location.href === `${link}/home.php`) {
  71. let charBtn = [...document.getElementsByTagName('b')];
  72. charBtn = charBtn.filter(el => el.innerText == 'Ваш Персонаж')[0];
  73. charBtn.style.cursor = 'pointer';
  74. charBtn.title = 'Нажмите на кнопку "Персонаж" для повторной загрузки своего уникального кода (в случае смены ника)'
  75. charBtn.addEventListener('click', () => fetchCode())
  76. oldInterface.appendChild(block);
  77. }
  78. }
  79. if (newInterface) {
  80. if (location.href === `${link}/home.php`) {
  81. let charBtn = [...document.getElementsByClassName('global_container_block_header')];
  82. charBtn = charBtn.filter(el => el.innerText === 'Персонаж')[0];
  83. charBtn.style.cursor = 'pointer';
  84. charBtn.title = 'Нажмите на кнопку "Персонаж" для повторной загрузки своего уникального кода (в случае смены ника)'
  85. charBtn.addEventListener('click', () => fetchCode())
  86. newInterface.insertBefore(block, newInterface.firstChild);
  87. }
  88. }
  89.  
  90. const classes = [
  91. {name: 'knight', imgHref: 'https://cfcdn.lordswm.com/i/f/r1.png?v=1.1', href: `${link}/castle.php?change_clr_to=1&sign=${myCode}`},
  92. {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}`},
  93. {name: 'necr', imgHref: 'https://cfcdn.lordswm.com/i/f/r2.png?v=1.1', href: `${link}/castle.php?change_clr_to=2&sign=${myCode}`},
  94. {name: 'nps', imgHref: 'https://cfcdn.lordswm.com/i/f/r102.png?v=1.1', href: `${link}/castle.php?change_clr_to=102&sign=${myCode}`},
  95. {name: 'mage', imgHref: 'https://cfcdn.lordswm.com/i/f/r3.png?v=1.1', href: `${link}/castle.php?change_clr_to=3&sign=${myCode}`},
  96. {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}`},
  97. {name: 'elf', imgHref: 'https://cfcdn.lordswm.com/i/f/r4.png?v=1.1', href: `${link}/castle.php?change_clr_to=4&sign=${myCode}`},
  98. {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}`},
  99. {name: 'barb', imgHref: 'https://cfcdn.lordswm.com/i/f/r5.png?v=1.1', href: `${link}/castle.php?change_clr_to=5&sign=${myCode}`},
  100. {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}`},
  101. {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}`},
  102. {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}`},
  103. {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}`},
  104. {name: 'demon', imgHref: 'https://cfcdn.lordswm.com/i/f/r7.png?v=1.1', href: `${link}/castle.php?change_clr_to=7&sign=${myCode}`},
  105. {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}`},
  106. {name: 'dwarf', imgHref: 'https://cfcdn.lordswm.com/i/f/r8.png?v=1.1', href: `${link}/castle.php?change_clr_to=8&sign=${myCode}`},
  107. {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}`},
  108. {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}`},
  109. {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}`},
  110. {name: 'pharaon', imgHref: 'https://cfcdn.lordswm.com/i/f/r10.png?v=1.1', href: `${link}/castle.php?change_clr_to=10&sign=${myCode}`},
  111.  
  112. ];
  113. classes.forEach(el => {
  114. let link = document.createElement('div');
  115. link.innerHTML = `<div title=${el.name}><img style='width: 19px; height: 19px; cursor: pointer;' src=${el.imgHref} alt=${el.name}/></div>`;
  116. link.addEventListener('click', () => {
  117. let fetchChange = async() => {
  118. fetch(el.href).then(response => {
  119. if (response.status === 200) {
  120. location.reload();
  121. }
  122. });
  123. }
  124. fetchChange();
  125.  
  126. })
  127. block.appendChild(link);
  128. });
  129.  
  130. const updates_popup = document.createElement('div');
  131. updates_popup.innerText = 'Изминения в скрипте "смена классов":';
  132. updates_popup.style = 'position: absolute; top: 125px; left: 15px; width: 200px; height: 200px; border: 1px solid black; background: white; padding: 10px; border-radius: 4px;';
  133. if (updates_popup_changeClass_toogle === true) {
  134. console.log('here1')
  135. updates_popup.style.display = 'block'
  136. } else if (updates_popup_changeClass_toogle === false) {
  137. console.log('here2')
  138. updates_popup.style.display = 'none'
  139. }
  140. const updates_text = document.createElement('div');
  141. updates_text.innerText = '1. Добавлена возможность обновить свой "уникальный" код, в случае смены ника нажав на текст "Персонаж" для нового интерфейса или "Ваш персонаж" для старого интерфейса';
  142. updates_text.style = 'font-weight: bold; border-top: 1px solid black';
  143. const close_popup_btn = document.createElement('div');
  144. close_popup_btn.innerText = 'Ознакомился';
  145. close_popup_btn.style = 'background: #00ff99; width: 110px; height: 20px; text-align: center; border-radius: 7px; cursor: pointer; font-weight: bold; margin-top: 30px; margin-left: 90px;';
  146. close_popup_btn.addEventListener('click', () => {
  147. updates_popup.style.display = 'none';
  148. localStorage.setItem('updates_popup_changeClass_toogle', false);
  149. })
  150. updates_popup.append(updates_text);
  151. updates_popup.append(close_popup_btn);
  152. document.body.append(updates_popup);
  153. })();