Advertisement
edgeworth

drawbox color

Jun 11th, 2025 (edited)
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*    BELOW CODE ADDED BY AGLOVALE.NEKOWEB.ORG    */
  2.  
  3. let colors = ["black", "white", "lightgrey", "crimson", "orange", "gold", "lightgreen",
  4. "cyan", "royalblue", "mediumorchid", "violet", "pink"];
  5.  
  6. function changeColor(e){
  7.     let id = e.id;
  8.     if (id){
  9.         id = id.replace('hash-code-', '#');
  10.     }
  11.     updateQueue(id);
  12. }
  13.  
  14. function updateQueue(c){
  15.     stroke_color = c;
  16.     if (colors.includes(c)){
  17.         colors = colors.filter(function(color) {
  18.             return color !== c;
  19.         });
  20.     } else {
  21.         colors.pop();
  22.     }
  23.     colors.unshift(c);
  24.     renderColor();
  25. }
  26.  
  27. function renderColor(){
  28.     let container = document.getElementById('drawbox-stroke-colors');
  29.     container.textContent = '';
  30.     colors.forEach((c) => {
  31.         let color = document.createElement('div');
  32.         color.setAttribute('onclick', 'changeColor(this)');
  33.         color.setAttribute('style',`background:${c}`);
  34.         color.setAttribute('id', c.replace('#','hash-code-'));
  35.         color.setAttribute('class', 'stroke-color');
  36.         container.appendChild(color);
  37.     });
  38. }
  39.  
  40. renderColor();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement