/*
* @title Zalgolf
* @description glitch text w/ Zalgo Scrambled Text
* @include http://*
* @include https://*
* @contributor aTakaakiSeki http://qiita.com/aTakaakiSeki/items/614d5d178f717c6b2997
* @license WTFTPL http://www.wtfpl.net/about/
* @javascript_url
*/
// orig code and reference c.f.
// http://qiita.com/aTakaakiSeki/items/614d5d178f717c6b2997
// slightly code-golf and ref/descr et al. c.f.
// https://gist.github.com/noromanba/3062530dc3970d93762a5775080715f8
/* oneliner-min
javascript:[].concat(...[...document.querySelectorAll(':not(style):not(script):not(:empty)')].map(e=>[...e.childNodes])).filter(n=>n.nodeName==='#text').map(n=>n.textContent=n.textContent.replace(/([a-z])/ig,(_,c)=>c+[...Array(Math.random()*30|0)].map(()=>String.fromCharCode(0x300+(Math.random()*79|0))).join('')));
*/
/* Devtools/Scratchpad-min
$x('//text()').map(n=>n.textContent=n.textContent.replace(/([a-z])/ig,(_,c)=>c+[...Array(Math.random()*30|0)].map(()=>String.fromCharCode(0x300+(Math.random()*79|0))).join('')));
*/
// unminified and reference
{
'use strict';
const combiningChar = () => {
// 0-29 random N times repeat
return Array.from(Array(Math.trunc(Math.random() * 30)), () => {
// http://www.unicode.org/charts/PDF/U0300.pdf
// U0300-U034E: 79 = 0x04F
return String.fromCharCode(0x300 + Math.trunc(Math.random() * 0x04F))
}).join('');
};
// TBD
// - select text-node w/ Xpath and XPath's not()
// - unchain methods
// - extract flatten
Array.prototype.concat.apply([], Array.from(document.querySelectorAll([
'head title',
'body :not(style):not(script):not(:empty)',
]), node => [...node.childNodes]))
.filter(node => node.nodeType === Node.TEXT_NODE)
.forEach(textNode => {
textNode.textContent =
// TBD alnum
textNode.textContent.replace(/([a-z])/ig, (_, captured) => {
return captured + combiningChar();
});
});
// TBD handle autopaging
}
// TIPS and TRICKS
//
// pseudo `Array#times()` idioms
//
// ES6/ES2015
// [...Array(10)].map((_, i) => i);
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
// Array.from(Array(10), (_, i) => i);
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
// Array.from(Array(10)).map((_, i) => i);
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
// Array.from(Array(10).keys());
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
//
// ES5
// Array.apply(null, Array(10)).map(function(_, i) { return i; });
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
// Array(10).join().split(',').map(function(_, i) { return i; });
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
//
//
// hex <-> decimal of Unicode Combining Character
//
// (79).toString(16)
// "4f"
// (0x4F).toString(10)
// "79"
//
// '0x0' + (0x300 + 1 * 79).toString(16).toUpperCase()
// "0x034F"
// '0x0' + (0x300 + 1 * 0x04F).toString(16).toUpperCase()
// "0x034F"