-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathscript.min.js
13 lines (13 loc) · 7.27 KB
/
script.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
function scrollToTop(){let e=document.documentElement.scrollTop||document.body.scrollTop;e>0&&(window.requestAnimationFrame(scrollToTop),window.scrollTo(0,e-e/8))}const htmlBody=document.querySelector("html, body"),results=document.querySelector("#results"),scrollToResults=()=>{let e=results.offsetTop;htmlBody.scrollTo({top:e,behavior:"smooth"})},searchInput=document.getElementById("search-input"),searchButton=document.getElementById("search-button"),resultsContainer=document.getElementById("results"),corsProxy="https://cors-anywhere.pulkitpareekofficial.workers.dev/?url=";function optimisedImageUrl(e){return e.replace("._V1_.","._V1_QL75_UX160_.")}function fetchAndShow(){let e=encodeURIComponent(searchInput.value),t=`${corsProxy}https://v3.sg.media-imdb.com/suggestion/x/${e}.json`;Pace.restart(),fetch(t).then(e=>e.json()).then(e=>{let t=e.d;resultsContainer.innerHTML="",t.forEach(e=>{if(e.i&&("movie"===e.qid||"tvSeries"===e.qid)){let t=document.createElement("div");t.classList.add("result"),t.setAttribute("IMDB",e.id);let s="";"movie"===e.qid&&e.i?s=`<a onClick="setUrl(this); return setVideo(this);" url="imdb=${e.id}&type=movie&title=${e.l.replace(/ /g,"_")}" isWebSeries="false" title="${e.l}" class="links" IMDB="${e.id}" href="https://www.2embed.cc/embed/${e.id}" target="_blank">
<img alt="${e.l}" src="${optimisedImageUrl(e.i.imageUrl)}">
<div class="info">
<h3>${e.l}</h3>
<p>${e.s}</p>
</div>
</a>`:"tvSeries"===e.qid&&e.i&&(s=`<a onClick="setUrl(this); return setVideo(this);" url="imdb=${e.id}&season=1&episode=1&title=${e.l.replace(/ /g,"_")}" IMDB="${e.id}" title="${e.l}" isWebSeries="true" class="links" href="https://www.2embed.cc/embedtv/${e.id}&s=1&e=1" target="_blank">
<img alt="${e.l}" src="${optimisedImageUrl(e.i.imageUrl)}">
<div class="info">
<h3>${e.l}</h3>
<p>${e.s}</p>
</div>
</a>`),t.innerHTML=s,resultsContainer.appendChild(t)}})})}function setAll(e,t,s,i,l){if(e&&t&&!s&&!i&&l){let r=document.createElement("a");r.setAttribute("onClick","setUrl(this); return setVideo(this);"),r.setAttribute("url",`imdb=${e}&type=movie&title=${t.replace(/ /g,"_")}`),r.setAttribute("isWebSeries","false"),r.setAttribute("title",t),r.setAttribute("class","links"),r.setAttribute("IMDB",e),r.setAttribute("href","https://www.2embed.cc/embed/"+e),r.setAttribute("target","_blank"),r.click()}else if(e&&t&&i&&!l){let a=document.createElement("a");a.setAttribute("onClick","setUrl(this); return setVideo(this);"),console.log("season setall",s,"episode",i),a.setAttribute("url",`imdb=${e}&season=${s}&episode=${i}`),a.setAttribute("isWebSeries","true"),a.setAttribute("title",t),a.setAttribute("class","links"),a.setAttribute("IMDB",e),a.setAttribute("href",`https://www.2embed.cc/embedtv/${e}&s=${s}&e=${i}`),a.setAttribute("target","_blank"),a.click()}}const fetchTitle=async e=>{let t=`${corsProxy}https://v3.sg.media-imdb.com/suggestion/x/${e}.json`;try{let s=await fetch(t),i=await s.json(),l=i.d[0].l;return l}catch(r){console.error(r)}};function setUrl(e){let t=e.getAttribute("url");window.history.replaceState({},"",`?${t.replace(/%20/g,"+")}`)}function fillSearchInput(){let e=new URLSearchParams(window.location.search),t=e.get("search"),s=e.get("season"),i=e.get("episode"),l=e.get("imdb"),r=e.get("type");if(!t||s||i||l)!l||!r||t||i||s?l&&!t&&i&&s&&(console.log("season",s,"episode",i),fetchTitle(l).then(e=>setAll(l,e,s,i,r)).catch(e=>console.error(e)),console.log("season",s,"episode",i)):fetchTitle(l).then(e=>setAll(l,e,s,i,r)).catch(e=>console.error(e));else{t=t.replace(/\+/g,"%20");let a=document.querySelector("#search-input");a.value=t,fetchAndShow()}}function updateURL(e){let t=e.value;t?window.history.replaceState({},"",`?search=${encodeURIComponent(t).replace(/%20/g,"+")}`):window.history.replaceState({},"",window.location.pathname)}function highlightCards(){let e=new URLSearchParams(window.location.search).get("imdb");try{document.querySelectorAll(".result").forEach(function(e){e.className="result"}),document.querySelector(`div[IMDB=${e}]`).className="result hoverClass"}catch(t){}}fillSearchInput(),window.onpopstate=function(){let e=new URLSearchParams(window.location.search),t=e.get("search"),s=e.get("imdb");if(t||s){let i=document.getElementsByClassName("information");for(let l=0;l<i.length;l++)i[l].style.display="none"}else{let r=document.getElementsByClassName("information");for(let a=0;a<r.length;a++)r[a].style.display="block"}};let timer;function episodeHighlight(e="s1e1"){document.querySelectorAll(".episodes").forEach(function(e){e.className="episodes"}),document.querySelector(`.episodes[cssidentification='${e}']`).className="episodes selected"}function setVideo(e){let t=document.getElementById("iframe"),s=document.getElementById("video");t.src=e.getAttribute("href"),s.style.display="block";let i=document.getElementById("webSeriesData"),l="b6b677eb7d4ec17f700e3d4dfc31d005",r=e.getAttribute("IMDB");if(Pace.restart(),scrollToTop(),window.dispatchEvent(new PopStateEvent("popstate")),"false"==e.getAttribute("isWebSeries")&&"links"==e.className&&(i.innerHTML=""),""!==e.getAttribute("title")&&(document.title=e.getAttribute("title")),e.className.includes("episode")&&(episodeHighlight(e.getAttribute("cssidentification")),console.log("clicked")),"true"==e.getAttribute("isWebSeries")){async function a(){let e=await fetch(`https://api.themoviedb.org/3/find/${r}?api_key=${l}&language=en-US&external_source=imdb_id`),t=await e.json(),s=t.tv_results[0].id,a=await fetch(`https://api.themoviedb.org/3/tv/${s}?api_key=${l}&language=en-US`),n=await a.json(),o=n.number_of_seasons;i.innerHTML+="<h2>Seasons:</h2>";for(let c=1;c<=o;c++){i.innerHTML+=`<h3>Season ${c}:</h3><br>`;let d=document.createElement("div");d.classList.add("episode-container");let u="",h=await fetch(`https://api.themoviedb.org/3/tv/${s}/season/${c}?api_key=${l}&language=en-US`),p=await h.json();for(let m of p.episodes){let g=m.episode_number,b=g.toLocaleString("en-US",{minimumIntegerDigits:2,useGrouping:!1});u+=`<a class="episodes" title="${n.name+": E"+b+". "+m.name}" cssidentification="s${c}e${g}" url="imdb=${r}&season=${c}&episode=${g}&title=${n.name.replace(/ /g,"_")+"_E"+b+"_"+m.name.replace(/ /g,"_")}" onClick="event.preventDefault();setVideo(this);setUrl(this); " href="https://www.2embed.cc/embedtv/${r}&s=${c}&e=${g}">E${b}. ${m.name}</a>`}d.innerHTML=u,i.appendChild(d),episodeHighlight()}let f=new URLSearchParams(window.location.search),y=f.get("season"),v=f.get("episode");y&&v?document.querySelector(`a[cssIdentification="s${y}e${v}"]`).click():y&&!v?document.querySelector(`a[cssIdentification="s${y}e1"]`).click():document.querySelector('a[cssIdentification="s1e1"]').click()}i.innerHTML="",a()}function n(){dataLayer.push(arguments)}return window.dataLayer=window.dataLayer||[],n("js",new Date),n("config","G-THTQ9GZQ0J"),highlightCards(),!1}searchInput.addEventListener("keyup",function(){let e=this;clearTimeout(timer),timer=setTimeout(function(){updateURL(e),fetchAndShow(),window.dispatchEvent(new PopStateEvent("popstate")),scrollToResults()},500)}),searchButton.addEventListener("click",function(){fetchAndShow(),scrollToResults(),window.dispatchEvent(new PopStateEvent("popstate"))});