Advertisement
nrzmalik

Articulate Storyline Captions Color Update

Aug 8th, 2023
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.91 KB | Source Code | 0 0
  1. function injectStyles(backgroundColor, textColor) {
  2.    
  3.     function hexToRgba(hex, alpha = 1) {
  4.         const [r, g, b] = [
  5.             parseInt(hex.slice(1, 3), 16),
  6.             parseInt(hex.slice(3, 5), 16),
  7.             parseInt(hex.slice(5, 7), 16)
  8.         ];
  9.         return `rgba(${r}, ${g}, ${b}, ${alpha})`;
  10.     }
  11.  
  12.    
  13.     const bgColor = (backgroundColor[0] === '#') ? hexToRgba(backgroundColor, 0.95) : backgroundColor;
  14.  
  15.     const styleEl = document.createElement('style');
  16.     document.head.appendChild(styleEl);
  17.    
  18.     const styles = `
  19.         .caption p {
  20.             background-color: ${bgColor};
  21.             color: ${textColor};
  22.             text-shadow: none;
  23.         }
  24.     `;
  25.  
  26.     styleEl.appendChild(document.createTextNode(styles));
  27. }
  28. let player = GetPlayer();
  29. var background = player.GetVar("BackgroundColor");
  30. var color = player.GetVar("TextColor");
  31. injectStyles(background, color);
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement