var FORMAT_LABEL={17:"3GP 144p",18:"MP4 360p",22:"MP4 720p",44:"WebM 480p",45:"WebM 720p",46:"WebM 1080p",91:"MP4 144p",92:"MP4 240p",93:"MP4 360p",94:"MP4 480p",95:"MP4 720p",96:"MP4 1080p",300:"MP4 720p 60fps",301:"MP4 1080p 60fps",133:"MP4 240p (Video)",134:"MP4 360p (Video)",135:"MP4 480p (Video)",136:"MP4 720p (Video)",137:"MP4 1080p (Video)",160:"MP4 144p (Video)",mp3128:"mp3128",mp3256:"mp3256","720P":"720P","1080p3":"1080p3",Settings:"Settings",About:"About",Donate:"Donate"};const b=e=>Object.assign({},...e.split("&").map(e=>(kva=e.split("=").map(decodeURIComponent),{[kva[0]]:kva[1]})));function notifyExtension(e){var t=e.currentTarget,a=t.getAttribute("download");return a=(a=a.replace(/[/\\?%*:|"<>]/g,"-")).replace(/[\u200B-\u200D\uFEFF]/g,"-"),e.returnValue=!1,e.preventDefault&&e.preventDefault(),t.getAttribute("loop")&&chrome.runtime.sendMessage({action:"download",url:t.getAttribute("href"),filename:a}),!1}var M,videoId,P,proKey;function A(e){var t=e.currentTarget;e.returnValue=!1,e.preventDefault&&e.preventDefault();var a=t.getAttribute("loop"),o=t.getAttribute("id");return P=(P=P.replace(/[/\\?%*:|"<>]/g,"-")).replace(/[\u200B-\u200D\uFEFF]/g,"-"),o=o.substring(10),a&&chrome.tabs.sendMessage(M,{msg:"loadFrame",data:o,vid:videoId,videoTitle:P,key:proKey,loop:a}),window.close(),!1}function k(e){e=JSON.parse(e),P=e.videoTitle,proKey=e.key,$(".VideoTitle").text(P);var t=e.VideoData;for(let e=0;e<t.length;e++){var a=t[e].format;if(FORMAT_LABEL[a]){let a=document.createElement("a"),o=t[e].url;a.setAttribute("id","ytdl_link_"+t[e].format),a.setAttribute("class","list-group-item list-group-item-action"),a.setAttribute("loop",e+""),a.innerText=t[e].label,t[e].isHlsStream||o&&o.indexOf(".m3u8")>-1?a.addEventListener("click",A,!1):t[e].download||t[e].external?(a.setAttribute("href",o),a.setAttribute("target","_blank"),t[e].external||(a.addEventListener("click",notifyExtension,!1),a.setAttribute("download",t[e].download))):a.addEventListener("click",A,!1),$(a).appendTo(".LinkContainer")}}$(".Loading").hide(),setTimeout(function(){try{chrome.tabs.sendMessage(M,{msg:"getList",data:videoId},function(e){if(e&&e.data)try{var t=JSON.parse(e.data),a=t&&t.VideoData?t.VideoData:[];for(let e=0;e<a.length;e++){var o=document.getElementById("ytdl_link_"+a[e].format);o&&a[e].label&&(o.textContent=a[e].label)}}catch(e){}})}catch(e){}},600)}$(document).ready(function(){$(".Loading").show(),$(".notYoutube").hide(),chrome.tabs.query({active:!0,currentWindow:!0},function(tabs){if(-1!==tabs[0].url.indexOf("youtube.com/watch")||-1!==tabs[0].url.indexOf("youtube.com/shorts/")||-1!==tabs[0].url.indexOf("youtube.com/live/")){if(M=tabs[0].id,tabs[0].url.indexOf("shorts/")>-1)try{var e=tabs[0].url.split("shorts/")[1]||"";e=(e=e.split("?")[0]).split("/")[0],videoId=e}catch(e){videoId=tabs[0].url.split("shorts/")[1]}else{const query=b(tabs[0].url.split("?")[1]);videoId=query["v"]}chrome.tabs.sendMessage(M,{msg:"getList",data:videoId},function(e){console.log("Executed..."),e&&k(e.data)})}else $(".Loading").hide(),$(".notYoutube").show()})});