smoothretro1982

word/character Replacer

Jul 30th, 2026 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. // --- CONFIGURATION ---
  2. const IS_WORD_MODE = true; // Set to true for words, false for single characters
  3. const RADIUS = 58;
  4.  
  5.  
  6.  
  7. // Character Mode Settings
  8. const charsToFind = ['6', '7'];
  9. const charToReplaceWith = ' ';
  10.  
  11. // Word Mode Settings
  12. const wordsToFind = ['test']; // Words to target (case-insensitive)
  13. const wordToReplaceWith = 'lolol'; // Must match length of target, or use spaces
  14.  
  15. // Cursor coordinates
  16. const cx = Number(cursor.x);
  17. const cy = Number(cursor.y);
  18.  
  19. // --- EXECUTION ---
  20. if (!IS_WORD_MODE) {
  21. // === SINGLE CHARACTER MODE ===
  22. for (let x = cx - RADIUS; x <= cx + RADIUS; x++) {
  23. for (let y = cy - RADIUS; y <= cy + RADIUS; y++) {
  24. const dx = x - cx;
  25. const dy = y - cy;
  26.  
  27. if (dx * dx + dy * dy <= RADIUS * RADIUS) {
  28. const info = getCharInfoXY(x, y);
  29.  
  30. if (charsToFind.includes(info.char) && !info.deco.bold) {
  31. writeCharAt(
  32. charToReplaceWith,
  33. prsFmt({ color: info.color, bold: false }),
  34. x,
  35. y
  36. );
  37. }
  38. }
  39. }
  40. }
  41. } else {
  42. // === WORD MODE ===
  43. // Scans line-by-line within the vertical radius bound
  44. for (let y = cy - RADIUS; y <= cy + RADIUS; y++) {
  45. // Reconstruct the text line across the horizontal radius bound
  46. let lineText = '';
  47. const startX = cx - RADIUS;
  48. const endX = cx + RADIUS;
  49.  
  50. for (let x = startX; x <= endX; x++) {
  51. const dx = x - cx;
  52. const dy = y - cy;
  53.  
  54. // Check if coordinate is within radius
  55. if (dx * dx + dy * dy <= RADIUS * RADIUS) {
  56. const info = getCharInfoXY(x, y);
  57. lineText += info.char || ' ';
  58. } else {
  59. lineText += ' '; // Placeholder for coordinates outside radius
  60. }
  61. }
  62.  
  63. // Check for matching words in the reconstructed line
  64. wordsToFind.forEach((word) => {
  65. const lowerLine = lineText.toLowerCase();
  66. const lowerWord = word.toLowerCase();
  67. let matchIdx = lowerLine.indexOf(lowerWord);
  68.  
  69. while (matchIdx !== -1) {
  70. // Replace each character of the found word
  71. for (let i = 0; i < word.length; i++) {
  72. const targetX = startX + matchIdx + i;
  73. const dx = targetX - cx;
  74. const dy = y - cy;
  75.  
  76. // Ensure the character is within radius and not bold before replacing
  77. if (dx * dx + dy * dy <= RADIUS * RADIUS) {
  78. const info = getCharInfoXY(targetX, y);
  79. if (!info.deco.bold) {
  80. const replacementChar = wordToReplaceWith[i] || ' ';
  81. writeCharAt(
  82. replacementChar,
  83. prsFmt({ color: info.color, bold: false }),
  84. targetX,
  85. y
  86. );
  87. }
  88. }
  89. }
  90. // Check for next occurrence on the same line
  91. matchIdx = lowerLine.indexOf(lowerWord, matchIdx + 1);
  92. }
  93. });
  94. }
  95. }
Add Comment
Please, Sign In to add comment