Drawaria Hide All Players Button!

Adds a "Hide All Players" button that hides and shows all players.

  1. // ==UserScript==
  2. // @name Drawaria Hide All Players Button!
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.01
  5. // @description Adds a "Hide All Players" button that hides and shows all players.
  6. // @match https://drawaria.online/*
  7. // @author YouTubeDrawaria
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=drawaria.online
  9. // @license MIT
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Translation map
  17. const translations = {
  18. 'en': {
  19. 'hide': 'Hide All Players',
  20. 'show': 'Show All Players'
  21. },
  22. 'ru': {
  23. 'hide': 'Скрыть всех игроков',
  24. 'show': 'Показать всех игроков'
  25. },
  26. 'es': {
  27. 'hide': 'Ocultar todos los jugadores',
  28. 'show': 'Mostrar todos los jugadores'
  29. }
  30. // Add more translations as needed
  31. };
  32.  
  33. // Function to get the current language
  34. function getCurrentLanguage() {
  35. const langSelector = document.querySelector('#langselector');
  36. return langSelector ? langSelector.value : 'en';
  37. }
  38.  
  39. // Function to translate the button text
  40. function translateButtonText(button, language) {
  41. const translationsForLanguage = translations[language];
  42. if (translationsForLanguage) {
  43. button.textContent = playersHidden ? translationsForLanguage.show : translationsForLanguage.hide;
  44. }
  45. }
  46.  
  47. // Function to hide or show all players and restore their original positions
  48. function togglePlayersVisibility(hide) {
  49. var playerListRows = Array.from(document.querySelectorAll('.playerlist-row'));
  50. if (hide) {
  51. // Hide all players and store their original positions
  52. playerListRows.forEach(function(row) {
  53. row.dataset.originalStyle = row.style.cssText; // Store original styles
  54. row.style.display = 'none';
  55. });
  56. } else {
  57. // Show all players and restore their original positions
  58. playerListRows.sort(function(a, b) {
  59. var nameA = a.querySelector('.playerlist-name a').textContent.toUpperCase();
  60. var nameB = b.querySelector('.playerlist-name a').textContent.toUpperCase();
  61. if (nameA < nameB) {
  62. return -1;
  63. }
  64. if (nameA > nameB) {
  65. return 1;
  66. }
  67. return 0;
  68. });
  69. playerListRows.forEach(function(row) {
  70. row.style.cssText = row.dataset.originalStyle; // Restore original styles
  71. row.style.display = 'table-row';
  72. });
  73. }
  74. }
  75.  
  76. // Add the "Hide All Players" button below the existing button
  77. var existingButton = document.querySelector('#roomcontrols-menu');
  78. if (existingButton) {
  79. // Create the "Hide All Players" button
  80. var hideAllButton = document.createElement('button');
  81. hideAllButton.className = 'btn btn-outline-secondary btn-sm';
  82. hideAllButton.style.padding = '1px 10px';
  83. hideAllButton.id = 'hide-all-players-button';
  84.  
  85. // Variable to control the visibility state
  86. var playersHidden = false;
  87.  
  88. // Function to update the button text and functionality
  89. function updateButton() {
  90. const currentLanguage = getCurrentLanguage();
  91. translateButtonText(hideAllButton, currentLanguage);
  92. hideAllButton.addEventListener('click', function() {
  93. playersHidden = !playersHidden;
  94. togglePlayersVisibility(playersHidden);
  95. translateButtonText(hideAllButton, currentLanguage);
  96. });
  97. }
  98.  
  99. // Initial update of the button text and functionality
  100. updateButton();
  101.  
  102. // Insert the "Hide All Players" button after the existing button
  103. existingButton.parentNode.insertBefore(hideAllButton, existingButton.nextSibling);
  104. }
  105.  
  106. // Event listener for language change
  107. document.querySelector('#langselector').addEventListener('change', updateButton);
  108.  
  109. // Style the player rows to display the ID
  110. var playerListRows = Array.from(document.querySelectorAll('.playerlist-row'));
  111. playerListRows.forEach(function(row) {
  112. var playerId = row.getAttribute('data-playerid');
  113. row.style.position = 'relative'; // Ensure the position is relative to place the ID label
  114. row.insertAdjacentHTML('beforeend', `<span class="player-id-label">${playerId}</span>`);
  115. });
  116.  
  117. // CSS to style the player ID label
  118. var css = document.createElement('style');
  119. css.type = 'text/css';
  120. css.innerHTML = `
  121. .player-id-label {
  122. position: absolute;
  123. top: 0;
  124. right: 0;
  125. background-color: rgba(0, 0, 0, 0.5);
  126. color: white;
  127. padding: 2px 4px;
  128. font-size: 0.8em;
  129. border-radius: 4px;
  130. }
  131. `;
  132. document.head.appendChild(css);
  133. })();