-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from yatikakain/youtube-context-feature
[Feature] Implemented "Generate Quiz from YouTube Video" Context Menu
- Loading branch information
Showing
3 changed files
with
144 additions
and
23 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Function to extract YouTube video ID from the URL | ||
function getYouTubeVideoId() { | ||
const urlParams = new URLSearchParams(window.location.search); | ||
return urlParams.get("v"); | ||
} | ||
|
||
(() => { | ||
const videoId = getYouTubeVideoId(); | ||
|
||
if (videoId) { | ||
console.log("Extracted YouTube Video ID:", videoId); | ||
|
||
fetch(`http://localhost:5000/getTranscript?videoId=${videoId}`) | ||
.then(response => response.json()) | ||
.then(data => { | ||
if (data.transcript) { | ||
console.log("Transcript received:", data.transcript); | ||
chrome.storage.local.set({ videoTranscript: data.transcript }, () => { | ||
console.log("Transcript saved in storage."); | ||
}); | ||
generateQuestions(data.transcript); | ||
} else { | ||
console.error("Failed to fetch transcript:", data.error); | ||
} | ||
}) | ||
.catch(error => { | ||
console.error("Error fetching transcript:", error); | ||
}); | ||
} | ||
})(); | ||
|
||
// Function to generate quiz questions from transcript | ||
function generateQuestions(transcript) { | ||
console.log("Generating questions from transcript..."); | ||
chrome.storage.local.set({ "selectedText": transcript }, () => { | ||
console.log("Transcript stored for quiz generation."); | ||
}); | ||
} |