Enhanced Hide Signatures on IGN Boards

Enhanced version with better performance and maintainability

  1. // ==UserScript==
  2. // @name Enhanced Hide Signatures on IGN Boards
  3. // @namespace https://www.ignboards.com/members/magof.5211856/
  4. // @version 0.2
  5. // @author Magof
  6. // @description Enhanced version with better performance and maintainability
  7. // @match https://www.ignboards.com/threads/*
  8. // @grant GM_addStyle
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Constants
  17. const STORAGE_KEY = 'hiddenUsers';
  18. const BUTTON_CLASSES = ['signature-toggle-button', 'button--link', 'button', 'rippleButton'];
  19. const ICONS = {
  20. visible: '<i class="fas fa-eye-slash"></i>',
  21. hidden: '<i class="fas fa-eye"></i>'
  22. };
  23. const TOOLTIPS = {
  24. visible: 'Hide this user\'s signature',
  25. hidden: 'Show this user\'s signature'
  26. };
  27.  
  28. // Cache DOM elements
  29. let postsContainer;
  30.  
  31. /**
  32. * Toggle signature visibility for a specific user
  33. * @param {string} user - The username to toggle
  34. * @param {boolean} isVisible - Whether to show or hide the signature
  35. */
  36. function toggleSignatureVisibility(user, isVisible) {
  37. const posts = postsContainer.querySelectorAll('.message');
  38. posts.forEach(post => {
  39. const authorElement = post.querySelector('.message-userExtras');
  40. if (!authorElement) return;
  41.  
  42. const postUser = authorElement.textContent.trim().split(',')[0];
  43. if (postUser !== user) return;
  44.  
  45. const signature = post.querySelector('.message-signature');
  46. const button = post.querySelector('.signature-toggle-button');
  47. if (signature) {
  48. signature.style.display = isVisible ? 'block' : 'none';
  49. }
  50. if (button) {
  51. button.innerHTML = isVisible ? ICONS.visible : ICONS.hidden;
  52. button.title = isVisible ? TOOLTIPS.visible : TOOLTIPS.hidden;
  53. }
  54. });
  55. }
  56.  
  57. /**
  58. * Update storage and toggle signature visibility
  59. * @param {string} user - The username to toggle
  60. */
  61. function handleSignatureToggle(user) {
  62. const hiddenUsers = JSON.parse(GM_getValue(STORAGE_KEY, '[]'));
  63. const userIndex = hiddenUsers.indexOf(user);
  64. const isVisible = userIndex === -1;
  65.  
  66. if (isVisible) {
  67. hiddenUsers.push(user);
  68. } else {
  69. hiddenUsers.splice(userIndex, 1);
  70. }
  71.  
  72. GM_setValue(STORAGE_KEY, JSON.stringify(hiddenUsers));
  73. toggleSignatureVisibility(user, !isVisible);
  74. }
  75.  
  76. /**
  77. * Create and add toggle buttons to posts
  78. */
  79. function addToggleButtons() {
  80. const posts = postsContainer.querySelectorAll('.message');
  81. posts.forEach(post => {
  82. const signature = post.querySelector('.message-signature');
  83. if (!signature) return;
  84.  
  85. const authorElement = post.querySelector('.message-userExtras');
  86. if (!authorElement) return;
  87.  
  88. const user = authorElement.textContent.trim().split(',')[0];
  89. const button = document.createElement('button');
  90. button.innerHTML = ICONS.visible;
  91. button.title = TOOLTIPS.visible;
  92. button.classList.add(...BUTTON_CLASSES);
  93. button.addEventListener('click', () => handleSignatureToggle(user));
  94.  
  95. const avatar = post.querySelector('.message-avatar');
  96. if (avatar) {
  97. avatar.parentNode.appendChild(button);
  98. }
  99. });
  100. }
  101.  
  102. /**
  103. * Apply saved preferences for hidden users
  104. */
  105. function applySavedPreferences() {
  106. const hiddenUsers = JSON.parse(GM_getValue(STORAGE_KEY, '[]'));
  107. hiddenUsers.forEach(user => toggleSignatureVisibility(user, false));
  108. }
  109.  
  110. // Initialize script
  111. function init() {
  112. postsContainer = document.querySelector('.messageList') || document.body;
  113. addToggleButtons();
  114. applySavedPreferences();
  115. }
  116.  
  117. // Add styles
  118. GM_addStyle(`
  119. .signature-toggle-button {
  120. margin-left: 50px;
  121. padding: 5px;
  122. background-color: transparent;
  123. border: none;
  124. cursor: pointer;
  125. transition: background-color 0.2s ease;
  126. }
  127. .signature-toggle-button:hover {
  128. background-color: rgba(0, 0, 0, 0.1);
  129. }
  130. .signature-toggle-button i {
  131. font-size: 1.2em;
  132. pointer-events: none;
  133. }
  134. `);
  135.  
  136. // Run initialization
  137. window.addEventListener('load', init);
  138. })();