var MCProvider=class{constructor(){this.ids={},this.videos=[]}run(){setInterval(()=>this.search(),1e3)}search(){chrome&&chrome.app&&void 0!==chrome.app.isInstalled&&chrome.runtime.sendMessage({tip:"metacafeVideo",title:document.title},e=>{let t=[],i=document.getElementsByClassName("poster");i.length&&(i=i[0].style.backgroundImage.match(/url\("(.*?)"\)/)[1]),e&&e.length!==this.videos.length&&(e.forEach((n,s)=>{if(!n.url)return!0;var o={type:n.type,url:n.url,title:document.title,fileName:document.title,superSpecialFileName:"true",bytSize:n.size,videoType:"MP4",poster:i,videoIndex:Number(n.url.match(/_0+(.*?)\./)[1])+1,isSelect:!1};this.videos=e,t.push(o)}),t.length&&chrome.runtime.sendMessage({tip:"addVideoBg",row:t}))})}addVideo(e,t){this.ids[e]=!0,this.getVideoData(e,i=>i.variants.length?void this.getAllSizes(i.variants,n=>{i.variants=n,this.videos=this.videos.concat(i),this.renderBtn(e,t)}):void 0)}getVideoData(){}renderBtn(e,t){if(!RENDER_BTN_ON_VIDEO)return;const i=this.videos.find(t=>t.vid===e);if(!i)return;const n=i.variants.map(e=>`\n            <div class="mtz-download-btn-dropdown-item" quality="${e.quality}">${e.quality}</div>\n        `).join("");$(`\n            <button class="mtz-download-btn" vid="${e}">\n                <span>Download</span>\n                <div class="mtz-download-btn-dropdown">${n}</div>\n            </button>\n        `).appendTo(t).on("click",e=>{e.stopPropagation(),this.download(e.target)})}getAllSizes(e,t){if(!GET_FILE_SIZE)return t(e);const i=e.map(e=>this.getFileSize(e.url));Promise.all(i).then(i=>{e.forEach((t,n)=>e[n].size=i[n]),t(e)})}getFileSize(e){return new Promise(t=>{const i=new XMLHttpRequest;i.open("HEAD",e,!0),i.onload=()=>{if(200===i.status){const e=+i.getResponseHeader("Content-Length");return t(e)}t(0)},i.onerror=()=>t(0),i.send()})}getCookie(e){var t=("; "+document.cookie).split("; "+e+"=");if(2==t.length)return t.pop().split(";").shift()}betweenStr(e,t,i){if(!t&&!i)return e;let n="";const s=e.indexOf(t);if(-1===s&&(n=""),0<=s&&(n=e.substr(s+t.length,e.length)),!i)return n;const o=n.indexOf(i);return-1===o&&-1!==s||-1===o?"":(n=n.substr(0,o),n)}},mcProvider=new MCProvider;mcProvider.run();