Convert Binary to Text on Facebook Posts

Convert binary text to readable text on Facebook posts.

  1. // ==UserScript==
  2. // @name Convert Binary to Text on Facebook Posts
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description Convert binary text to readable text on Facebook posts.
  6. // @match https://www.facebook.com/*/posts/*
  7. // @grant none
  8. // @run-at document-end
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Check if the text content is binary
  15. function isBinaryString(str) {
  16. return /^[01\s]+$/.test(str);
  17. }
  18.  
  19. // Convert binary string to text
  20. function binaryToText(binaryStr) {
  21. let text = '';
  22. binaryStr = binaryStr.replace(/\s+/g, ''); // Remove any whitespace
  23. for (let i = 0; i < binaryStr.length; i += 8) {
  24. let byte = binaryStr.slice(i, i + 8);
  25. text += String.fromCharCode(parseInt(byte, 2));
  26. }
  27. return text;
  28. }
  29.  
  30. // Process and convert binary text nodes
  31. function processTextNodes(rootNode) {
  32. const walker = document.createTreeWalker(rootNode, NodeFilter.SHOW_TEXT, null, false);
  33. let node;
  34. while (node = walker.nextNode()) {
  35. let textContent = node.textContent.trim();
  36. if (textContent.length > 0 && isBinaryString(textContent)) {
  37. node.textContent = binaryToText(textContent);
  38. }
  39. }
  40. }
  41.  
  42. // Function to process the whole page
  43. function processPage() {
  44. processTextNodes(document.body);
  45. }
  46.  
  47. // Run the processPage function every second
  48. const intervalId = setInterval(() => {
  49. processPage();
  50. }, 1000);
  51.  
  52. // Clear the interval when the page is unloaded
  53. window.addEventListener('beforeunload', () => {
  54. clearInterval(intervalId);
  55. });
  56.  
  57. // Initial processing
  58. processPage();
  59. })();