Welcome to Scribe

The latest in tech, science, personal growth, business and travel curated for you daily.

featured article

test

Latest articles

Receive the latest articles in your inbox

Insert your email signup form below

[insert e-mail subscription form]

document.addEventListener("DOMContentLoaded", function () { const container = document.querySelector(".video-container"); const heading = document.getElementById("dynamic-heading"); const API_KEY = "AIzaSyCX2TTKcjQ83YSiXcee2rdrAbKPTfeTGo8"; const defaultCountry = "US"; // Default to United States const categories = ["Music", "Gaming", "News", "Entertainment"]; // Add more as needed const countries = ["US", "IN", "BR", "RU", "GB"]; // Add the top 50 YouTube user countries const maxResults = 9; // Adjust as needed function fetchVideos(country = defaultCountry, category = "Entertainment") { let categoryEncoded = encodeURIComponent(category); let url = `https://www.googleapis.com/youtube/v3/videos?part=snippet,statistics&chart=mostPopular®ionCode=${country}&maxResults=${maxResults}&key=${API_KEY}`; heading.innerHTML = `Most Viewed ${category} YouTube Video in the Last 24 Hours in ${country}`; fetch(url) .then((response) => response.json()) .then((data) => { container.innerHTML = ""; if (data.items.length === 0) { container.innerHTML = "

No videos found.

"; return; } data.items.forEach((video, index) => { let videoId = video.id; let videoTitle = video.snippet.title; let videoUrl = `https://www.youtube.com/watch?v=${videoId}`; let channelTitle = video.snippet.channelTitle; let viewCount = video.statistics.viewCount; let categoryLink = `/most-viewed-${categoryEncoded}-videos-${country}/`; let videoCard = `

${videoTitle}

Channel: ${channelTitle}

Views: ${new Intl.NumberFormat().format(viewCount)}

More ${category} videos from ${country}
`; container.innerHTML += videoCard; // Ad slot after every 3 videos if ((index + 1) % 3 === 0) { container.innerHTML += `

Advertisement

`; } }); }) .catch((error) => console.error("Error fetching videos:", error)); } // Fetch videos for default country and category on load fetchVideos(); });