Guest User

Untitled

a guest
Sep 21st, 2026
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. document.addEventListener('click', function(e) {
  2. // Detecta si el elemento clickeado es un botón de responder (ya sea de Dollchan o del foro)
  3. const target = e.target;
  4. const isPostButton = target.id === 'formButton' ||
  5. target.value === 'Reply' ||
  6. target.value === 'Post' ||
  7. target.classList.contains('qr-submit') ||
  8. target.textContent.toLowerCase().includes('post') ||
  9. target.textContent.toLowerCase().includes('reply');
  10.  
  11. if (isPostButton) {
  12. // Localiza el cuadro de texto activo en la página
  13. const textareas = document.querySelectorAll('textarea');
  14.  
  15. // Regex para buscar patrones como !2d6, !1d20, !3d14, etc. (insensible a mayúsculas/minúsculas)
  16. const regex = /!(\d+)d(\d+)/gi;
  17.  
  18. textareas.forEach(textarea => {
  19. if (regex.test(textarea.value)) {
  20. // Reiniciamos el índice de la regex por seguridad
  21. regex.lastIndex = 0;
  22.  
  23. // Reemplazamos todas las ocurrencias que aparezcan en el texto
  24. textarea.value = textarea.value.replace(regex, (match, cantidadStr, carasStr) => {
  25. const cantidad = parseInt(cantidadStr, 10);
  26. const caras = parseInt(carasStr, 10);
  27.  
  28. // Validación básica para evitar valores absurdos o vacíos
  29. if (cantidad <= 0 || caras <= 0) return match;
  30.  
  31. let tiradas = [];
  32. let total = 0;
  33.  
  34. for (let i = 0; i < cantidad; i++) {
  35. const tirada = Math.floor(Math.random() * caras) + 1;
  36. tiradas.push(tirada);
  37. total += tirada;
  38. }
  39.  
  40. // Formato más lindo y colorido usando emojis nativos soportados por cualquier foro
  41. if (cantidad === 1) {
  42. return `🎲 [ ${cantidad}d${caras} ] ➔ ${tiradas[0]} 🎯`;
  43. } else {
  44. // Se cambió ** por == para el resaltado
  45. return `🎲 [ ${cantidad}d${caras} ] ➔ (${tiradas.join(' + ')}) = ==${total}== 💥`;
  46. }
  47. });
  48.  
  49. // Fuerza a Dollchan y al DOM a leer el nuevo texto modificado
  50. textarea.dispatchEvent(new Event('input', { bubbles: true }));
  51. textarea.dispatchEvent(new Event('change', { bubbles: true }));
  52. }
  53. });
  54. }
  55. }, true);
Advertisement
Add Comment
Please, Sign In to add comment