Created
October 17, 2024 08:22
-
-
Save dvygolov/b9e3aca6424b8553d1390f9e5c25beed to your computer and use it in GitHub Desktop.
This script prompts for the number of videos to process and then console.logs all the video titles found
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get all video elements on the page | |
const videoElements = document.querySelectorAll('a#video-title-link'); | |
// Ask user for the number of videos to process | |
const numberOfVideos = parseInt(prompt("How many videos do you want to process?"), 10); | |
// Initialize an empty string to store all video lines | |
let videoList = ''; | |
// Process the required number of video titles | |
for (let i = 0; i < Math.min(numberOfVideos, videoElements.length); i++) { | |
const video = videoElements[i]; | |
const title = video.getAttribute('title'); | |
const link = 'https://youtube.com' + video.getAttribute('href'); | |
videoList += `${i + 1}. <a href="${link}">${title}</a>\n`; | |
} | |
// Log the entire list in a single console.log | |
console.log(videoList); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment