Advertisement
nrzmalik

Storyline Closed Caption Font Customization

Mar 22nd, 2024 (edited)
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 3.39 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.    .view-phone #bottom-bar * {
  30.     pointer-events: auto;
  31. }
  32.   `;
  33.  
  34. addCssToHead(css);
  35.  
  36. var fontFamilyLabel = document.createElement("label");
  37.     fontFamilyLabel.textContent = "CC Font Family";
  38.      fontFamilyLabel.classList.add("switch-label");
  39.  
  40.     var fontFamilySelect = document.createElement("select");
  41.     fontFamilySelect.id = "fontFamily";
  42.     var fontFamilies = [
  43.         "Arial",
  44.         "Helvetica",
  45.         "Times New Roman",
  46.         "Verdana",
  47.         "Georgia",
  48.         "Palatino",
  49.         "Garamond",
  50.         "Courier New",
  51.         "Brush Script MT"
  52.     ];
  53.     fontFamilies.forEach(function(fontFamily) {
  54.         var option = document.createElement("option");
  55.         option.value = fontFamily;
  56.         option.textContent = fontFamily;
  57.         fontFamilySelect.appendChild(option);
  58.     });
  59.  
  60.     var fontSizeLabel = document.createElement("label");
  61.     fontSizeLabel.textContent = "CC Font Size";
  62.     fontSizeLabel.classList.add("switch-label");
  63.  
  64.     var fontSizeSelect = document.createElement("select");
  65.     fontSizeSelect.id = "fontSize";
  66.     var fontSizes = [8, 10, 12, 14, 16, 18, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72];
  67.     fontSizes.forEach(function(fontSize) {
  68.         var option = document.createElement("option");
  69.         option.value = fontSize;
  70.         option.textContent = fontSize;
  71.         fontSizeSelect.appendChild(option);
  72.     });
  73. fontSizeSelect.value = "14";
  74.     var shortcutsSwitch = document.querySelector('[data-ref="acctextSwitch"]');
  75.  
  76.     shortcutsSwitch.insertAdjacentHTML('afterend', '<br><br>');
  77.     shortcutsSwitch.insertAdjacentElement('afterend', fontFamilySelect);
  78.     shortcutsSwitch.insertAdjacentElement('afterend', fontFamilyLabel);
  79.     shortcutsSwitch.insertAdjacentHTML('afterend', '<br><br>');
  80.     shortcutsSwitch.insertAdjacentElement('afterend', fontSizeSelect);
  81.     shortcutsSwitch.insertAdjacentElement('afterend', fontSizeLabel);
  82.    
  83.    
  84.  
  85.     fontFamilySelect.addEventListener("change", applyFont);
  86.     fontSizeSelect.addEventListener("change", applyFont);
  87.    
  88.     function applyFont() {
  89.     var selectedFont = document.getElementById("fontFamily").value;
  90.     var selectedSize = document.getElementById("fontSize").value;
  91.  
  92.     var styleElement = document.createElement("style");
  93.     styleElement.type = "text/css";
  94.  
  95.     var cssRule = ".caption { font-family: " + selectedFont + " !important; font-size: " + selectedSize + "px !important; }";
  96.  
  97.     if (styleElement.styleSheet) {
  98.         styleElement.styleSheet.cssText = cssRule;
  99.     } else {
  100.         styleElement.appendChild(document.createTextNode(cssRule));
  101.     }
  102.  
  103.     var existingStyleElement = document.getElementById("fontStyle");
  104.     if (existingStyleElement) {
  105.         existingStyleElement.parentNode.removeChild(existingStyleElement);
  106.     }
  107.  
  108.     styleElement.id = "fontStyle";
  109.  
  110.     document.head.appendChild(styleElement);
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement