-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcow.min.js
14 lines (10 loc) · 1.78 KB
/
cow.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
Copyright (c) 2017 Owen Shepherd
This software is open-source under the MIT license.
The full license can be viewed here: https://opensource.org/licenses/MIT
This is CowJS, a web developer's easter egg
Homepage: https://github.com/414owen/cow-js
*/
(function(){function g(a,b){for(var c="";b--;)c+=a;return c}function h(a){a&&console.log("%c "+a,"font-family: monospace")}function k(a){for(a=a.split("\n").reduce(function(a,b){for(var c=[];50<b.length;){var d=49,e=50,l="";f.test(b[50])?(d++,e++):f.test(b[48])?(d--,e--):f.test(b[49])||(l="-",e--);c.push(b.slice(0,d)+l);b=b.slice(e)}c.push(b);return a.concat(c)},[]);f.test(a[0]);)a=a.slice(1);for(;f.test(a[a.length-1]);)a=a.slice(0,a.length-1);if(0!==a.length){var b=a.reduce(function(a,b){return a>
b.length?a:b.length},0),e=1===a.length?"<>":"/\\"+g("|",2*a.length-4)+"\\/";return g("_",b+2)+"\n"+a.map(function(a,c){return e[2*c]+" "+a+d(b-a.length)+" "+e[2*c+1]+"\n"}).join("")+" "+g("-",b+2)+"\n"+d(8)+"\\ ^__^\n"+d(9)+"\\ (oo)\\_______\n"+d(12)+"(__)\\ )\\/\\\n"+d(16)+"||----w |\n"+d(16)+"|| ||"}}var b="",f=/^\s*$/,d=g.bind(" "," ");document.addEventListener("paste",function(a){b+=a.clipboardData.getData("text")});document.onkeydown=function(a){var c=document.activeElement.tagName.toLowerCase(),
d=!0;if(8===a.keyCode)if(a.ctrlKey)for(c=b.split(/\s/),b=b.slice(0,b.length-c[c.length-1].length);f.test(b[b.length-1]);)b=b.slice(0,b.length-1);else b=b.slice(0,b.length-1);else a.ctrlKey||-1!==["textarea","input"].indexOf(c)?d=!1:13===a.keyCode?a.shiftKey?b+="\n":(h(k(b)),b=""):a.key&&1===a.key.length?b+=a.key:a.keyIdentifier&&(c=parseInt(a.keyIdentifier.slice(2),16),0<c&&(c=String.fromCharCode(c),a.shiftKey||(c=c.toLowerCase()),1===c.length&&(b+=c)));d&&a.preventDefault()};h(k("Focus the page, type, then press enter"))})();