Greasy Fork is available in English.

Hide Mandiner User

Userscript for hiding mandiner.hu's users

  1. // ==UserScript==
  2. // @name Hide Mandiner User
  3. // @name:hu Mandiner Hozzászóló Elrejtő
  4. // @description Userscript for hiding mandiner.hu's users
  5. // @description:hu Felhasználói szkript a mandiner.hu felhasználóinak elrejtéséhez
  6. // @icon https://mandiner.hu/images/favicon.png
  7. // @version 5.0
  8. // @license MIT
  9. // @include https://*mandiner.hu/cikk/*
  10. // @grant none
  11. // @namespace https://greasyfork.org/users/412587
  12. // ==/UserScript==
  13. let comments = document.querySelectorAll('.comment'),
  14. disabledUsers = window.localStorage.getItem('disabledUsers') === null ? [] : JSON.parse(window.localStorage.getItem('disabledUsers')),
  15. hideDisabledUsers = window.localStorage.getItem('hideDisabledUsers') === null ? 'false' : window.localStorage.getItem('hideDisabledUsers'),
  16. commentsHead = document.querySelector('.comments-head'),
  17. headerDisabledUsers = document.createElement('h5'),
  18. searchBox = document.createElement('div'),
  19. searchHeader = document.createElement('div'),
  20. searchContent = document.createElement('div'),
  21. searchField = document.createElement('input'),
  22. searchButton = document.createElement('button'),
  23. searchBreak = document.createElement('br'),
  24. resultField = document.createElement('textarea'),
  25. searchFooter = document.createElement('div'),
  26. addUsersButton = document.createElement('button'),
  27. buttonImportUsers = document.createElement('button');
  28. console.log('Comments: ' + comments.length);
  29. console.log('Disabled users: ' + disabledUsers.length);
  30.  
  31. headerDisabledUsers.innerText = '▼ Némított felhasználók';
  32. headerDisabledUsers.style.cursor = 'pointer';
  33. buttonImportUsers.style.padding = '0.25em';
  34. buttonImportUsers.style.margin = '0.25em';
  35. buttonImportUsers.style.backgroundColor = '#517491';
  36. buttonImportUsers.style.color = '#fff';
  37. buttonImportUsers.style.fontWeight = 'bold';
  38. buttonImportUsers.innerText = '📂 Importálás';
  39.  
  40. searchBox.setAttribute('id', 'searchBox');
  41. searchBox.style.border = '1px solid #000';
  42. searchBox.style.margin = '0.25em';
  43. searchBox.style.width = 'fit-content';
  44.  
  45. searchHeader.setAttribute('id', 'searchHeader');
  46. searchHeader.innerText = '▶ Tömeges felhasználó tiltás';
  47. searchHeader.style.borderBottom = '1px solid #000';
  48. searchHeader.style.padding = '0.25em';
  49. searchHeader.style.cursor = 'pointer';
  50. searchHeader.onclick = () => {
  51. if (searchContent.style.display == 'none') {
  52. searchContent.style.display = 'block';
  53. searchFooter.style.display = 'block';
  54. searchHeader.innerText = searchHeader.innerText.replace('▶', '▼');
  55. } else {
  56. searchContent.style.display = 'none';
  57. searchFooter.style.display = 'none';
  58. searchHeader.innerText = searchHeader.innerText.replace('▼', '▶');
  59. }
  60. };
  61.  
  62. searchContent.setAttribute('id', 'searchContent');
  63. searchContent.style.padding = '0.25em';
  64. searchContent.style.display = 'none';
  65. searchField.setAttribute('id', 'searchField');
  66. searchField.setAttribute('placeholder','Felhasználónév-részlet');
  67. searchField.style.border = '1px solid #000';
  68. searchButton.innerText = '🔎';
  69. searchButton.setAttribute('title', 'Felhasználó keresése')
  70. searchButton.style.padding = '0 0.25em';
  71. searchButton.style.marginLeft = '0.25em';
  72. searchButton.style.backgroundColor = '#517491';
  73. resultField.style.marginTop = '0.25em';
  74. resultField.setAttribute('rows','5');
  75. resultField.setAttribute('placeholder','Talált felhasználók');
  76. resultField.style.border = '1px solid #000';
  77. searchContent.appendChild(searchField);
  78. searchContent.appendChild(searchButton);
  79. searchContent.appendChild(searchBreak);
  80. searchContent.appendChild(resultField);
  81.  
  82. searchButton.onclick = () => {
  83. let searchUser = searchField.value,
  84. searchUserRegexp = new RegExp(searchUser, 'gi'),
  85. users = [];
  86. resultField.innerHTML = '';
  87.  
  88. for (let comment of comments) {
  89. let user = comment.querySelector('.commentuser').text;
  90. if (user != null || user != undefined) {
  91. users.push(user);
  92. }
  93. }
  94. users = [...new Set(users)].filter((v)=>v.match(searchUserRegexp));
  95. for (let user of users) {
  96. resultField.innerHTML += user + '\n';
  97. }
  98. addUsersButton.removeAttribute('disabled');
  99. };
  100.  
  101. searchFooter.setAttribute('id', 'searchFooter');
  102. searchFooter.style.borderTop = '1px solid #000';
  103. searchFooter.style.display = 'none';
  104. addUsersButton.innerText = '👥 Felhasználók tiltása';
  105. addUsersButton.style.padding = '0.25em';
  106. addUsersButton.style.margin = '0.25em';
  107. addUsersButton.style.backgroundColor = '#517491';
  108. addUsersButton.style.color = '#fff';
  109. addUsersButton.style.fontWeight = 'bold';
  110. addUsersButton.setAttribute('disabled', 'disabled');
  111. searchFooter.appendChild(addUsersButton);
  112.  
  113. addUsersButton.onclick = () => {
  114. let users = resultField.innerHTML.split('\n').filter((v) => v != '');
  115. users = [...new Set(users)]
  116. if (users.length !== 0) {
  117. for (let user of users) {
  118. if (user != '' && (disabledUsers.length == 0 || !disabledUsers.includes(user))) {
  119. disabledUsers.push(user);
  120. }
  121. }
  122. window.localStorage.setItem('disabledUsers', JSON.stringify(disabledUsers));
  123. window.location.reload(true);
  124. }
  125. };
  126.  
  127. searchBox.appendChild(searchHeader);
  128. searchBox.appendChild(searchContent);
  129. searchBox.appendChild(searchFooter);
  130.  
  131. commentsHead.appendChild(headerDisabledUsers);
  132. commentsHead.appendChild(searchBox);
  133. commentsHead.appendChild(buttonImportUsers);
  134.  
  135. buttonImportUsers.onclick = () => {
  136. let fileInput = document.createElement('input');
  137. fileInput.setAttribute('type', 'file');
  138. fileInput.setAttribute('accept', '.txt');
  139. fileInput.onchange = () => {
  140. let reader = new FileReader(),
  141. file = fileInput.files[0];
  142. reader.onload = (event) => {
  143. let newUsers = event.target.result.split('\n');
  144. if (newUsers.length !== 0) {
  145. for (let newUser of newUsers) {
  146. if (newUser != '' && (disabledUsers.length == 0 || !disabledUsers.includes(newUser))) {
  147. disabledUsers.push(newUser);
  148. }
  149. }
  150. window.localStorage.setItem('disabledUsers', JSON.stringify(disabledUsers));
  151. window.location.reload(true);
  152. }
  153. };
  154. reader.readAsText(file);
  155. };
  156. fileInput.click();
  157. };
  158.  
  159. if (disabledUsers.length > 0) {
  160. let commentsHead = document.querySelector('.comments-head'),
  161. listDisabledUsers = document.createElement('ul'),
  162. buttonExportUsers = document.createElement('button'),
  163. buttonClearUsers = document.createElement('button');
  164. if (hideDisabledUsers === 'true') {
  165. listDisabledUsers.setAttribute('style', 'display: none;');
  166. headerDisabledUsers.innerText = headerDisabledUsers.innerText.replace('▼', '▶');
  167. } else {
  168. listDisabledUsers.removeAttribute('style');
  169. headerDisabledUsers.innerText = headerDisabledUsers.innerText.replace('▶', '▼');
  170. }
  171. headerDisabledUsers.onclick = () => {
  172. if (listDisabledUsers.hasAttribute('style')) {
  173. listDisabledUsers.removeAttribute('style');
  174. headerDisabledUsers.innerText = headerDisabledUsers.innerText.replace('▶', '▼');
  175. window.localStorage.setItem('hideDisabledUsers', 'false');
  176. } else {
  177. listDisabledUsers.setAttribute('style', 'display: none;');
  178. headerDisabledUsers.innerText = headerDisabledUsers.innerText.replace('▼', '▶');
  179. window.localStorage.setItem('hideDisabledUsers', 'true');
  180. }
  181. };
  182. buttonClearUsers.innerText = '✓ Összes felhasználó engedélyezése';
  183. buttonClearUsers.style.padding = '0.25em';
  184. buttonClearUsers.style.margin = '0.25em';
  185. buttonClearUsers.style.backgroundColor = '#070';
  186. buttonClearUsers.style.color = '#fff';
  187. buttonClearUsers.style.fontWeight = 'bold';
  188. buttonExportUsers.style.padding = '0.25em';
  189. buttonExportUsers.style.margin = '0.25em';
  190. buttonExportUsers.style.backgroundColor = '#517491';
  191. buttonExportUsers.style.color = '#fff';
  192. buttonExportUsers.style.fontWeight = 'bold';
  193. buttonExportUsers.innerText = '💾 Exportálás';
  194. for (let disabledUser of disabledUsers) {
  195. let listItemDisabledUser = document.createElement('li'),
  196. spanDisabledUser = document.createElement('span'),
  197. buttonEnableUser = document.createElement('button');
  198. spanDisabledUser.innerText = disabledUser;
  199. buttonEnableUser.setAttribute('data-username',disabledUser);
  200. buttonEnableUser.innerText = '✓';
  201. buttonEnableUser.setAttribute('title', 'Engedélyezés');
  202. buttonEnableUser.style.border = '1px solid #fff';
  203. buttonEnableUser.style.backgroundColor = '#070';
  204. buttonEnableUser.style.color = '#fff';
  205. buttonEnableUser.style.padding = '0.25em';
  206. buttonEnableUser.style.margin = '0 0.25em';
  207. buttonEnableUser.style.fontWeight = 'bold';
  208. buttonEnableUser.onclick = () => {
  209. let userName = buttonEnableUser.getAttribute('data-username');
  210. disabledUsers = disabledUsers.filter(item => item !== userName);
  211. window.localStorage.setItem('disabledUsers', JSON.stringify(disabledUsers));
  212. window.location.reload(true);
  213. };
  214. listItemDisabledUser.appendChild(spanDisabledUser);
  215. listItemDisabledUser.appendChild(buttonEnableUser);
  216. listDisabledUsers.appendChild(listItemDisabledUser);
  217. }
  218. buttonExportUsers.onclick = () => {
  219. if (disabledUsers.length > 0) {
  220. let users = disabledUsers.join('\n'),
  221. downloadLink = document.createElement('a');
  222. downloadLink.setAttribute(
  223. 'href',
  224. window.URL.createObjectURL(
  225. new Blob(
  226. [users],
  227. {type: 'text/plain'}
  228. )
  229. )
  230. );
  231. downloadLink.setAttribute('download', 'users.txt');
  232. downloadLink.click();
  233. }
  234. };
  235. buttonClearUsers.onclick = () => {
  236. disabledUsers = [];
  237. window.localStorage.setItem('disabledUsers', JSON.stringify(disabledUsers));
  238. window.location.reload(true);
  239. };
  240. commentsHead.appendChild(buttonExportUsers);
  241. commentsHead.appendChild(buttonClearUsers);
  242. commentsHead.appendChild(listDisabledUsers);
  243. }
  244.  
  245. for (let comment of comments) {
  246. let user = comment.querySelector('.commentuser'),
  247. buttonDisableUser = document.createElement('button');
  248. if (user != null || user != undefined) {
  249. if (disabledUsers.includes(user.text)) {
  250. comment.style.display = 'none';
  251. comment.style.visibility = 'hidden';
  252. }
  253. buttonDisableUser.innerText = 'X';
  254. buttonDisableUser.setAttribute('title', 'Tiltás');
  255. buttonDisableUser.style.border = '1px solid #fff';
  256. buttonDisableUser.style.backgroundColor = '#f00';
  257. buttonDisableUser.style.color = '#fff';
  258. buttonDisableUser.style.padding = '0.25em';
  259. buttonDisableUser.style.margin = '0 0.25em';
  260. buttonDisableUser.style.fontWeight = 'bold';
  261. buttonDisableUser.setAttribute('data-username', user.text);
  262.  
  263. buttonDisableUser.onclick = () => {
  264. let userName = buttonDisableUser.getAttribute('data-username');
  265. if (
  266. disabledUsers.length == 0 ||
  267. !disabledUsers.includes(userName)
  268. ) {
  269. disabledUsers.push(userName);
  270. window.localStorage.setItem('disabledUsers', JSON.stringify(disabledUsers));
  271. }
  272. window.location.reload(true);
  273. };
  274. user.after(buttonDisableUser);
  275. }
  276. }