`;
}
}
// Function to insert or replace the button
function insertOrReplaceButton() {
if (window.location.hostname === 'www.themoviedb.org') {
insertTMDBButton();
} else if (window.location.hostname === 'www.imdb.com') {
insertIMDbButton();
}
}
// Function to insert button for TMDB
function insertTMDBButton() {
const posterWrapper = document.querySelector('.poster_wrapper');
if (posterWrapper) {
let ottOffer = posterWrapper.querySelector('.ott_offer');
if (!ottOffer) {
ottOffer = document.createElement('div');
ottOffer.className = 'ott_offer';
posterWrapper.insertBefore(ottOffer, posterWrapper.firstChild);
} else {
const existingLink = ottOffer.querySelector('a');
if (existingLink) {
existingLink.removeAttribute('href');
existingLink.style.cursor = 'pointer';
}
}
ottOffer.innerHTML = createWatchNowButtonContent(false);
const oldElement = ottOffer;
const newElement = oldElement.cloneNode(true);
oldElement.parentNode.replaceChild(newElement, oldElement);
newElement.addEventListener('click', showModal);
newElement.style.position = 'relative';
newElement.style.zIndex = '10';
newElement.style.marginBottom = '10px';
newElement.style.cursor = 'pointer';
}
}
// Function to insert button for IMDb
function insertIMDbButton() {
const titleElement = document.querySelector('.hero__primary-text');
if (titleElement) {
const watchNowButton = document.createElement('span');
watchNowButton.innerHTML = createWatchNowButtonContent(true);
watchNowButton.style.display = 'inline-block';
watchNowButton.style.verticalAlign = 'middle';
titleElement.insertAdjacentElement('afterend', watchNowButton);
watchNowButton.querySelector('button').addEventListener('click', showModal);
}
}
// Function to get ID (TMDB or IMDb)
function getId() {
if (window.location.hostname === 'www.themoviedb.org') {
const match = window.location.pathname.match(/\/(movie|tv)\/(\d+)/);
return match ? match[2] : null;
} else if (window.location.hostname === 'www.imdb.com') {
const match = window.location.pathname.match(/\/title\/(tt\d+)/);
return match ? match[1] : null;
}
return null;
}
// Function to determine if it's a movie or TV show
function getContentType() {
console.log("Starting getContentType function");
console.log("Current URL:", window.location.href);
console.log("Document title:", document.title);
if (window.location.hostname === 'www.themoviedb.org') {
console.log("Detected TMDB");
const isMovie = window.location.pathname.includes('/movie/');
console.log("Is movie path:", isMovie);
return isMovie ? 'movie' : 'tv';
} else if (window.location.hostname === 'www.imdb.com') {
console.log("Detected IMDb");
const title = document.title;
console.log("Full title:", title);
const isSeries = title.includes("Series");
console.log("Title includes 'Series':", isSeries);
return isSeries ? 'tv' : 'movie';
}
console.log("Unknown website");
return null;
}
// Test the function
const result = getContentType();
console.log("Final result:", result);
// Function to show modal
function showModal() {
const id = getId();
const contentType = getContentType();
let baseUrl;
// Set baseUrl based on the contentType
if (contentType === 'tv') {
baseUrl = 'https://vidsrc.me/embed/';
} else {
baseUrl = 'https://vidsrc.xyz/embed/';
}
if (id) {
const isIMDb = window.location.hostname === 'www.imdb.com';
const idParam = isIMDb ? id : `${contentType}?tmdb=${id}`;
iframe.src = `${baseUrl}${idParam}`;
modal.style.display = 'block';
}
}
// Function to initialize the script
function init() {
insertOrReplaceButton();
}
// Use a MutationObserver to detect when the relevant elements are added to the DOM
const observer = new MutationObserver((mutations, obs) => {
const relevantElement = window.location.hostname === 'www.themoviedb.org'
? document.querySelector('.poster_wrapper')
: document.querySelector('.hero__primary-text');
if (relevantElement) {
init();
obs.disconnect(); // Stop observing once we've found and modified the relevant element
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
// Close modal on close button click
closeButton.addEventListener('click', () => {
modal.style.display = 'none';
iframe.src = ''; // Clear the iframe source when closing
});
// Close modal when clicking outside of it
modal.addEventListener('click', (event) => {
if (event.target === modal) {
modal.style.display = 'none';
iframe.src = ''; // Clear the iframe source when closing
}
});
})();