Skip to content

Instantly share code, notes, and snippets.

@dvygolov
Created October 17, 2024 08:22
Show Gist options
  • Save dvygolov/b9e3aca6424b8553d1390f9e5c25beed to your computer and use it in GitHub Desktop.
Save dvygolov/b9e3aca6424b8553d1390f9e5c25beed to your computer and use it in GitHub Desktop.

Revisions

  1. dvygolov created this gist Oct 17, 2024.
    19 changes: 19 additions & 0 deletions youtubevideoslist.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    // 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);