WebShuffler

Shuffles every text on websites

  1. // ==UserScript==
  2. // @name WebShuffler
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2.2
  5. // @description Shuffles every text on websites
  6. // @author lxvdev
  7. // @license MIT
  8. // @match *://*/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to shuffle all the text on the website
  16. function shuffleText(node) {
  17. if (node.nodeType === Node.TEXT_NODE) {
  18. let text = node.textContent.trim();
  19. if (text.length > 1) {
  20. let shuffledText = text.split('').sort(() => Math.random() - 0.5).join('');
  21. node.textContent = shuffledText;
  22. }
  23. } else if (node.nodeType === Node.ELEMENT_NODE) {
  24. node.childNodes.forEach(function(childNode) {
  25. shuffleText(childNode);
  26. });
  27. }
  28. }
  29.  
  30. // Function to shuffle the page title
  31. function shuffleTitle() {
  32. let title = document.title.trim();
  33. if (title.length > 1) {
  34. let shuffledTitle = title.split('').sort(() => Math.random() - 0.5).join('');
  35. document.title = shuffledTitle;
  36. }
  37. }
  38.  
  39. // Function for shuffling text that changed
  40. function handleMutations(mutationsList, observer) {
  41. mutationsList.forEach(mutation => {
  42. if (mutation.type === 'childList') {
  43. mutation.addedNodes.forEach(node => {
  44. if (node.nodeType === Node.TEXT_NODE || node.nodeType === Node.ELEMENT_NODE) {
  45. shuffleText(node);
  46. }
  47. });
  48. }
  49. });
  50. }
  51.  
  52. // Checks if there is running observers
  53. function isObserverRunning() {
  54. return observer.takeRecords().length > 0;
  55. }
  56.  
  57. const observer = new MutationObserver(handleMutations);
  58. observer.observe(document.body, { childList: true, subtree: true });
  59.  
  60. // Starts observing for text changes
  61. function startObserver() {
  62. if (!isObserverRunning()) {
  63. observer.observe(document.body, { childList: true, subtree: true });
  64. }
  65. }
  66.  
  67. // Starts observing and shuffles text if the tab gets focused again
  68. window.addEventListener('focus', () => {
  69. shuffleTitle();
  70. startObserver();
  71. shuffleText(document.body);
  72. });
  73.  
  74. // Stops observing if the tab isn't focused
  75. window.addEventListener('blur', () => {
  76. observer.disconnect();
  77. });
  78.  
  79. // Shuffles text on load
  80. window.onload = function() {
  81. shuffleTitle();
  82. shuffleText(document.body);
  83. };
  84. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址