function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split("="); if (pair[0] === variable) { return decodeURIComponent(pair[1]); } } return null; } function isYouTubeUrl(url) { return (url.includes('youtube.com') || url.includes('youtu.be')); } function getYouTubeVideoId(url) { var video_id = null; if (url.includes('youtube.com')) { var urlParams = new URLSearchParams(new URL(url).search); video_id = urlParams.get('v'); } else if (url.includes('youtu.be')) { video_id = url.split('/').pop(); } return video_id; } window.onload = function() { var keyword = getQueryVariable("query"); var iframe_url = ""; if (keyword) { if (isYouTubeUrl(keyword)) { var video_id = getYouTubeVideoId(keyword); if (video_id) { iframe_url = "https://www.y2mate.com/youtube/" + video_id; //iframe_url = "https://y2mate.tube/convert/?videoId=" + video_id; //iframe_url = "https://y2mate.city/?query=" + keyword; } } else { iframe_url = "https://www.y2mate.com/search/" + encodeURIComponent(keyword); //iframe_url = "https://y2mate.tube/search/" + encodeURIComponent(keyword); //iframe_url = "https://y2mate.city/?video=" + encodeURIComponent(keyword); } document.getElementById("main-iframe").src = iframe_url; } else { iframe_url = "https://y2mate.city/"; document.getElementById("main-iframe").src = iframe_url; } }