// : var canvas, div1, div2; canvas.moveTo(150, 150); canvas.moveTo(153, 151); canvas.moveTo(11, 151); canvas.moveTo(153, 120); canvas.moveTo(153, 1); div1 = '<div style="width:150px;height:200px;color:red"></div>'; div2 = '<div style="width:150px;height:200px;color:blue"></div>'; // : var canvas, div1, div2, __moveTo__ = 'moveTo'; __width_height__ = 'width:150px;height:200px;'; canvas[__moveTo__](150, 150); canvas[__moveTo__](153, 151); canvas[__moveTo__](11, 151); canvas[__moveTo__](153, 120); canvas[__moveTo__](153, 1); div1 = '<div style="' + __width_height__ + 'color:red"></div>'; div2 = '<div style="' + __width_height__ + 'color:blue"></div>';
(N * (L+1)) - (N * (2 + V) + V + 4 + L)
N * L - (N * (4 + V) + V + 4 + L)
var __document__ = document;
c = smth.length
// : for (i = 0;i<smth.length; i++)do(i); // : i=smth.length;while(i--)do(i);
var blabla= function (){};
redo them into the Function Defination function blabla(){}
Another minus a couple of bytes.getElementById, getElementsByTagName
use querySelector, querySelectorAll
<div id="aaa"> - <div a=aaa>
<div id=aaa> - <div a=1>
'#ff0000' -> 'red', '#fedc52' -> '#fd5'
var b = document.body; var c = document.getElementsByTagName('canvas')[0]; var a = c.getContext('2d'); (function (ctx, __document__body__, canvas) { // }(a,b,c))
The order a, b, c is important because the minifikator will remake your code into this form: (function(a,b,c){ // }(a,b,c))
And you will not need to worry about matching the names of internal variables with external ones and you can remove the global closure. Minus as many as 26 bytes!e.keyCode^27||e.preventDefault()
instead of e.keyCode==27&&e.preventDefault()
// Full version of Notes ll be on my web site soon. // Creating closure to compile with UglifyJS // (!) After compile remove global closure manually (function (ctx, __document__body__, canvas) { // Dictionary for some frequently used method names and strings var __fillStyle__ = 'fillStyle', __dblclick__ = 'dblclick', __setAttribute__ = 'setAttribute', __background_and_left__ = 'position:absolute;left:', __fillRect__ = 'fillRect', __addColorStop__ = 'addColorStop', __innerHTML__ = 'innerHTML', __textarea__ = 'textarea', __ffe__ = '#ffe', // Other shorthands __document__ = document, __localStorage__ = localStorage, i,j,c,imageData, width = 200, height = 250, paperGradient = ctx.createLinearGradient(width, height/2, width, 0); // Making fixed canvas size canvas[__setAttribute__]('width', 202); canvas[__setAttribute__]('height', 275); // Creates note at e.clientX e.clientY function createPaper(e) { // Opera haven't onbeforeuload event // I must save document.body content on each keyup and each keyCode=27 keydown // Sorry... :3 // (!) replace b and save to actual after min __document__body__[__innerHTML__] += '<a onkeydown=event.keyCode^27||b.removeChild(this),w() style=' + __background_and_left__ + e.clientX + 'px;top:' + e.clientY + 'px;><i style=' + __background_and_left__ + '30px;top:10px;color:#a53;font-size:9px>'+Date()+'</i><img src=' + imageData + '><' + __textarea__ + ' onkeyup=this.'+__innerHTML__+'=this.value,w() style=' + __background_and_left__ + '28px;top:33px;background:transparent;width:170px;height:200px;border:0;line-height:20px;overflow:hidden>Esc</' + __textarea__ + '></a>'; save(); } // Saves document.body to localStorage function save() { __localStorage__[__dblclick__] = __document__body__[__innerHTML__]; } // Making sexy paper // Gradient paperGradient[__addColorStop__](0, '#ff9'); paperGradient[__addColorStop__](1, __ffe__); ctx[__fillStyle__] = paperGradient; ctx.strokeStyle = '#aa7'; // Draw paper body ctx.strokeRect(1,1, width,height); ctx[__fillRect__](1,1, width,height); // Creating paper texture i = width; ctx[__fillStyle__] = __ffe__; while(--i) { while(--j) { Math.random()>.7&&ctx[__fillRect__](i,j,1,1); } j = height; } // 2 Vertical red lines ctx[__fillStyle__] = '#a51'; ctx[__fillRect__](20, 1, 1, height); ctx[__fillRect__](22, 1, 1, height); // Some horizontal gray lines ctx[__fillStyle__] = '#aaa'; for (i = 50; i < height; i += 20) ctx[__fillRect__](0, i, width, 1); // Grabbing image source imageData = canvas.toDataURL(); // Print "Hello message" or load localStorage content __document__body__[__innerHTML__]=__localStorage__[__dblclick__] || __dblclick__+', uses ' + __localStorage__; // Some action events __document__.addEventListener(__dblclick__, createPaper, 0); }(a,b,c)) // Vars must be in a, b, c order
// c.lineTo(150,150);c.lineTo(150,200);c.lineTo(150,250);c.lineTo(250,350);c.lineTo(450,350); // var a='lineTo';c[a](150,150);c[a](150,200);c[a](150,250);c[a](250,350);c[a](450,350); // var a=z.lineTo.bind(z);a(150,150);a(150,200);a(150,250);a(250,350);a(450,350);
Source: https://habr.com/ru/post/115369/
All Articles