priMELval

mc colour codes

May 6th, 2019 (edited)
814
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.12 KB | None | 0 0
  1. <html>
  2. <body>
  3.  
  4.  
  5. Colours: <input type="text" value="c6ea395d" id="colorIn">
  6. <br>
  7. Text: <input type="text" value="text" id="textIn">
  8. <br>
  9. Random? <input type="checkbox" id="random"><br>
  10. Bold <input type="checkbox" id="bold"><br>
  11. Italic <input type="checkbox" id="italic"><br>
  12. Underline <input type="checkbox" id="under"><br>
  13. Strikethrough <input type="checkbox" id="strike"><br>
  14. <button onclick="makePretty()"> make fabulous</button>
  15. <br><br>
  16. <input type="text" value="" id="copy" >
  17.  
  18. <br>
  19. <p>Click the button below to copy to clipboard</p>
  20. <button style=" background-color:#777777;font-size:30px;" id="preview" onclick="copy()"> Preview </button>
  21.  
  22. <br><br>
  23. Presets:
  24. <br>
  25. <button onclick="getElementById('colorIn').value ='c6ea395d';getElementById('random').checked = false;">Rainbow</button>
  26. <button onclick="getElementById('colorIn').value ='1234567890abcdef';getElementById('random').checked = true;">All Colours</button>
  27. <br>
  28. <br>
  29. <div style="background-color:#777777;">
  30. <div style="color:#000000;"> 0 = Black </div>
  31. <div style="color:#0000aa;"> 1 = Dark Blue </div>
  32. <div style="color:#00aa00;"> 2 = Dark Green </div>
  33. <div style="color:#00aaaa;"> 3 = Aqua </div>
  34. <div style="color:#aa0000;"> 4 = Dark Red </div>
  35. <div style="color:#aa00aa;"> 5 = Purple </div>
  36. <div style="color:#aaaa00;"> 6 = Orange </div>
  37. <div style="color:#aaaaaa;"> 7 = Light Grey </div>
  38. <div style="color:#555555;"> 8 = Dark Grey </div>
  39. <div style="color:#5555ff;"> 9 = Blue </div>
  40. <div style="color:#55ff55;"> a = Light Green </div>
  41. <div style="color:#55ffff;"> b = Light Blue </div>
  42. <div style="color:#ff5555;"> c = Light Red </div>
  43. <div style="color:#ff55ff;"> d = Pink </div>
  44. <div style="color:#ffff55;"> e = Yellow </div>
  45. <div style="color:#000000;"> f = White </div>
  46. </div>
  47. <br>
  48. <script>
  49.  
  50.  
  51.     var copyText;
  52.     var mcColors = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];
  53.     var htmlColors = ["000000","0000aa","00aa00","00aaaa","aa0000","aa00aa","aaaa00","aaaaaa","555555","5555ff","55ff55","55ffff","ff5555","ff55ff","ffff55","ffffff"];
  54.    
  55.     //colour code part
  56.    
  57.     function makePretty() {
  58.         var textIn = document.getElementById("textIn").value;
  59.         var text = [...textIn];
  60.         var colorIn = document.getElementById("colorIn").value;
  61.         var colors = [...colorIn];
  62.         var textOut = "§" + text.join("§");
  63.         var thisColor;
  64.         var lastColor;
  65.         var loopNum = 0;
  66.         var formatting = "<formatting style='";
  67.        
  68.        
  69.         //spaces don't need colour codes smdh
  70.         while (textOut.includes("§ ")) {
  71.             textOut = textOut.replace("§ ", " ");
  72.         }
  73.        
  74.        
  75.         while (textOut.includes("§")) {
  76.             if (document.getElementById("random").checked) {
  77.        
  78.            
  79.                 thisColor = "&" + colors[Math.floor(Math.random() * colors.length)];
  80.            
  81.            
  82.             } else {
  83.        
  84.                 thisColor = "&" + colors[loopNum-colors.length*Math.floor(loopNum/colors.length)];
  85.                 loopNum++
  86.             }
  87.            
  88.             if (document.getElementById("bold").checked) {
  89.                 thisColor = thisColor.concat("&l");
  90.             }
  91.             if (document.getElementById("italic").checked) {
  92.                 thisColor = thisColor.concat("&o");
  93.             }
  94.             if (document.getElementById("under").checked) {
  95.                 thisColor = thisColor.concat("&n");
  96.             }
  97.             if (document.getElementById("strike").checked) {
  98.                 thisColor = thisColor.concat("&m");
  99.             }
  100.             //remove duplicate colours
  101.                 if (thisColor == lastColor) {
  102.                     textOut = textOut.replace("§", "");
  103.                 } else {
  104.                     textOut = textOut.replace("§", thisColor);
  105.                 }
  106.                 lastColor = thisColor;
  107.         }
  108.             if (document.getElementById("bold").checked) {
  109.                 formatting = formatting.concat("font-weight: bold;");
  110.             }
  111.             if (document.getElementById("italic").checked) {
  112.                 formatting = formatting.concat("font-style: italic;");
  113.             }
  114.            
  115.             formatting = formatting.concat("text-decoration:");
  116.            
  117.             if (document.getElementById("under").checked) {
  118.                 formatting = formatting.concat(" underline");
  119.             }
  120.             if (document.getElementById("strike").checked) {
  121.                 formatting = formatting.concat(" line-through");
  122.             }
  123.             formatting = formatting.concat(";'>");
  124.             previewText = textOut;
  125.             document.getElementById("copy").value = textOut;
  126.            
  127.     //preview part
  128.    
  129.             loopNum = 0;
  130.             previewText = previewText.replace(/&l/g, "");
  131.             previewText = previewText.replace(/&m/g, "");
  132.             previewText = previewText.replace(/&n/g, "");
  133.             previewText = previewText.replace(/&o/g, "");
  134.             matchColor = previewText.match(/(?<=\&)(.)/g);
  135.             previewText = previewText.replace("&"+ matchColor[loopNum], "<yeet style='color:#"+(htmlColors[mcColors.indexOf(matchColor[loopNum])])+"'>");
  136.                
  137.             while (previewText.includes("&")) {
  138.                 console.log(loopNum);
  139.                 console.log(matchColor[loopNum]);
  140.                 previewText = previewText.replace("&"+ matchColor[loopNum], "</yeet><yeet style='color:#"+(htmlColors[mcColors.indexOf(matchColor[loopNum])])+"'>");
  141.                 loopNum++;
  142.             }
  143.            
  144.             document.getElementById("preview").innerHTML = formatting + previewText + "</yeet> </formatting>";
  145.     }
  146.    
  147.    
  148.     function copy() {
  149.        
  150.         console.log("does this work?");
  151.         var copyText = document.getElementById("copy");
  152.         copyText.select();
  153.         copyText.setSelectionRange(0, 99999);
  154.         document.execCommand("copy");
  155.     }
  156.        
  157. </script>
  158. </body>
  159. </html>
Add Comment
Please, Sign In to add comment