Advertisement
ipsBruno

(Javascript) Tidy Code

Oct 5th, 2013
553
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  3.  
  4.  
  5. <center><font face=verdana><font size=5 color=green><b>T</b>abulador e Analisador de Códigos V3</font></br></br>
  6.  
  7. - Deixa seu código tabulado e organizado</br>
  8. - Analisa se os brackets {} de seu código estão fechados e abertos de forma correta e avisa qual é o erro</br>
  9. - Rápido e fácil uso. Cole seu código abaixo e clique em analisar !!</br>
  10.  
  11. </font></br>
  12. <style>
  13. * { margin: 0; padding: 0;}
  14.  
  15. body, html { height:100%;  }
  16.  
  17.  
  18. </style>
  19. <script>  
  20. var i = 0;
  21. var filtro = " \t\n\r\f";
  22.  
  23. var bla = 0;
  24. var bck = 0;
  25. var rs = ['  ', '  '];
  26. var linha = rs;
  27. var impressaofinal = "";
  28. var HAScomment = 0;
  29. var nostring = 1;
  30.  
  31.  
  32.  
  33. function indent(parametros) {
  34.  
  35.  
  36.     linha = parametros.split("\n");
  37.  
  38.     document.write("<div  style=\"background-color:black;\" id='status' ></div><center><br/><canvas style=\"background-color:black\" id='canvasID' width='600px'></canvas></center><textarea id='novocodigo' style='display:none;height:80%;width:90%;'>");
  39.     document.bgColor = 'black';
  40.  
  41.     bar = new createProgressBar(20, 20, 400, 10, "green", linha.length, "canvasID");
  42.     bar.showText(true, "white", "verdana", 10);
  43.  
  44.  
  45.     setTimeout(function () {
  46.         processar(i, bar, bck, bla, linha, filtro);
  47.     }, 100);
  48.     document.getElementById('area').style.display = "none";
  49.  
  50.     return true;
  51. }
  52.  
  53.  
  54. function terminar(bck) {
  55.     document.bgColor = 'white';
  56.     if (bck) {
  57.  
  58.         alert("Existem " + bck +"   { a mais (+) demais no código");
  59.         alert("O erro foi encontrado antes da linha " + (ultimobrack - 1));
  60.     }
  61.  
  62.     document.write(impressaofinal + "</textarea>");
  63.     document.getElementById("canvasID").style.display = "none";
  64.     document.getElementById("novocodigo").style.display = "block";
  65.     document.getElementById('status').innerHTML = "<font face=\"Verdana\" color=\"green\" size=\"3\">Foi finalizado !!";
  66. }
  67.  
  68. function processar(i, bar, bck, bla, linha, filtro) {
  69.  
  70.  
  71.     bar.updateProgress();
  72.  
  73.  
  74.     document.getElementById('status').innerHTML = "<font face=\"Verdana\" color=\"white\" size=\"3\">Processando: <font size=1>" + linha[i];
  75.  
  76.     j = 0;
  77.     comment = new Array();
  78.    
  79.  
  80.     while ((filtro.indexOf(linha[i][j]) != -1)) {
  81.         j++;
  82.     }
  83.  
  84.     f = j;
  85.     impressaofinal += "\n";
  86.  
  87.     for (b = 0; linha[i][j]; j++) {
  88.    
  89.         if(linha[i][j] == '"' && linha[i][j-1] != '\\' && HAScomment == 0  &&  comment[i]  != 1) {
  90.                 nostring = !nostring;
  91.         }
  92.         else if (linha[i][j] == "/" && linha[i][j + 1] == "*" && nostring) {
  93.             HAScomment = 1;
  94.         }
  95.  
  96.         else if (linha[i][j] == "*" && linha[i][j + 1] == "/" && nostring) {
  97.             HAScomment = 0;
  98.         }
  99.  
  100.         else if (linha[i][j] == "/" && linha[i][j + 1] == "/" && nostring) {
  101.             comment[i] = 1;
  102.         }
  103.  
  104.  
  105.         else if (linha[i][j] == "{" && HAScomment == 0  &&  comment[i]  != 1 && nostring) {
  106.  
  107.             bck++;
  108.  
  109.             ultimobrack = i;
  110.  
  111.             if (j == f) {
  112.                 f = -1;
  113.             }
  114.  
  115.         }
  116.  
  117.         else if (linha[i][j] == "}" && HAScomment == 0  &&  comment[i]  != 1 && nostring) {
  118.             bck--;
  119.         }
  120.  
  121.         if (bck < 0) {
  122.             alert("Existem } demais no código");
  123.             alert("O processo foi parado proximo a linha que houve o erro");
  124.             terminar(0);
  125.             return true;
  126.         }
  127.  
  128.  
  129.         if (!b && bck) {
  130.  
  131.             for (x = 0; x < (f == -1 ? bck - 1 : bck); x++) {
  132.                 impressaofinal += "\t";
  133.             }
  134.  
  135.         }
  136.  
  137.  
  138.         impressaofinal += linha[i][j];
  139.  
  140.         b = 1;
  141.  
  142.         u = bck;
  143.  
  144.         if (f == -1 && linha[i].length > 1) {
  145.  
  146.             impressaofinal += "\n";
  147.  
  148.             for (x = 0; x < (bck); x++) {
  149.                 impressaofinal += "\t";
  150.             }
  151.  
  152.             f--;
  153.         }
  154.  
  155.  
  156.     }
  157.  
  158.     if (i < linha.length - 1) {
  159.         i++;
  160.         linha[i - 1][0] = 0;
  161.         setTimeout(function () {
  162.             processar(i, bar, bck, bla, linha, filtro);
  163.         }, 2);
  164.  
  165.     } else {
  166.         setTimeout( function() { terminar(bck); }, 1000);
  167.     }
  168.     return true;
  169. }
  170.  
  171. String.prototype.rtrim = function () {
  172.     return this.replace(/\s+$/, "");
  173. }
  174.  
  175. function createProgressBar(x, y, largura, altura, color, maximo, canvasid) {
  176.         this.valorprogresso = 0
  177.         this.maximo = maximo
  178.         this.largura = largura
  179.         this.altura = altura
  180.         this.cnv = document.getElementById(canvasid).getContext('2d')
  181.         this.background = document.getElementById(canvasid).style.background;
  182.         this.posicaox = x
  183.         this.posicaoy = y
  184.         this.cor = color
  185.         this.updateProgress = function () {
  186.                 if (this.valorprogresso < this.maximo) {
  187.                         this.cnv.fillStyle = this.cor
  188.                         this.cnv.fillRect(this.posicaox + ((this.largura /  this.maximo) * (this.valorprogresso)), y,this.largura /  this.maximo, this.altura)
  189.                         this.valorprogresso+=1
  190.  
  191.                         if (this.textmiddle) {
  192.                                 this.cnv.fillStyle =this.background
  193.                                 this.cnv.fillRect(this.posicaox - 3, y + (this.tamanhof + this.altura), this.tamanhof * 5, this.tamanhof + this.altura - 1)
  194.                                 this.cnv.fillStyle = this.textcolor
  195.                                 this.cnv.font = this.textfonte
  196.                                 if ((((this.valorprogresso / this.maximo) * 100) >> 0) == 100) {
  197.                                         this.cnv.fillText("Completo!", this.posicaox - 1, this.altura + y + (this.tamanhof * 2)-3)
  198.                                 } else {
  199.                                         this.cnv.fillText((((this.valorprogresso / this.maximo) * 100) >> 0) + " %", this.posicaox - 2, this.altura + y + (this.tamanhof * 2))
  200.                                 }
  201.                         }
  202.                 }
  203.                 return (this.valorprogresso < this.maximo);
  204.         }
  205.         this.getProgress = function () {
  206.                 return this.valorprogresso;
  207.         }
  208.         this.setProgress = function (v) {
  209.                 return this.valorprogresso = v;
  210.         }
  211.         this.showText = function (ativado, color, fonte, tamanho) {
  212.                 this.textcolor = color
  213.                 this.tamanhof = tamanho
  214.                 this.textfonte = tamanho + "pt " + fonte
  215.                 this.textmiddle = ativado;
  216.         }
  217.         return true;
  218. }
  219.  
  220.  
  221.  
  222. </script>  
  223.  
  224. <textarea width="600" heigth="600" id="area" style="margin: 2px; width: 630px; height: 201px; ">Cole seu código aqui !!
  225.  
  226. </textarea></br>
  227.  
  228. <input type=button onClick=indent(document.getElementById('area').value) value=Analisar />  
  229. </center>
  230. </br></br>
  231. Por <b>Bruno da Silva</b> @ <b>iPs TeaM 2010-2013 - email@brunodasilva.com www.ipsbr.net</b>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement