-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathscript.min.js
More file actions
13 lines (13 loc) · 8.35 KB
/
script.min.js
File metadata and controls
13 lines (13 loc) · 8.35 KB
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 i="";"movie"===e.qid&&e.i?i=`<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&&(i=`<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=i,resultsContainer.appendChild(t)}})})}const fetchTitle=async e=>{let t=`${corsProxy}https://v3.sg.media-imdb.com/suggestion/x/${e}.json`;try{let i=await fetch(t),s=await i.json(),r=s.d[0].l;return r}catch(l){console.error(l)}};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"),i=e.get("season"),s=e.get("episode"),r=e.get("imdb"),l=e.get("type");if(!t||i||s||r)!r||!l||t||s||i?r&&!t&&s&&i&&(console.log("season",i,"episode",s),fetchTitle(r).then(e=>setAll(r,e,i,s,l)).catch(e=>console.error(e)),console.log("season",i,"episode",s)):fetchTitle(r).then(e=>setAll(r,e,i,s,l)).catch(e=>console.error(e));else{t=t.replace(/\+/g,"%20");let o=document.querySelector("#search-input");o.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"),i=e.get("imdb");if(t||i){let s=document.getElementsByClassName("information");for(let r=0;r<s.length;r++)s[r].style.display="none"}else{let l=document.getElementsByClassName("information");for(let o=0;o<l.length;o++)l[o].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"}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"))});const PLAYER_CONFIG={iframeId:"iframe",videoContainerId:"video",embedMovieUrl:e=>`https://vidsrc.su/embed/movie/${e}`,embedTvUrl:(e,t,i)=>`https://vidsrc.su/embed/tv/${e}/${t}/${i}`};async function fetchTmdbIdFromImdb(e){let t=`https://api.themoviedb.org/3/find/${e}?api_key=b6b677eb7d4ec17f700e3d4dfc31d005&language=en-US&external_source=imdb_id`;try{let i=await fetch(t),s=await i.json();return s.movie_results&&s.movie_results[0]?s.movie_results[0].id:null}catch(r){return console.error("Failed to fetch TMDB ID:",r),null}}async function fetchTmdbTvIdFromImdb(e){let t=`https://api.themoviedb.org/3/find/${e}?api_key=b6b677eb7d4ec17f700e3d4dfc31d005&language=en-US&external_source=imdb_id`;try{let i=await fetch(t),s=await i.json();return s.tv_results&&s.tv_results[0]?s.tv_results[0].id:null}catch(r){return console.error("Failed to fetch TMDB ID for TV show:",r),null}}async function setAll(e,t,i,s,r){if(e&&t&&!i&&!s&&r){let l=await fetchTmdbIdFromImdb(e);if(!l){alert("Could not find TMDB ID for this movie.");return}let o=document.createElement("a");o.setAttribute("onClick","setUrl(this); return setVideo(this);"),o.setAttribute("url",`imdb=${e}&type=movie&title=${t.replace(/ /g,"_")}`),o.setAttribute("isWebSeries","false"),o.setAttribute("title",t),o.setAttribute("class","links"),o.setAttribute("IMDB",e),o.setAttribute("href",PLAYER_CONFIG.embedMovieUrl(l)),o.setAttribute("target","_blank"),o.click()}else if(e&&t&&s&&!r){let n=await fetchTmdbTvIdFromImdb(e);if(!n){alert("Could not find TMDB ID for this TV show.");return}let a=document.createElement("a");a.setAttribute("onClick","setUrl(this); return setVideo(this);"),console.log("season setall",i,"episode",s),a.setAttribute("url",`imdb=${e}&season=${i}&episode=${s}`),a.setAttribute("isWebSeries","true"),a.setAttribute("title",t),a.setAttribute("class","links"),a.setAttribute("IMDB",e),a.setAttribute("href",PLAYER_CONFIG.embedTvUrl(n,i,s)),a.setAttribute("target","_blank"),a.click()}}function setVideo(e){let t=document.getElementById(PLAYER_CONFIG.iframeId),i=document.getElementById(PLAYER_CONFIG.videoContainerId);t.removeAttribute("sandbox"),t.src=e.getAttribute("href"),i.style.display="block";let s=document.getElementById("webSeriesData"),r="b6b677eb7d4ec17f700e3d4dfc31d005",l=e.getAttribute("IMDB");if(Pace.restart(),scrollToTop(),window.dispatchEvent(new PopStateEvent("popstate")),"false"==e.getAttribute("isWebSeries")&&"links"==e.className&&(s.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 o(){let e=await fetch(`https://api.themoviedb.org/3/find/${l}?api_key=${r}&language=en-US&external_source=imdb_id`),t=await e.json(),i=t.tv_results[0].id,o=await fetch(`https://api.themoviedb.org/3/tv/${i}?api_key=${r}&language=en-US`),n=await o.json(),a=n.number_of_seasons;s.innerHTML+="<h2>Seasons:</h2>";for(let c=1;c<=a;c++){s.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/${i}/season/${c}?api_key=${r}&language=en-US`),m=await h.json();for(let p of m.episodes){let f=p.episode_number,b=f.toLocaleString("en-US",{minimumIntegerDigits:2,useGrouping:!1});u+=`<a class="episodes" title="${n.name+": E"+b+". "+p.name}" cssidentification="s${c}e${f}" url="imdb=${l}&season=${c}&episode=${f}&title=${n.name.replace(/ /g,"_")+"_E"+b+"_"+p.name.replace(/ /g,"_")}" onClick="event.preventDefault();setVideo(this);setUrl(this); " href="${PLAYER_CONFIG.embedTvUrl(i,c,f)}">E${b}. ${p.name}</a>`}d.innerHTML=u,s.appendChild(d),episodeHighlight()}let g=new URLSearchParams(window.location.search),v=g.get("season"),y=g.get("episode");v&&y?document.querySelector(`a[cssIdentification="s${v}e${y}"]`).click():v&&!y?document.querySelector(`a[cssIdentification="s${v}e1"]`).click():document.querySelector('a[cssIdentification="s1e1"]').click()}s.innerHTML="",o()}function n(){dataLayer.push(arguments)}return window.dataLayer=window.dataLayer||[],n("js",new Date),n("config","G-THTQ9GZQ0J"),highlightCards(),!1}