Zalgolf
by
noromanba
2017-05-21 [2017/05/21 08:07:12]
glitch text w/ Zalgo Scrambled Text
@@ -1,17 +1,17 @@
/*
* @title Zalgolf
- * @description glithch text w/ js Zalgo Scrambled Text
+ * @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/
+ * @contributor aTakaakiSeki http://qiita.com/aTakaakiSeki/items/614d5d178f717c6b2997
+ * @license WTFTPL http://www.wtfpl.net/about/
* @javascript_url
*/
-// orig code and description c.f.
+// orig code and reference c.f.
// http://qiita.com/aTakaakiSeki/items/614d5d178f717c6b2997
-// slightly code-golf and description et al. c.f.
+// slightly code-golf and ref/descr et al. c.f.
// https://gist.github.com/noromanba/3062530dc3970d93762a5775080715f8
/* oneliner-min
@@ -22,24 +22,28 @@
$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';
- // http://www.unicode.org/charts/PDF/U0300.pdf
const combiningChar = () => {
- // random repeat for *N combine
+ // 0-30 random N times repeat
return Array.from(Array(Math.trunc(Math.random() * 30)), () => {
- return String.fromCharCode(0x300 + Math.floor(Math.random() * 79))
+ // http://www.unicode.org/charts/PDF/U0300.pdf
+ // 0x0300-0x034F: 79 = 0x04F
+ return String.fromCharCode(0x300 + Math.trunc(Math.random() * 0x04F))
}).join('');
};
// TBD
- // - XPath for text-node select w/ XPath's not()
+ // - 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.nodeName === '#text')
+ ]), node => [...node.childNodes]))
+ .filter(node => node.nodeType === Node.TEXT_NODE)
.map(textNode => {
return textNode.textContent =
// TBD alnum
@@ -47,13 +51,19 @@
return captured + combiningChar();
});
});
+
+ // TBD handle autopaging
}
+// TIPS and TRICKS
+//
// pseudo `Array#times()` idioms
//
-// ES6
+// 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());
@@ -64,4 +74,17 @@
// [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(16)
+// "79"
+//
+// '0x0' + (0x300 + 1 * 79).toString(16).toUpperCase()
+// "0x034F"
+// '0x0' + (0x300 + 1 * 0x04F).toString(16).toUpperCase()
+// "0x034F"
/*
* @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-30 random N times repeat
return Array.from(Array(Math.trunc(Math.random() * 30)), () => {
// http://www.unicode.org/charts/PDF/U0300.pdf
// 0x0300-0x034F: 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)
.map(textNode => {
return 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(16)
// "79"
//
// '0x0' + (0x300 + 1 * 79).toString(16).toUpperCase()
// "0x034F"
// '0x0' + (0x300 + 1 * 0x04F).toString(16).toUpperCase()
// "0x034F"
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。