1var aginlinecss_fired = false; 2 3function aginlinecss_action_scripts(){ 4 var event = new CustomEvent('agciAction', {}); 5 document.dispatchEvent(event); 6} 7 8function agic_ready_event(){ 9 document.addEventListener("DOMContentLoaded", function(){ 10 var event = new CustomEvent('agciReady', {}); 11 document.dispatchEvent(event); 12 13 let bLoader = document.querySelector('.css-body-loader'); 14 if(bLoader){ 15 document.querySelector('body').style.display = 'block'; 16 bLoader.remove(); 17 } 18 }); 19} 20 21function agic_action_event(){ 22 document.addEventListener("DOMContentLoaded", function(){ 23 window.addEventListener('touchstart', function(){ 24 if(aginlinecss_fired === false){ 25 aginlinecss_fired = true; 26 setTimeout(function(){aginlinecss_action_scripts();}, 50); 27 } 28 }); 29 window.addEventListener('scroll', function(){ 30 if(aginlinecss_fired === false){ 31 aginlinecss_fired = true; 32 setTimeout(function(){aginlinecss_action_scripts();}, 50); 33 } 34 }); 35 window.addEventListener('mousemove', function(){ 36 if(aginlinecss_fired === false){ 37 aginlinecss_fired = true; 38 setTimeout(function(){aginlinecss_action_scripts();}, 50); 39 } 40 }); 41 }); 42} 43 44function agic_webp_check(attrs){ 45 document.addEventListener("DOMContentLoaded", function(){ 46 setTimeout(function(){ 47 agci_send_optimize(attrs); 48 }, 3000); 49 }); 50} 51 52function agci_send_optimize(attrs){ 53 let srcList = [], srcMake = [], imgs, i, bgsrc, src; 54 55 imgs = document.querySelectorAll('img'); 56 for(i=0; i<imgs.length; i++){ 57 attrs.forEach(function(prop){ 58 src = imgs[i].getAttribute(prop); 59 if(src){ 60 srcList.push(src); 61 } 62 }); 63 } 64 65 imgs = document.querySelectorAll('a'); 66 for(i=0; i<imgs.length; i++){ 67 src = imgs[i].getAttribute('href'); 68 if(src){ 69 if(src.indexOf('.png') > 0 || src.indexOf('.jpeg') > 0 || src.indexOf('.jpg') > 0){ 70 srcList.push(src); 71 } 72 } 73 } 74 75 imgs = document.querySelectorAll('*'); 76 for(i=0; i<imgs.length; i++){ 77 bgsrc = imgs[i].style.backgroundImage; 78 if(bgsrc.length && bgsrc != 'none' && bgsrc != 'initial'){ 79 bgsrc = bgsrc.match(/url\(["']?([^"']*)["']?\)/); 80 if(bgsrc){ 81 srcList.push(bgsrc[1]); 82 } 83 } 84 } 85 86 if(srcList.length){ 87 for(let i=0; i<srcList.length; i++){ 88 src = srcList[i]; 89 if(src.indexOf('.webp') == -1 && src.substr(0, 2) != '//' && src.substr(0, 5) != 'http:' && src.substr(0, 6) != 'https:'){ 90 if(src.indexOf('.png') > 0 || src.indexOf('.jpeg') > 0 || src.indexOf('.jpg') > 0){ 91 srcMake.push(src); 92 } 93 } 94 } 95 } 96 97 if(srcMake.length){ 98 BX.ajax({ 99 url: '/bitrix/tools/arturgolubev.cssinliner/ajax.php', 100 data: { 101 action: 'convert_webp', 102 images: srcMake, 103 path: window.location.pathname, 104 sessid: BX.bitrix_sessid() 105 }, 106 method: 'POST', 107 // dataType: 'json', 108 dataType: 'html', 109 timeout: 60, 110 async: true, 111 processData: false, 112 scriptsRunFirst: false, 113 start: true, 114 cache: false, 115 onsuccess: function(data){ 116 // console.log(data); 117 }, 118 onfailure: function(){ 119 console.log('arturgolubev.inlinecss webp error'); 120 } 121 }); 122 } 123} 124 125BX.addCustomEvent("onFrameDataReceivedBefore", function(json) { 126 for (i=0; i<json.dynamicBlocks.length; i++) { 127 json.dynamicBlocks[i].PROPS.CSS = ''; 128 } 129}); 130 131BX.addCustomEvent("onFrameDataReceived" , function(json) { 132 var unitedStyle = false; 133 if(json.css){ 134 for (key in json.css) { 135 if(json.css[key].indexOf("css_united") >= 0){ 136 unitedStyle = json.css[key]; 137 } 138 } 139 } 140 141 if(unitedStyle){ 142 // console.log('unitedStyle', unitedStyle); 143 144 var reloadByFind = true, reloadByError = document.body.classList.contains('agic_reload_css'); 145 146 var links = document.querySelectorAll('link[rel="stylesheet"]'); 147 if(links.length){ 148 links.forEach(function(item){ 149 if(item.href){ 150 if(item.href.indexOf(unitedStyle) >= 0){ 151 reloadByFind = false; 152 } 153 } 154 }); 155 } 156 157 if (reloadByError || reloadByFind){ 158 // console.log("Reload css", 'reloadByError: ' + reloadByError, 'reloadByFind: ' + reloadByFind); 159 160 var link = document.createElement('link'); 161 link.rel = 'stylesheet'; 162 link.href = unitedStyle + '?v=updated'; 163 document.head.appendChild(link); 164 } 165 } 166});
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.