Advertisement
FlyFar

minifier.html

Jul 19th, 2023
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.14 KB | Cybersecurity | 0 0
  1. <!-- 1 open minifier.html -->
  2. <!-- 2 paste the html code in the upper text field -->
  3. <!-- 3 click on minify + byte-ify -->
  4. <!-- 4 copy the results -->
  5. <!-- 5 go to data.h and replace the array (of the changed HTML file) with the copied bytes -->
  6. <!-- ** now upload your new sketch :)** -->
  7. <html>
  8.   <head>
  9.     <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  10.     <script>
  11.       function miniEsc(){
  12.         var input = $('#input').val().replace(/\r\n|\r|\n/g," ").replace( /\s\s+/g, ' ' ).replace(/"/g, '\\"' );
  13.         $('#output').val(input);
  14.         $('#info1').html($('#input').val().length);
  15.         $('#info2').html(input.length);
  16.       }
  17.      
  18.       function mini(){
  19.         var input = $('#input').val().replace(/\r\n|\r|\n/g," ").replace( /\s\s+/g, ' ' );
  20.         $('#output').val(input);
  21.         $('#info1').html($('#input').val().length);
  22.         $('#info2').html(input.length);
  23.       }
  24.      
  25.       String.prototype.convertToHex = function (delim) {
  26.           return this.split("").map(function(c) {
  27.               return ("0" + c.charCodeAt(0).toString(16)).slice(-2);
  28.           }).join(delim || "");
  29.       };
  30.      
  31.       function byte(){
  32.         var input = $('#input').val().convertToHex(",0x");
  33.         $('#output').val("0x"+input);
  34.         $('#info1').html($('#input').val().length);
  35.         $('#info2').html((input.match(/,/g) || []).length+1);
  36.       }
  37.      
  38.       function byteAndmini(){
  39.         var input = "0x"+$('#input').val().replace(/\r\n|\r|\n/g," ").replace( /\s\s+/g, ' ' ).convertToHex(",0x");;
  40.         $('#output').val(input);
  41.         $('#info1').html($('#input').val().length);
  42.         $('#info2').html((input.match(/,/g) || []).length+1);
  43.       }
  44.     </script>
  45.   </head>
  46.   <body>
  47.     <textarea id="input" rows="30" cols="80"></textarea><br />
  48.     <p><span id="info1">0</span> => <span id="info2">0</span></p>
  49.     <button onclick="mini()">minify</button>
  50.     <button onclick="miniEsc()">minify + escape</button>
  51.     <button onclick="byte()">byte-ify</button>
  52.     <button onclick="byteAndmini()">minify + byte-ify</button><br />
  53.     <textarea id="output" rows="30" cols="80"></textarea><br />
  54.   </body>
  55. </html>
Tags: minifier
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement