Last active
August 29, 2015 14:27
-
-
Save Rplus/20cfb6e8a3a005f45e96 to your computer and use it in GitHub Desktop.
Usability 測試的 bookmarklet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fork from https://blog.gslin.org/archives/2015/08/14/5926/ | |
// re-build to jQuery independence script | |
javascript: (function() { | |
'use strict'; | |
var rStr = ' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
var rStrLen = rStr.length; | |
function textNodesUnder(node) { | |
node = node.firstChild; | |
while (node) { | |
if (Node.TEXT_NODE === node.nodeType) { | |
if ('' !== node.nodeValue.trim()) { | |
var _str = ''; | |
var _strLen = node.nodeValue.trim().length; | |
while (_strLen) { | |
_str += rStr.charAt(Math.floor(Math.random() * rStrLen)); | |
_strLen--; | |
} | |
node.nodeValue = _str; | |
} | |
} else if ('STYLE' === node.nodeName.toUpperCase() || 'SCRIPT' === node.nodeName.toUpperCase()) { | |
// skip `style`, `script` | |
} else { | |
textNodesUnder(node); | |
} | |
node = node.nextSibling; | |
} | |
} | |
textNodesUnder(document.documentElement); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rStr
包含space
的這個作法可能會在重覆執行 random text 操作時,
造成字元不斷減少
當生成的空白剛好在字首或字尾時便會觸發
這在兩個字的 tag 上,較容易發覺字元縮減的這一狀況