Skip to content

Instantly share code, notes, and snippets.

@Rplus
Last active August 29, 2015 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rplus/20cfb6e8a3a005f45e96 to your computer and use it in GitHub Desktop.
Save Rplus/20cfb6e8a3a005f45e96 to your computer and use it in GitHub Desktop.
Usability 測試的 bookmarklet
// 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);
})();
@Rplus
Copy link
Author

Rplus commented Aug 14, 2015

rStr 包含 space 的這個作法可能會在
重覆執行 random text 操作時,
造成字元不斷減少

當生成的空白剛好在字首或字尾時便會觸發
這在兩個字的 tag 上,較容易發覺字元縮減的這一狀況

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment