1(function($) { 2 3 let darkModeClass = 'darklooks-mode-changer-enabled', 4 dark_mode_storage_key = 'darklooksDarkModeEnabled', 5 $is_dark = localStorage.getItem(dark_mode_storage_key), 6 $modeChanger = $('.darklooks-mode-changer'); 7 8 9 // Enabled Time based mode 10 if( darklooksFrontendObject.modetime || $is_dark ) { 11 // is mode time active 12 $is_dark = true; 13 // 14 operationBunker(); 15 } 16 17 // Mode changing 18 $modeChanger.on( 'click', function() { 19 $is_dark = $(this).is(':checked'); 20 // 21 operationBunker(); 22 } ) 23 24/** 25 * OS Dark/Light 26 * 27 */ 28 29if( darklooksFrontendObject.is_os ) { 30 31 // OS Dark Event 32 if( window.matchMedia('(prefers-color-scheme: dark)').matches ) { 33 $is_dark = true; 34 // 35 operationBunker(); 36 } 37 38 // OS Light Event 39 if( window.matchMedia('(prefers-color-scheme: light)').matches ) { 40 $is_dark = false; 41 // 42 operationBunker(); 43 } 44} 45 46/** 47 * Image and logo change on mode 48 * 49 */ 50function operationBunker() { 51 52let getLogoUrl = darklooksFrontendObject.site_logo, 53 lightLogo = getLogoUrl.light_logo, 54 darkLogo = getLogoUrl.dark_logo, 55 getImages = darklooksFrontendObject.images, 56 $switch = $('.darklooks-mode-changer'), 57 $html = $('html'); 58 59 if( $is_dark ) { 60 // Add Dark Class 61 $html.addClass(darkModeClass); 62 // Add checked attr in switcher 63 $switch.attr( 'checked', true ); 64 //Dark mode enabled status set in local store 65 localStorage.setItem(dark_mode_storage_key, $is_dark ); 66 // Dark Logo 67 $('[src="'+lightLogo+'"]').attr( {src: darkLogo,srcset:darkLogo} ); 68 // Show dark image 69 $.each( getImages, function( key, item ) { 70 $('[src="'+item[0]+'"]').attr( {src: item[1],srcset:item[1]} ); 71 } ) 72 73 } else { 74 75 // Remove Dark Class 76 $html.removeClass(darkModeClass); 77 // Remove checked attr in switcher 78 $switch.attr( 'checked', false ); 79 // remove dark mode enabled status from local store 80 localStorage.removeItem(dark_mode_storage_key); 81 // Light Logo 82 $('[src="'+darkLogo+'"]').attr( {src: lightLogo,srcset:lightLogo} ); 83 // Show light image 84 $.each( getImages, function( key, item ) { 85 $('[src="'+item[1]+'"]').attr( {src: item[0],srcset:item[0]} ); 86 } ) 87 } 88} 89 90 91/** 92 * 93 * Dark mode neglect background selector 94 * 95 */ 96 97function neglect_bg_elements() { 98 99 document.querySelectorAll( "div, section, header, footer, main, aside" ).forEach( function(e) { 100 101 if( "none" !== window.getComputedStyle(e, null).backgroundImage ) { 102 e.classList.add("dl-dark-neglect"); 103 e.querySelectorAll("*").forEach(function (e) { 104 return e.classList.add("dl-dark-neglect"); 105 }) 106 } 107 108 }); 109} 110document.addEventListener("DOMContentLoaded", neglect_bg_elements); 111 112 113})(jQuery)
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.