Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.