1const ThemeService = { 2 /** 3 * Saves the website colors to a cookie. 4 */ 5 saveColors() { 6 let colors = document.querySelector("body").dataset.colors; 7 if (!CookieService.getCookie("site-colors")) { 8 CookieService.setCookie("site-colors", colors, 30); 9 } 10 }, 11 /** 12 * Retrieves the saved website colors from the cookie. 13 * 14 * @returns {Object} - The saved colors in JSON format or null if no colors are saved. 15 */ 16 getSavedColors() { 17 const savedColors = JSON.parse(CookieService.getCookie('site-colors')); 18 return savedColors ? JSON.parse(savedColors) : false; 19 }, 20 /** 21 * Converts a hexadecimal color code to an RGB value. 22 * 23 * @param {string} color - The hexadecimal color code, for example "#FF0000". 24 * @returns {string} - The RGB value, for example "rgb(255, 0, 0)". 25 */ 26 hexToRgb(color) { 27 if (!/^#[0-9A-F]{6}$/i.test(color)) { 28 return; 29 } 30 31 let hex = color.startsWith("#") ? color.slice(1) : color; 32 let r = parseInt(hex.substring(0, 2), 16); 33 let g = parseInt(hex.substring(2, 4), 16); 34 let b = parseInt(hex.substring(4, 6), 16); 35 36 return `rgb(${r}, ${g}, ${b})`; 37 }, 38 /** 39 * Sets the background color of HTML elements to a gradient of the given RGB color. 40 * 41 * @param {string} colorRGB - The RGB color value, for example "rgb(255, 0, 0)". 42 * @param {number} colorStep - The step size for the gradient. 43 * @param {jQuery} htmlBlocks - The HTML elements to set the background color of. 44 * @param {string} action - The type of gradient, either "increasing" or "decreasing". 45 */ 46 setBgColor(colorRGB, colorStep, htmlBlocks, action) { 47 let [r, g, b] = colorRGB.slice(4, -1).split(',').map(Number); 48 49 htmlBlocks.each(function (index) { 50 let newR, newG, newB; 51 52 switch (action) { 53 case 'decreasing': 54 newR = r + (255 - r) * colorStep * index; 55 newG = g + (255 - g) * colorStep * index; 56 newB = b + (255 - b) * colorStep * index; 57 break; 58 case 'increasing': 59 newR = r * (1 + colorStep * index); 60 newG = g * (1 + colorStep * index); 61 newB = b * (1 + colorStep * index); 62 break; 63 default: 64 return; 65 } 66 67 // Ensure RGB values are within the range 0-255 68 newR = Math.min(255, Math.max(0, Math.round(newR))); 69 newG = Math.min(255, Math.max(0, Math.round(newG))); 70 newB = Math.min(255, Math.max(0, Math.round(newB))); 71 72 $(this).css('backgroundColor', `rgb(${newR}, ${newG}, ${newB})`); 73 }); 74 } 75} 76 77 78 79
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.