Dyslexic Experience

Read like someone with Dyslexia. Experience it yourself.

  1. // ==UserScript==
  2. // @name Dyslexic Experience
  3. // @namespace http://geon.github.io/programming/2016/03/03/dsxyliea
  4. // @version 1.0
  5. // @description Read like someone with Dyslexia. Experience it yourself.
  6. // @author You
  7. // @match http://tampermonkey.net/index.php?version=3.12.58&ext=dhdg&updated=true
  8. // @grant none
  9. //* I exported this code directly from "http://geon.github.io/programming/2016/03/03/dsxyliea" The reason I exported this code and uploaded it here is so others, such as
  10. //* yourself can (somewhat) experience what it is like to have dyslexia in your own point of view while browsing your favorite sites. *//
  11. // ==/UserScript==
  12.  
  13.  
  14. /* jshint -W097 */
  15.  
  16. 'use strict';
  17.  
  18. "use strict";
  19.  
  20. $(function(){
  21.  
  22. var getTextNodesIn = function(el) {
  23. return $(el).find(":not(iframe,script)").addBack().contents().filter(function() {
  24. return this.nodeType == 3;
  25. });
  26. };
  27.  
  28. // var textNodes = getTextNodesIn($("p, h1, h2, h3"));
  29. var textNodes = getTextNodesIn($("*"));
  30.  
  31.  
  32.  
  33. function isLetter(char) {
  34. return /^[\d]$/.test(char);
  35. }
  36.  
  37.  
  38. var wordsInTextNodes = [];
  39. for (var i = 0; i < textNodes.length; i++) {
  40. var node = textNodes[i];
  41.  
  42. var words = []
  43.  
  44. var re = /\w+/g;
  45. var match;
  46. while ((match = re.exec(node.nodeValue)) != null) {
  47.  
  48. var word = match[0];
  49. var position = match.index;
  50.  
  51. words.push({
  52. length: word.length,
  53. position: position
  54. });
  55. }
  56.  
  57. wordsInTextNodes[i] = words;
  58. };
  59.  
  60.  
  61. function messUpWords () {
  62.  
  63. for (var i = 0; i < textNodes.length; i++) {
  64.  
  65. var node = textNodes[i];
  66.  
  67. for (var j = 0; j < wordsInTextNodes[i].length; j++) {
  68.  
  69. // Only change a tenth of the words each round.
  70. if (Math.random() > 1/10) {
  71.  
  72. continue;
  73. }
  74.  
  75. var wordMeta = wordsInTextNodes[i][j];
  76.  
  77. var word = node.nodeValue.slice(wordMeta.position, wordMeta.position + wordMeta.length);
  78. var before = node.nodeValue.slice(0, wordMeta.position);
  79. var after = node.nodeValue.slice(wordMeta.position + wordMeta.length);
  80.  
  81. node.nodeValue = before + messUpWord(word) + after;
  82. };
  83. };
  84. }
  85.  
  86. function messUpWord (word) {
  87.  
  88. if (word.length < 3) {
  89.  
  90. return word;
  91. }
  92.  
  93. return word[0] + messUpMessyPart(word.slice(1, -1)) + word[word.length - 1];
  94. }
  95.  
  96. function messUpMessyPart (messyPart) {
  97.  
  98. if (messyPart.length < 2) {
  99.  
  100. return messyPart;
  101. }
  102.  
  103. var a, b;
  104. while (!(a < b)) {
  105.  
  106. a = getRandomInt(0, messyPart.length - 1);
  107. b = getRandomInt(0, messyPart.length - 1);
  108. }
  109.  
  110. return messyPart.slice(0, a) + messyPart[b] + messyPart.slice(a+1, b) + messyPart[a] + messyPart.slice(b+1);
  111. }
  112.  
  113. // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
  114. function getRandomInt(min, max) {
  115. return Math.floor(Math.random() * (max - min + 1) + min);
  116. }
  117.  
  118.  
  119. setInterval(messUpWords, 50);
  120. });

QingJ © 2025

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