Badge Toggle

Toggle visibility of chat badges

  1. // ==UserScript==
  2. // @name Badge Toggle
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Toggle visibility of chat badges
  6. // @author guildedbird
  7. // @match https://pixelplace.io/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const EXCLUDED_BADGES = [
  16. "/img/badges/moderator.png",
  17. "/img/badges/chat-moderator.png",
  18. "/img/badges/former-global-moderator.png",
  19. "/img/badges/painting-moderator.png",
  20. "/img/badges/painting-owner.png",
  21. "/img/badges/admin.png"
  22. ];
  23.  
  24. function updateBadgeVisibility(showBadges) {
  25. const images = document.querySelectorAll('#chat .messages .row img');
  26. images.forEach(img => {
  27. const src = img.getAttribute('src');
  28. if (!EXCLUDED_BADGES.includes(src)) {
  29. img.style.display = showBadges ? '' : 'none';
  30. }
  31. });
  32. }
  33.  
  34. function showNotification(isEnabled) {
  35. setTimeout(() => {
  36. const notifications = document.querySelector('#notification');
  37. if (!notifications) return;
  38.  
  39. const existingNotification = notifications.querySelector('.box');
  40. if (existingNotification) existingNotification.remove();
  41.  
  42. const notification = document.createElement('div');
  43. notification.className = isEnabled ? 'box success' : 'box warning';
  44. notification.innerHTML = `
  45. <div class="icon"></div>
  46. <div class="content">
  47. <div class="title">Tools</div>
  48. <div class="description">Badges are now ${isEnabled ? 'displayed in' : 'hidden from'} chat</div>
  49. </div>`;
  50.  
  51. notifications.appendChild(notification);
  52.  
  53. setTimeout(() => {
  54. notification.style.transition = 'opacity 1s';
  55. notification.style.opacity = '0';
  56. setTimeout(() => notification.remove(), 1000);
  57. }, 6000);
  58. });
  59. }
  60.  
  61.  
  62. const checkbox = document.createElement('a');
  63. checkbox.href = '#';
  64. checkbox.classList.add('input-checkbox', 'selected');
  65. checkbox.setAttribute('data-name', 'tools-enable-flair');
  66.  
  67. checkbox.innerHTML = `
  68. <div>
  69. <div class="input">
  70. <div></div>
  71. </div>
  72. </div>
  73. <div>
  74. <div class="header">Display badges</div>
  75. <div class="content">
  76. Display badges in chat. Note: This does not disable mod badges
  77. </div>
  78. </div>`;
  79.  
  80. checkbox.addEventListener('click', function(e) {
  81. e.preventDefault();
  82. checkbox.classList.toggle('selected');
  83. const isSelected = checkbox.classList.contains('selected');
  84. updateBadgeVisibility(isSelected);
  85. showNotification(isSelected);
  86. });
  87.  
  88. const modalContent = document.querySelector('#modals .box[data-id="main"] .box-content[data-id="tools"] div form');
  89. if (modalContent) {
  90. const formChildren = modalContent.children;
  91. if (formChildren.length >= 18) {
  92. modalContent.insertBefore(checkbox, formChildren[17]);
  93. } else {
  94. modalContent.appendChild(checkbox);
  95. }
  96. }
  97.  
  98. const observer = new MutationObserver(() => {
  99. updateBadgeVisibility(true);
  100. });
  101.  
  102. const chat = document.querySelector('#chat .messages');
  103. if (chat) {
  104. observer.observe(chat, { childList: true, subtree: true });
  105. }
  106.  
  107. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址