hwm_change_class

change class in one click

当前为 2024-03-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name hwm_change_class
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.4
  5. // @author Лосось
  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.  
  20. if (!myId) {
  21. localStorage.setItem('myId', currentId);
  22. location.reload();
  23. }
  24.  
  25. let links = ['https://my.lordswm.com', 'https://www.heroeswm.ru'];
  26.  
  27. let link = location.href.slice(0,22) === 'https://my.lordswm.com' ? links[0] : links[1];
  28.  
  29. let fetchCode = async () => {
  30. fetch(`${link}/castle.php?show_castle_f=1`)
  31. .then(function(response) {
  32. return response.text()
  33. })
  34. .then(function(html) {
  35. var parser = new DOMParser();
  36. var doc = parser.parseFromString(html, "text/html");
  37. var element = doc.getElementsByClassName('castle_yes_no_buttons')[0].getElementsByTagName('a')[0].href;
  38. var code = element.slice(-32);
  39. var plId = document.cookie.match(/pl_id=\d*/gi);
  40. localStorage.setItem('myCode', code);
  41. })
  42. .catch(function(err) {
  43. });
  44. }
  45.  
  46. if (!myCode) fetchCode();
  47.  
  48. if (myId !== currentId) {
  49. fetchCode();
  50. localStorage.setItem('myId', currentId);
  51. }
  52.  
  53. let newInterface = document.getElementsByClassName('home_pers_block')[0];
  54.  
  55. let oldInterface = [...document.getElementsByTagName('b')];
  56. oldInterface = oldInterface.filter(el => el.textContent === 'Ваш Персонаж')[0];
  57.  
  58. var parentNewInterface = document.getElementsByClassName('home_container_block')[4];
  59.  
  60. let block = document.createElement('div');
  61. block.style = 'display: flex; justify-content: center;'
  62.  
  63. if (oldInterface) {
  64. if (location.href === `${link}/home.php`) {
  65. oldInterface.appendChild(block);
  66. }
  67. }
  68. if (newInterface) {
  69. if (location.href === `${link}/home.php`) {
  70. newInterface.insertBefore(block, newInterface.firstChild);
  71. }
  72. }
  73.  
  74. const classes = [
  75. {name: 'knight', imgHref: 'https://cfcdn.lordswm.com/i/f/r1.png?v=1.1', href: `${link}/castle.php?change_clr_to=1&sign=${myCode}`},
  76. {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}`},
  77. {name: 'necr', imgHref: 'https://cfcdn.lordswm.com/i/f/r2.png?v=1.1', href: `${link}/castle.php?change_clr_to=2&sign=${myCode}`},
  78. {name: 'nps', imgHref: 'https://cfcdn.lordswm.com/i/f/r102.png?v=1.1', href: `${link}/castle.php?change_clr_to=102&sign=${myCode}`},
  79. {name: 'mage', imgHref: 'https://cfcdn.lordswm.com/i/f/r3.png?v=1.1', href: `${link}/castle.php?change_clr_to=3&sign=${myCode}`},
  80. {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}`},
  81. {name: 'elf', imgHref: 'https://cfcdn.lordswm.com/i/f/r4.png?v=1.1', href: `${link}/castle.php?change_clr_to=4&sign=${myCode}`},
  82. {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}`},
  83. {name: 'barb', imgHref: 'https://cfcdn.lordswm.com/i/f/r5.png?v=1.1', href: `${link}/castle.php?change_clr_to=5&sign=${myCode}`},
  84. {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}`},
  85. {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}`},
  86. {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}`},
  87. {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}`},
  88. {name: 'demon', imgHref: 'https://cfcdn.lordswm.com/i/f/r7.png?v=1.1', href: `${link}/castle.php?change_clr_to=7&sign=${myCode}`},
  89. {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}`},
  90. {name: 'dwarf', imgHref: 'https://cfcdn.lordswm.com/i/f/r8.png?v=1.1', href: `${link}/castle.php?change_clr_to=8&sign=${myCode}`},
  91. {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}`},
  92. {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}`},
  93. {name: 'pharaon', imgHref: 'https://cfcdn.lordswm.com/i/f/r10.png?v=1.1', href: `${link}/castle.php?change_clr_to=10&sign=${myCode}`},
  94.  
  95. ];
  96. classes.forEach(el => {
  97. let link = document.createElement('div');
  98. link.innerHTML = `<div title=${el.name}><img style='width: 20px; height: 20px; cursor: pointer;' src=${el.imgHref} alt=${el.name}/></div>`;
  99. link.addEventListener('click', () => {
  100. let fetchChange = async() => {
  101. fetch(el.href).then(response => {
  102. if (response.status === 200) {
  103. location.reload();
  104. }
  105. });
  106. }
  107. fetchChange();
  108.  
  109. })
  110. block.appendChild(link);
  111. });
  112. })();