$(document).ready(async function(){if('indexedDB' in window){var id_video='video_home';var dbName='db_video';var storeName='videos';if(!$("#"+id_video).length){return;}var info_video=await readIndexedDB(dbName,storeName,id_video);var read_from_cache=false;if(info_video !=undefined)read_from_cache=!skipCache(info_video);if(read_from_cache){var videoURL=URL.createObjectURL(info_video.data);$("<video class='bck_video_bottom video_cache' style='z-index:7;display:none;' playsinline='' loop='' muted='' autoplay src='"+videoURL+"'></video>").insertBefore("#"+id_video);$(".video_cache").fadeIn(400);setTimeout(function(){$("#"+id_video).detach();},500);}else{writeIndexedDB(dbName,storeName,id_video);}}});function skipCache(info_video){var res=true;$.ajax({type:'POST',url:"/ajax_video.php",data:{OP:"fmtime_video",src:($("#"+info_video.id+" source").attr('src'))},async:false}).done(function(json){try{ json=JSON.parse(json);var fmtime=json.fmtime; res=(info_video.time<fmtime); }catch(error){res= true; }}).fail(function(){res= true;});return res;}async function readIndexedDB(dbName,storeName,key){try{var db=await openIndexedDB(dbName,storeName);var transaction=db.transaction([storeName],'readonly');var objectStore=transaction.objectStore(storeName);var request=objectStore.get(key);return new Promise((resolve,reject)=>{request.onsuccess=(event)=>{resolve(event.target.result);};request.onerror=(event)=>{reject(event.target.error);};});}catch(error){indexedDB.deleteDatabase(dbName);}}async function writeIndexedDB(dbName,storeName,key){try{var videoElement=document.getElementById(key);var videoURL=videoElement.currentSrc;var response=await fetch(videoURL);var videoBlob=await response.blob();var db=await openIndexedDB(dbName,storeName);var transaction=db.transaction([storeName],'readwrite');var objectStore=transaction.objectStore(storeName);var data={id:key,time:Math.floor(Date.now()/ 1000),data:videoBlob};var request=objectStore.put(data,key);request.onsuccess=()=>{};request.onerror=(event)=>{};}catch(error){indexedDB.deleteDatabase(dbName);}}function openIndexedDB(dbName,storeName){return new Promise((resolve,reject)=>{var openRequest=indexedDB.open(dbName,1);openRequest.onupgradeneeded=(event)=>{var db=event.target.result;if(!db.objectStoreNames.contains(storeName)){db.createObjectStore(storeName); } };openRequest.onsuccess=(event)=>{resolve(event.target.result); };openRequest.onerror=(event)=>{reject(event.target.error); }; });}