Created
July 21, 2013 01:00
-
-
Save gmfc/6047058 to your computer and use it in GitHub Desktop.
Unicode javascript. "zalgo"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//those go UP | |
var zalgo_up = [ | |
'\u030d', /* Ì */ '\u030e', /* ÌŽ */ '\u0304', /* Ì„ */ '\u0305', /* Ì… */ | |
'\u033f', /* Ì¿ */ '\u0311', /* Ì‘ */ '\u0306', /* ̆ */ '\u0310', /* Ì */ | |
'\u0352', /* ͒ */ '\u0357', /* ͗ */ '\u0351', /* ͑ */ '\u0307', /* ̇ */ | |
'\u0308', /* ̈ */ '\u030a', /* ̊ */ '\u0342', /* ͂ */ '\u0343', /* ̓ */ | |
'\u0344', /* ÌˆÌ */ '\u034a', /* ÍŠ */ '\u034b', /* Í‹ */ '\u034c', /* ÍŒ */ | |
'\u0303', /* ̃ */ '\u0302', /* Ì‚ */ '\u030c', /* ÌŒ */ '\u0350', /* Í */ | |
'\u0300', /* Ì€ */ '\u0301', /* Ì */ '\u030b', /* Ì‹ */ '\u030f', /* Ì */ | |
'\u0312', /* ̒ */ '\u0313', /* ̓ */ '\u0314', /* ̔ */ '\u033d', /* ̽ */ | |
'\u0309', /* ̉ */ '\u0363', /* ͣ */ '\u0364', /* ͤ */ '\u0365', /* ͥ */ | |
'\u0366', /* ͦ */ '\u0367', /* ͧ */ '\u0368', /* ͨ */ '\u0369', /* ͩ */ | |
'\u036a', /* ͪ */ '\u036b', /* Í« */ '\u036c', /* ͬ */ '\u036d', /* Í */ | |
'\u036e', /* ͮ */ '\u036f', /* ͯ */ '\u033e', /* ̾ */ '\u035b', /* ͛ */ | |
'\u0346', /* ͆ */ '\u031a' /* ̚ */ | |
]; | |
//those go UP | |
var zalgo_custom = [ | |
'\u0E47' /* ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ */ | |
]; | |
//those go DOWN | |
var zalgo_down = [ | |
'\u0316', /* ̖ */ '\u0317', /* ̗ */ '\u0318', /* ̘ */ '\u0319', /* ̙ */ | |
'\u031c', /* Ìœ */ '\u031d', /* Ì */ '\u031e', /* Ìž */ '\u031f', /* ÌŸ */ | |
'\u0320', /* Ì */ '\u0324', /* ̤ */ '\u0325', /* Ì¥ */ '\u0326', /* ̦ */ | |
'\u0329', /* ̩ */ '\u032a', /* ̪ */ '\u032b', /* ̫ */ '\u032c', /* ̬ */ | |
'\u032d', /* Ì */ '\u032e', /* Ì® */ '\u032f', /* ̯ */ '\u0330', /* Ì° */ | |
'\u0331', /* ̱ */ '\u0332', /* ̲ */ '\u0333', /* ̳ */ '\u0339', /* ̹ */ | |
'\u033a', /* ̺ */ '\u033b', /* ̻ */ '\u033c', /* ̼ */ '\u0345', /* ͅ */ | |
'\u0347', /* ͇ */ '\u0348', /* ͈ */ '\u0349', /* ͉ */ '\u034d', /* Í */ | |
'\u034e', /* ÍŽ */ '\u0353', /* Í“ */ '\u0354', /* Í” */ '\u0355', /* Í• */ | |
'\u0356', /* ͖ */ '\u0359', /* ͙ */ '\u035a', /* ͚ */ '\u0323' /* ̣ */ | |
]; | |
//those always stay in the middle | |
var zalgo_mid = [ | |
'\u0315', /* Ì• */ '\u031b', /* Ì› */ '\u0340', /* Ì€ */ '\u0341', /* Ì */ | |
'\u0358', /* ͘ */ '\u0321', /* ̡ */ '\u0322', /* ̢ */ '\u0327', /* ̧ */ | |
'\u0328', /* ̨ */ '\u0334', /* ̴ */ '\u0335', /* ̵ */ '\u0336', /* ̶ */ | |
'\u034f', /* Í */ '\u035c', /* Íœ */ '\u035d', /* Í */ '\u035e', /* Íž */ | |
'\u035f', /* ÍŸ */ '\u0360', /* Í */ '\u0362', /* Í¢ */ '\u0338', /* ̸ */ | |
'\u0337', /* Ì· */ '\u0361', /* Í¡ */ '\u0489' /* Ò‰_ */ | |
]; | |
// rand funcs | |
//--------------------------------------------------- | |
//gets an int between 0 and max | |
function rand(max) | |
{ | |
return Math.floor(Math.random() * max); | |
} | |
//gets a random char from a zalgo char table | |
function rand_zalgo(array) | |
{ | |
var ind = Math.floor(Math.random() * array.length); | |
return array[ind]; | |
} | |
// utils funcs | |
//--------------------------------------------------- | |
//hide show element | |
//lookup char to know if its a zalgo char or not | |
function is_zalgo_char(c) | |
{ | |
var i; | |
for(i=0; i<zalgo_up.length; i++) | |
if(c == zalgo_up[i]) | |
return true; | |
for(i=0; i<zalgo_down.length; i++) | |
if(c == zalgo_down[i]) | |
return true; | |
for(i=0; i<zalgo_mid.length; i++) | |
if(c == zalgo_mid[i]) | |
return true; | |
return false; | |
} | |
// main shit | |
//--------------------------------------------------- | |
function zalgo_textarea(id) | |
{ | |
var p = document.getElementById(id); | |
var txt = p.value; | |
var newtxt = ''; | |
for(var i=0; i<txt.length; i++) | |
{ | |
if(is_zalgo_char(txt.substr(i, 1))) | |
continue; | |
var num_up; | |
var num_mid; | |
var num_down; | |
var num_custom; | |
//add the normal character | |
newtxt += txt.substr(i, 1); | |
//options | |
if(document.getElementById('zalgo_opt_mini').checked) | |
{ | |
num_up = rand(8); | |
num_mid = rand(2); | |
num_down = rand(8); | |
num_custom = rand(8); | |
} | |
else if(document.getElementById('zalgo_opt_normal').checked) | |
{ | |
num_up = rand(16) / 2 + 1; | |
num_mid = rand(6) / 2; | |
num_down = rand(16) / 2 + 1; | |
num_custom = rand(16) / 2 + 1; | |
} | |
else if(document.getElementById('zalgo_opt_omg').checked) | |
{ | |
num_up = 50; | |
num_mid = 10; | |
num_down = 50; | |
num_custom = 200; | |
} | |
else //maxi | |
{ | |
num_up = rand(64) / 4 + 3; | |
num_mid = rand(16) / 4 + 1; | |
num_down = rand(64) / 4 + 3; | |
num_custom = rand(64) / 4 + 3; | |
} | |
if(document.getElementById('zalgo_opt_up').checked) | |
for(var j=0; j<num_up; j++) | |
newtxt += rand_zalgo(zalgo_up); | |
if(document.getElementById('zalgo_opt_mid').checked) | |
for(var j=0; j<num_mid; j++) | |
newtxt += rand_zalgo(zalgo_mid); | |
if(document.getElementById('zalgo_opt_down').checked) | |
for(var j=0; j<num_down; j++) | |
newtxt += rand_zalgo(zalgo_down); | |
if(document.getElementById('zalgo_opt_custom').checked) | |
for(var j=0; j<num_custom; j++) | |
newtxt += rand_zalgo(zalgo_custom); | |
} | |
//result is in nextxt, display that | |
//remove all children of zalgo_container | |
var container = document.getElementById('zalgo_container'); | |
while(container.childNodes.length) | |
container.removeChild(container.childNodes[0]); | |
//build blocks for each line & create a <br /> | |
var lines = newtxt.split("\n"); | |
for(var i=0; i<lines.length; i++) | |
{ | |
var n = document.createElement('text'); | |
n.innerHTML = lines[i]; | |
container.appendChild(n); | |
var nl = document.createElement('br'); | |
container.appendChild(nl); | |
} | |
//done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment