Binary to Text Translator

Automatically translates binary code to text on web pages without adding extra spaces between letters.

  1. // ==UserScript==
  2. // @name Binary to Text Translator
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Automatically translates binary code to text on web pages without adding extra spaces between letters.
  6. // @author ChatGpt4mini
  7. // @match *://*/*
  8. // @match *http://reddit.com/*
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Function to convert binary string to text
  18. function binaryToText(binary) {
  19. // Remove any extra spaces and split binary into 8-bit chunks
  20. return binary.replace(/\s+/g, '').match(/.{1,8}/g)
  21. .map(bin => String.fromCharCode(parseInt(bin, 2)))
  22. .join('');
  23. }
  24.  
  25. // Function to find and translate binary text
  26. function translateBinary() {
  27. const textNodes = [];
  28.  
  29. // Function to traverse DOM and get text nodes
  30. function getTextNodes(node) {
  31. if (node.nodeType === Node.TEXT_NODE) {
  32. if (node.nodeValue.trim()) {
  33. textNodes.push(node);
  34. }
  35. } else {
  36. node.childNodes.forEach(getTextNodes);
  37. }
  38. }
  39.  
  40. // Get all text nodes in the document
  41. getTextNodes(document.body);
  42.  
  43. // Iterate through each text node and replace binary with translated text
  44. textNodes.forEach(node => {
  45. const regex = /\b(?:[01]{8}(?:\s)?)+\b/g; // Matches sequences of 8-bit binary numbers
  46. const originalText = node.nodeValue;
  47. const translatedText = originalText.replace(regex, match => binaryToText(match));
  48.  
  49. if (originalText !== translatedText) {
  50. node.nodeValue = translatedText;
  51. }
  52. });
  53. }
  54.  
  55. // Run the translation function
  56. translateBinary();
  57.  
  58. // Observe changes in the body for dynamically added content
  59. const observer = new MutationObserver(translateBinary);
  60. observer.observe(document.body, { childList: true, subtree: true });
  61. })();