Advertisement
nrzmalik

Storyline Caption Customization

Mar 22nd, 2024 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 3.34 KB | Source Code | 0 0
  1. function addCssToHead(cssRules) {
  2.     var styleElement = document.createElement('style');
  3.     styleElement.textContent = cssRules;
  4.     document.head.appendChild(styleElement);
  5. }
  6.  
  7. var css = `select {
  8.   display: inline-block;
  9.   padding: 4px 4px;
  10.   font-size: 15px;
  11.   font-family: Arial, sans-serif;
  12.   border: 1px solid #ccc;
  13.   background-color: #fff;
  14.   color: #585858;
  15.   cursor: pointer;
  16.   outline: none;
  17. }
  18.  
  19. select option {
  20.   padding: 10px 15px;
  21.   font-size: 15px;
  22.   color: #585858;
  23.   cursor: pointer;
  24. }
  25.  
  26. select:focus {
  27.   border-color: #007bff;
  28. }
  29.   `;
  30.  
  31. addCssToHead(css);
  32.  
  33. var fontFamilyLabel = document.createElement("label");
  34.     fontFamilyLabel.textContent = "CC Font Family";
  35.      fontFamilyLabel.classList.add("switch-label");
  36.  
  37.     var fontFamilySelect = document.createElement("select");
  38.     fontFamilySelect.id = "fontFamily";
  39.     var fontFamilies = [
  40.         "Arial",
  41.         "Helvetica",
  42.         "Times New Roman",
  43.         "Verdana",
  44.         "Georgia",
  45.         "Palatino",
  46.         "Garamond",
  47.         "Courier New",
  48.         "Brush Script MT"
  49.     ];
  50.     fontFamilies.forEach(function(fontFamily) {
  51.         var option = document.createElement("option");
  52.         option.value = fontFamily;
  53.         option.textContent = fontFamily;
  54.         fontFamilySelect.appendChild(option);
  55.     });
  56.  
  57.     var fontSizeLabel = document.createElement("label");
  58.     fontSizeLabel.textContent = "CC Font Size";
  59.     fontSizeLabel.classList.add("switch-label");
  60.  
  61.     var fontSizeSelect = document.createElement("select");
  62.     fontSizeSelect.id = "fontSize";
  63.     var fontSizes = [8, 10, 12, 14, 16, 18, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72];
  64.     fontSizes.forEach(function(fontSize) {
  65.         var option = document.createElement("option");
  66.         option.value = fontSize;
  67.         option.textContent = fontSize;
  68.         fontSizeSelect.appendChild(option);
  69.     });
  70. fontSizeSelect.value = "14";
  71.     var shortcutsSwitch = document.querySelector('[data-ref="shortcutsSwitch"]');
  72.  
  73.     shortcutsSwitch.insertAdjacentHTML('afterend', '<br><br>');
  74.     shortcutsSwitch.insertAdjacentElement('afterend', fontFamilySelect);
  75.     shortcutsSwitch.insertAdjacentElement('afterend', fontFamilyLabel);
  76.     shortcutsSwitch.insertAdjacentHTML('afterend', '<br><br>');
  77.     shortcutsSwitch.insertAdjacentElement('afterend', fontSizeSelect);
  78.     shortcutsSwitch.insertAdjacentElement('afterend', fontSizeLabel);
  79.    
  80.    
  81.  
  82.     fontFamilySelect.addEventListener("change", applyFont);
  83.     fontSizeSelect.addEventListener("change", applyFont);
  84.    
  85.     function applyFont() {
  86.     var selectedFont = document.getElementById("fontFamily").value;
  87.     var selectedSize = document.getElementById("fontSize").value;
  88.  
  89.     var styleElement = document.createElement("style");
  90.     styleElement.type = "text/css";
  91.  
  92.     var cssRule = ".caption { font-family: " + selectedFont + " !important; font-size: " + selectedSize + "px !important; }";
  93.  
  94.     if (styleElement.styleSheet) {
  95.         styleElement.styleSheet.cssText = cssRule;
  96.     } else {
  97.         styleElement.appendChild(document.createTextNode(cssRule));
  98.     }
  99.  
  100.     var existingStyleElement = document.getElementById("fontStyle");
  101.     if (existingStyleElement) {
  102.         existingStyleElement.parentNode.removeChild(existingStyleElement);
  103.     }
  104.  
  105.     styleElement.id = "fontStyle";
  106.  
  107.     document.head.appendChild(styleElement);
  108. }
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement