hwm_forum_ban

changing messages of your enemies to any text that you want

  1. // ==UserScript==
  2. // @name hwm_forum_ban
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.01
  5. // @author Лосось
  6. // @description changing messages of your enemies to any text that you want
  7. // @match /^https{0,1}:\/\/((www|qrator|my)\.(heroeswm|lordswm)\.(ru|com)|178\.248\.235\.15)\/(forum_messages).php*/
  8. // @include /^https{0,1}:\/\/((www|qrator|my)\.(heroeswm|lordswm)\.(ru|com)|178\.248\.235\.15)\/(forum_messages).php*/
  9. // @license MIT
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. //init UI elements
  16. let fragment = document.createElement('div');
  17.  
  18. let showScriptBtn = document.createElement('button');
  19. showScriptBtn.innerText = 'Ban List';
  20.  
  21. let addNewHeroBtn = document.createElement('button');
  22. addNewHeroBtn.innerText = 'Add new hero';
  23.  
  24. let inputHero = document.createElement('input');
  25. inputHero.placeholder = 'enter hero nickname';
  26.  
  27. let inputHeroText = document.createElement('input');
  28. inputHeroText.placeholder = 'enter hero text';
  29.  
  30. let banList = document.createElement('ul');
  31.  
  32. //init variables and constants
  33. let isShowScriptLS = JSON.parse(localStorage.getItem('hwmScriptToogle'));
  34.  
  35. let nicks = JSON.parse(localStorage.getItem('nicks'));
  36.  
  37. let isShowScript = isShowScriptLS;
  38.  
  39. let messages = [...document.querySelectorAll('.message_footer')];
  40.  
  41. // init saved data
  42.  
  43. if (!isShowScriptLS) {
  44. localStorage.setItem('hwmScriptToogle', JSON.stringify(false));
  45. }
  46.  
  47. if (!nicks) {
  48. localStorage.setItem('nicks', JSON.stringify([]));
  49. location.reload();
  50. }
  51.  
  52. // add event listeners to ui
  53.  
  54. showScriptBtn.addEventListener('click', () => {
  55. isShowScript = !isShowScript;
  56. localStorage.setItem('hwmScriptToogle', isShowScript);
  57. fragment.style.visibility = isShowScript ? 'visible' : 'hidden';
  58. })
  59.  
  60. addNewHeroBtn.addEventListener('click', () => {
  61. if (!inputHero.value.length) {
  62. alert('enter a nickname!');
  63. return;
  64. };
  65. let newHero = {
  66. id: new Date().getTime(),
  67. text: inputHeroText.value,
  68. nick: inputHero.value,
  69. }
  70. nicks.push(newHero);
  71. localStorage.setItem('nicks', JSON.stringify(nicks));
  72. location.reload();
  73. })
  74.  
  75. // add styles to ui
  76.  
  77. showScriptBtn.style = 'position: absolute; right: 10px; top: 2px; z-index: 999998'
  78. fragment.style = 'background: DarkKhaki; position: absolute; right: 10px; top: 25px; min-height: 100px; min-width: 300px; display: flex; flex-direction: column; z-index: 999999'
  79. fragment.style.visibility = isShowScript ? 'visible' : 'hidden';
  80.  
  81. // parsing posts and making changes
  82.  
  83. for (let i = 0; i < messages.length; i++) {
  84. for (let j = 0; j < nicks.length; j++) {
  85. if (messages[i].getElementsByTagName('a')[0].innerText.toLowerCase() === nicks[j].nick.toLowerCase() || messages[i].getElementsByTagName('a')[1].innerText.toLowerCase() === nicks[j].nick.toLowerCase()) {
  86. messages[i].nextSibling.innerText = nicks[j].text;
  87. messages[i].nextSibling.style = 'color: #000000; padding: 5px;font-size: 0.8125em;';
  88. }
  89. }
  90. }
  91.  
  92. for (let i = 0; i < nicks.length; i++) {
  93. let listElement = document.createElement('li');
  94. let bannedNick = document.createElement('span');
  95. let bannedNickText = document.createElement('span');
  96.  
  97. bannedNick.innerText = nicks[i].nick;
  98. bannedNickText.innerText = nicks[i].text;
  99.  
  100. bannedNick.style = 'padding: 5px; background: FloralWhite'
  101. bannedNickText.style = 'padding: 5px; background: Gainsboro'
  102.  
  103. let deleteBtn = document.createElement('button');
  104. deleteBtn.style = 'width: 25px; height: 25px; border: none; cursor: pointer; margin-left: 5px; border-radius: 15px;';
  105. deleteBtn.innerText = 'X';
  106.  
  107. listElement.appendChild(bannedNick)
  108. listElement.appendChild(bannedNickText)
  109. listElement.appendChild(deleteBtn)
  110.  
  111. deleteBtn.addEventListener('click', () => {
  112. nicks = nicks.filter(nick => nick.id !== nicks[i].id);
  113. localStorage.setItem('nicks', JSON.stringify(nicks));
  114. location.reload();
  115. })
  116. banList.appendChild(listElement);
  117. }
  118.  
  119. fragment.appendChild(inputHero);
  120. fragment.appendChild(inputHeroText);
  121. fragment.appendChild(addNewHeroBtn);
  122. fragment.appendChild(banList);
  123.  
  124. document.body.appendChild(fragment);
  125. document.body.appendChild(showScriptBtn);
  126. })();