Last active
September 23, 2017 02:52
-
-
Save wlib/b3aa742e1ec0c9ed1daca6e98d3efdd6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<html> | |
<head> | |
<title>Zalgo Generator</title> | |
<script src="./zalgo.js"></script> | |
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.5.2/css/bulma.min.css" rel="stylesheet" type="text/css"> | |
</head> | |
<body> | |
<section class="hero is-info is-fullheight is-bold"> | |
<section class="section"> | |
<input id="input" class="input" autofocus> | |
<section class="section has-text-centered"> | |
<input id="level" type="range" min="0" max="20" step="1"> | |
</section> | |
</section> | |
<div class="hero-body"> | |
<div class="container has-text-centered"> | |
<h1 id="output" class="title is-1"></h1> | |
</div> | |
</div> | |
</section> | |
<script src="index.js"></script> | |
</body> | |
</html> |
This file contains hidden or 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
const input = document.querySelector("#input"); | |
const level = document.querySelector("#level"); | |
const output = document.querySelector("#output"); | |
input.onkeydown = (e) => { | |
if (e.keyCode === 13) { | |
output.innerText = zalgo(input.value, level.value); | |
} | |
} | |
level.onchange = () => output.innerText = zalgo(input.value, level.value); |
This file contains hidden or 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
// Draw a random value from an array | |
function randItem(array) { | |
return array[Math.floor(Math.random() * array.length)]; | |
} | |
// Random unicode zalgo characters | |
// prettier-ignore | |
const 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" /* ̚ */ | |
]; | |
// prettier-ignore | |
const 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" /* ̣ */ | |
]; | |
// prettier-ignore | |
const mid = [ | |
"\u0315", /* Ì• */ "\u031b", /* Ì› */ "\u0340", /* Ì€ */ "\u0341", /* Ì */ | |
"\u0358", /* ͘ */ "\u0321", /* ̡ */ "\u0322", /* ̢ */ "\u0327", /* ̧ */ | |
"\u0328", /* ̨ */ "\u0334", /* ̴ */ "\u0335", /* ̵ */ "\u0336", /* ̶ */ | |
"\u034f", /* Í */ "\u035c", /* Íœ */ "\u035d", /* Í */ "\u035e", /* Íž */ | |
"\u035f", /* ÍŸ */ "\u0360", /* Í */ "\u0362", /* Í¢ */ "\u0338", /* ̸ */ | |
"\u0337", /* Ì· */ "\u0361", /* Í¡ */ "\u0489" /* Ò‰_ */ | |
]; | |
// Generate zalgo text | |
function zalgo(input = "", level = 1, targetChars = 0) { | |
// Default zalgo level is just level 1, but level 0 is minimum possible | |
level = level < 0 ? 1 : parseInt(level); | |
// Maximum character count minimum is based on input length | |
targetChars = | |
targetChars < input.length ? input.length * (level + 5) : parseInt(targetChars); | |
// This will hold our new zalgo generated string | |
let zalgo = ""; | |
const zalgoToAdd = Math.floor((targetChars - input.length) / input.length); | |
const remainder = (targetChars - input.length) % input.length; | |
for (let i in input) { | |
// Add the original input's character before the zalgo characters | |
zalgo += input[i]; | |
// Add random zalgo characters | |
for (let j = 0; j < zalgoToAdd; j++) { | |
const chars = randItem([up, mid, down]); | |
zalgo += randItem(chars); | |
} | |
// Account for remainder | |
zalgo += Array(remainder + 1).join(randItem(mid)); | |
} | |
// Return generated zalgo | |
return zalgo; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment