Zalgolf
by
noromanba
2017-05-21 [2017/05/21 08:07:12]
glitch text w/ Zalgo Scrambled Text
@@ -1,6 +1,6 @@
/*
* @title Zalgolf
- * @description js Zalgo Scrambled Text
+ * @description glithch text w/ js Zalgo Scrambled Text
* @include http://*
* @include https://*
* @contributor aTakaakiSeki http://qiita.com/aTakaakiSeki/items/614d5d178f717c6b2997
@@ -49,9 +49,11 @@
});
}
-// pseudo `Array#repeat()` idioms
+// pseudo `Array#times()` idioms
//
// ES6
+// [...Array(10)].map((_, 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());
/*
* @title Zalgolf
* @description glithch text w/ js 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 description c.f.
// http://qiita.com/aTakaakiSeki/items/614d5d178f717c6b2997
// slightly code-golf and description 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('')));
*/
{
'use strict';
// http://www.unicode.org/charts/PDF/U0300.pdf
const combiningChar = () => {
// random repeat for *N combine
return Array.from(Array(Math.trunc(Math.random() * 30)), () => {
return String.fromCharCode(0x300 + Math.floor(Math.random() * 79))
}).join('');
};
// TBD
// - XPath for text-node select w/ XPath's not()
// - unchain methods
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')
.map(textNode => {
return textNode.textContent =
// TBD alnum
textNode.textContent.replace(/([a-z])/ig, (_, captured) => {
return captured + combiningChar();
});
});
}
// pseudo `Array#times()` idioms
//
// ES6
// [...Array(10)].map((_, 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]
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。