1/* Javascript */ 2 3// Call theme value from browsers local storage. 4var theme = localStorage.getItem("theme"); 5// Root element of the document. 6const _root = document.documentElement; 7 8// Check if local storage has no theme value, define the initial value. 9!theme && localStorage.setItem("theme", "light"); 10 11// Update theme value. 12theme = localStorage.getItem("theme"); 13 14// Apply theme value to document root element. 15_root.setAttribute("data-theme", theme); 16 17// Function for change theme. 18// You can define this function to the a button or call this any way. 19function changeTheme() { 20 theme === "light" 21 ? localStorage.setItem("theme", "dark") 22 : localStorage.setItem("theme", "light"); 23 24 // Update theme value 25 theme = localStorage.getItem("theme"); 26 27 // Apply theme to document root element 28 _root.setAttribute("data-theme", theme); 29}
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.