Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     // Isso aqui ja faz pegar todos os pais.
  2.  
  3.     var elements = [];
  4.     var posicaoX = 0;
  5.     var posicaoY = 0;
  6.  
  7.     function rightclick() {
  8.         var rightclick;
  9.         var e = window.event;
  10.      
  11.       // Detecta um clique esquerdo fora da caixa pra fechar ela.
  12.         if(e.which == 1){
  13.           var auxTarget = e.target;
  14.           var dontDelete = false;
  15.  
  16.           // O carinha existe, vamos ver se eu cliquei dentro ou fora.
  17.           if($("#containerCSSEditor")){
  18.  
  19.           while(auxTarget.tagName != "BODY"){
  20.               if(auxTarget.getAttribute("id") == "containerCSSEditor")
  21.               dontDelete = true;
  22.               auxTarget = auxTarget.parentNode;
  23.           }
  24.        
  25.           // Cliquei fora, pode deletar.
  26.           if(!dontDelete) $("#containerCSSEditor").remove();
  27.           }
  28.         }  
  29.  
  30.         if (e.which == 3 || e.button == 2){
  31.           var auxTarget = e.target;
  32.           var act = true;
  33.           if(auxTarget.getAttribute("id") == "containerCSSEditor" || auxTarget.parentNode.getAttribute("id") == "containerCSSEditor" || auxTarget.parentNode.getAttribute("id") == "CSSEditorUlContainer"){
  34.             act = false;
  35.           }
  36.           if(act){
  37.             elements = [];
  38.             var target = e.target;
  39.             posicaoX = e.pageX;
  40.             posicaoY = e.pageY;
  41.             auxTarget = target;
  42.            
  43.             if($("#containerCSSEditor")){
  44.                 $("#containerCSSEditor").remove();
  45.             }
  46.  
  47.             while(auxTarget.tagName != "BODY"){
  48.                 elements.push(auxTarget);
  49.                 auxTarget = auxTarget.parentNode;
  50.             }
  51.        
  52.             criarListaCSS(false);
  53.           }
  54.         }
  55.     }
  56.  
  57.     function criarListaCSS(verdade){
  58.  
  59.         $("#containerCSSEditor").remove();
  60.          
  61.         // Cria o container Geral.
  62.         var cssEditForm = document.createElement("div");
  63.         cssEditForm.setAttribute("id", "containerCSSEditor");
  64.  
  65.         // Cria o titulo do css;
  66.         var cssTitle = document.createElement("h3");
  67.         cssTitle.setAttribute("id", "cssEditorTitle");
  68.         cssTitle.append("CSS Aplicados");
  69.  
  70.         // Cria a lista e vamos comecar a tacar as coisa ali. (TODO)
  71.         var cssULContainer = document.createElement("ul");
  72.         cssULContainer.setAttribute("id", "CSSEditorUlContainer");
  73.  
  74.         // Agora comeca a adicionar os elementos da lista.
  75.  
  76.         for(var i = 0; i < elements.length; i++){
  77.             var cssEditorLi = document.createElement("li");
  78.             cssEditorLi.setAttribute("class", "cssEditorLi");
  79.             cssEditorLi.setAttribute("id", "EditorLi"+i);
  80.             cssEditorLi.setAttribute("onclick", "abreEditorCSS(" + i + ")");
  81.             var classe = elements[i].className;
  82.             var idElemento = elements[i].id;
  83.  
  84.             if(classe != ""){
  85.                 classe = "."+classe;
  86.             }
  87.             if(idElemento != ""){
  88.                 idElemento = "#"+idElemento;
  89.             }
  90.  
  91.             if(!verdade){
  92.                 if(classe != "" && classe != ""){
  93.                     cssEditorLi.innerHTML = elements[i].tagName.toLowerCase() + " " + classe + " " + idElemento;
  94.                     cssULContainer.append(cssEditorLi);
  95.                 }
  96.             }else{
  97.                 cssEditorLi.innerHTML = elements[i].tagName.toLowerCase() + " " + classe + " " + idElemento;
  98.                 cssULContainer.append(cssEditorLi);
  99.             }
  100.         }
  101.        
  102.         cssEditForm.append(cssTitle);
  103.         cssEditForm.append(cssULContainer);
  104.         if(!verdade){
  105.             var voltarCSSEditorNode = document.createElement("article");
  106.             voltarCSSEditorNode.setAttribute("class", "button-carregar");
  107.             voltarCSSEditorNode.setAttribute("id", "carregar");
  108.             voltarCSSEditorNode.setAttribute("onclick", "criarListaCSS(true)");
  109.             voltarCSSEditorNode.innerHTML = "Carregar todos os elementos";
  110.             cssEditForm.append(voltarCSSEditorNode);
  111.         }
  112.  
  113.         $("body").append(cssEditForm);
  114.         $("#containerCSSEditor").css("top", posicaoY).css("left", posicaoX);
  115.     }
  116.  
  117.  
  118.     function abreEditorCSS(index){
  119.  
  120.       var top = $("#containerCSSEditor").css("top");
  121.       var left = $("#containerCSSEditor").css("left");
  122.       $("#containerCSSEditor").remove();
  123.       // Cria um novo editor, dessa vez com base em um form.
  124.       var containerCSSEditorNode = document.createElement("div");
  125.       containerCSSEditorNode.setAttribute("id", "containerCSSEditor");
  126.  
  127.       var voltarCSSEditorNode = document.createElement("article");
  128.       voltarCSSEditorNode.setAttribute("class", "button-voltar");
  129.       voltarCSSEditorNode.setAttribute("id", "voltarButton");
  130.       voltarCSSEditorNode.setAttribute("onclick", "criarListaCSS(false)");
  131.       voltarCSSEditorNode.innerHTML = "Voltar"
  132.       containerCSSEditorNode.append(voltarCSSEditorNode);
  133.  
  134.       var quebraLinha = document.createElement("br");
  135.       //containerCSSEditorNode.append(quebraLinha);
  136.  
  137.       // Botar um titulo pra ficar mais bonitin
  138.       var cssTitleNode = document.createElement("h3");
  139.       cssTitleNode.setAttribute("id", "cssEditorTitleEdit");
  140.       cssTitleNode.append("Alterar CSS");
  141.       containerCSSEditorNode.append(cssTitleNode);
  142.  
  143.       // Cria o form.
  144.       var formCSSEditorNode = document.createElement("form");
  145.       formCSSEditorNode.setAttribute("id", "formCSSEditor");
  146.       formCSSEditorNode.setAttribute("method", "post");
  147.       formCSSEditorNode.setAttribute("action", "google.com"); // TODO.
  148.       // Agora cria os inputs do form
  149.       // Nome do elemento.
  150.       var inputNameCSSEditorNode = document.createElement("input");
  151.       inputNameCSSEditorNode.setAttribute("readonly", "");
  152.       inputNameCSSEditorNode.setAttribute("name", "divName");
  153.       inputNameCSSEditorNode.setAttribute("id", "divName");
  154.       inputNameCSSEditorNode.setAttribute("type", "text");
  155.       inputNameCSSEditorNode.setAttribute("value", "< " + elements[index].tagName.toLowerCase() + " class='" + elements[index].className + "' id='" + elements[index].id + "' >");
  156.       formCSSEditorNode.append(inputNameCSSEditorNode);
  157.  
  158.       // Agora as regras.
  159.       var inputCssCSSEditorNode = document.createElement("textarea");
  160.       inputCssCSSEditorNode.setAttribute("rows", "30")
  161.       inputCssCSSEditorNode.setAttribute("name", "inputCSSEditorCSS");
  162.       inputCssCSSEditorNode.setAttribute("id", "inputCSSEditorCSS");
  163.       inputCssCSSEditorNode.setAttribute("type", "text");
  164.       inputCssCSSEditorNode.setAttribute("placeholder", "Carregando...");
  165.       formCSSEditorNode.append(inputCssCSSEditorNode);
  166.  
  167.       // Botao de submit;
  168.       var submitCSSEditorNode = document.createElement("button");
  169.       submitCSSEditorNode.setAttribute("class", "button");
  170.       submitCSSEditorNode.setAttribute("id", "saveButtonCSSEditor");
  171.       submitCSSEditorNode.setAttribute("onclick", "removeFormCSSEditor");
  172.       submitCSSEditorNode.innerHTML = "Enviar Alterações"
  173.       // Agora comeca a putaria de juntar tudo.
  174.       formCSSEditorNode.append(submitCSSEditorNode);
  175.       containerCSSEditorNode.append(formCSSEditorNode);
  176.       $("body").append(containerCSSEditorNode);
  177.       // Aparentemente jquery so funciona se ele ja ta appended.
  178.       $("#containerCSSEditor").css("top", top).css("left", left);
  179.      
  180.       // Por enquanto, nao quero nenhum submit.
  181.       document.addEventListener("submit", function(e){
  182.           e.preventDefault();
  183.       })
  184.       $.get( "https://www.rbedin.com/layouts/html5_social_white/estilo.css?MIN=off", function( data ) {
  185.         // quebra por linha o css;
  186.         var linesData = data.split("\n");
  187.         for(var i = 0; i < linesData.length; i++){
  188.           // se tem { entao eh uma declaracao de css;
  189.           if(linesData[i].includes("{")){
  190.             // agora tenta quebrar por a b c;
  191.             var lvl = 0;
  192.             var splitLines = linesData[i].split(" ");
  193.             // agora por cada uma dessas linhas, vamos ver se existe na arvore algum que contenha essa declaracao
  194.             for(var j = splitLines.length; j >= 0; j--){
  195.               // Vamos subindo as arveres;
  196.               console.log(splitLines[j]);
  197.               /*
  198.               for(var k = 0; k < count(elements); k++){
  199.                 // Busca pelas classes se comeca com .
  200.                 if(splitLines[j][0] == "."){
  201.  
  202.                 }
  203.                 // Busca pelo id se comeca com #
  204.                 else if(splitLines[j][0] == "#"){
  205.  
  206.                 }
  207.                 // Busca pela tag.
  208.                 else{
  209.  
  210.                 }
  211.               } */
  212.             }
  213.             console.log("\n");
  214.           }
  215.         }
  216.         console.log(data);
  217.         console.log(splitData);
  218.         //$("#inputCSSEditorCSS").html(data);
  219.       });
  220.     }
  221.  
  222.     function getAllStyles(elem) {
  223.       if (!elem) return []; // Element does not exist, empty list.
  224.       var win = document.defaultView || window, style, styleNode = [];
  225.       if (win.getComputedStyle) { /* Modern browsers */
  226.           style = win.getComputedStyle(elem, '');
  227.           for (var i=0; i<style.length; i++) {
  228.               styleNode.push( style[i] + ':' + style.getPropertyValue(style[i]) );
  229.               //               ^name ^           ^ value ^
  230.           }
  231.       } else if (elem.currentStyle) { /* IE */
  232.           style = elem.currentStyle;
  233.           for (var name in style) {
  234.               styleNode.push( name + ':' + style[name] );
  235.           }
  236.       } else { /* Ancient browser..*/
  237.           style = elem.style;
  238.           for (var i=0; i<style.length; i++) {
  239.               styleNode.push( style[i] + ':' + style[style[i]] );
  240.           }
  241.       }
  242.       return styleNode;
  243.     }
  244.  
  245.  
  246.  
  247.  
  248.  
  249.     function removeFormCSSEditor(){
  250.     $("#containerCSSEditor").remove();
  251.     }
  252.  
  253.     var sheet = (function(){
  254.       var style = document.createElement("style");
  255.       style.appendChild(document.createTextNode(""));
  256.       document.head.appendChild(style);
  257.  
  258.       return style.sheet;
  259.     });
  260.     var v = sheet();
  261.     v.insertRule(
  262.       "#containerCSSEditor{"  +
  263.         "position: absolute;" +
  264.         "display: table;" +
  265.         "height: 600px;" +
  266.         "width: 450px;" +
  267.         "background: #e6e6e6;" +
  268.         "overflow-x: hidden;" +
  269.         "overflow-y: scroll;" +
  270.         "border-radius: 10px;" +
  271.         "border: 1px solid black;" +
  272.         "padding-top: 10px;" +
  273.       "}"
  274.     );
  275.     v.insertRule(
  276.       "#containerCSSEditor input, #containerCSSEditor button, #containerCSSEditor textarea{" +
  277.         "width: 80%; " +
  278.         "box-sizing: border-box; " +
  279.         "background: #616161; " +
  280.         "margin-left: 10%;" +
  281.         "margin-bottom: 4px; " +
  282.         "color: #FFF; " +
  283.         "font-family: monospace;" +
  284.         "border-radius: 5px;" +
  285.         "height: 20px;" +
  286.         "z-index: 10;" +
  287.       "}"
  288.     );
  289.     v.insertRule(
  290.       "#cssEditorTitleEdit{" +
  291.         "text-align: center;"+
  292.         "margin-top: 0;" +
  293.         "padding-bottom: 10px;" +
  294.         "border-bottom: 1px solid black;"+
  295.         "padding-right: 90px;" +
  296.         "padding-top: 8px; " +
  297.       "}"
  298.     )
  299.     v.insertRule(
  300.       "#cssEditorTitle{" +
  301.         "text-align: center;"+
  302.         "padding-bottom: 10px;" +
  303.         "margin-bottom: 0px;" +
  304.       "}"
  305.     )
  306.     v.insertRule(
  307.       "#CSSEditorUlContainer{" +
  308.         "max-height: 450px;" +
  309.         "overflow-x: hidden;" +
  310.         "overflow-y: scroll;" +
  311.         "margin-left: -40px" +
  312.       "}"
  313.     );
  314.     v.insertRule(
  315.       "#CSSEditorUlContainer li:first-child{" +
  316.         "border-top: 1px solid black;"+
  317.       "}"
  318.     );
  319.     v.insertRule(
  320.       ".cssEditorLi{" +
  321.         "padding-top: 15px;" +
  322.         "padding-bottom: 7px;" +
  323.         "padding-left: 25px;" +
  324.         "height: 25px;" +
  325.         "width: 100%;" +
  326.         "background: #e6e6e6;" +
  327.         "font-size: 14px;" +
  328.         " transition: transform .2s;" +
  329.         "border-bottom: 1px solid black;" +
  330.         "cursor: pointer;" +
  331.         "list-style-type: none;" +
  332.       "}"
  333.     );
  334.     v.insertRule(
  335.       ".cssEditorLi:hover{" +
  336.         "background: #b3b3b3;" +
  337.         "padding-left: 10px;" +
  338.         "transform: scale(1.1);" +
  339.         "border: 1px solid black;" +
  340.         "margin-top: 3px;" +
  341.         "margin-bottom: 3px;" +
  342.       "}"
  343.     );
  344.     v.insertRule(
  345.       ".button-voltar{" +
  346.         "color: black;" +
  347.         "cursor: pointer;" +
  348.         "margin-left: 20px;" +
  349.         "padding: 7px;" +
  350.         "border: 1px solid black;" +
  351.         "border-radius: 10px;" +
  352.         "background-color: #616161;" +
  353.         "font-family: monospace;" +
  354.         "color: white;" +
  355.       "}"
  356.     );
  357.     v.insertRule(
  358.       ".button-carregar{" +
  359.         "text-align: center;" +
  360.         "cursor: pointer;" +
  361.         "margin-left: 20px;" +
  362.         "padding: 7px;" +
  363.         "border: 1px solid black;" +
  364.         "border-radius: 10px;" +
  365.         "width: 80%; " +
  366.         "box-sizing: border-box; " +
  367.         "margin-left: 10%;" +
  368.         "background-color: #616161;" +
  369.         "font-family: monospace;" +
  370.         "color: white;" +
  371.       "}"
  372.     );
  373.    
  374.     v.insertRule(
  375.       "#divName{"+
  376.         "display: block;" +
  377.         "text-align: center;" +
  378.         "font-size: 14px;" +
  379.       "}"
  380.     );
  381.  
  382.     v.insertRule(
  383.       "#inputCSSEditorCSS{" +
  384.         "overflow-x: hidden;" +
  385.         "overflow-y: scroll;" +
  386.         "height: 100%!important;" +
  387.         "max-height: 360px!important;" +
  388.         "margin-top: 10px!important;" +
  389.         "margin-bottom: 10px!important;" +
  390.       "}"
  391.     );
  392.  
  393.     $("html").unbind().mousedown(rightclick);
  394.  
  395.     //window.onload = function() {
  396.       document.addEventListener("contextmenu", function(e){
  397.         if(e.which == 3 || e.button == 2){
  398.           e.preventDefault();
  399.         }
  400.       }, false);
  401.     //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement