Skip to content

Commit

Permalink
feat: grab thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
san1234100 committed Feb 27, 2024
0 parents commit f7ff0f5
Show file tree
Hide file tree
Showing 9 changed files with 2,353 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
3 changes: 3 additions & 0 deletions assets/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
28 changes: 28 additions & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const youtubeLinkEl = document.getElementById('youtubeLink')
const youtubeThumbnailEl = document.getElementById('youtubeThumbnail')
const btnEl = document.querySelector('button')
console.log(youtubeLinkEl,youtubeThumbnailEl,btnEl);

btnEl.addEventListener('click',getThumbnail)

function getThumbnail() {
let youtubeLink = youtubeLinkEl.value;
let videoId = getYoutubeVideoId(youtubeLink);
if (videoId) {
let thumbnailUrl = 'https://img.youtube.com/vi/' + videoId + '/maxresdefault.jpg';
console.log(thumbnailUrl);
youtubeThumbnailEl.innerHTML = '<img src="' + thumbnailUrl + '">';
} else {
alert('Invalid YouTube Link');
}
}

function getYoutubeVideoId(url) {
let regExp = /^.*(youtu\.be\/|v\/|e\/|u\/\w+\/|embed\/|v=)([^#\&\?]*).*/;
let match = url.match(regExp);
if (match && match[2].length == 11) {
return match[2];
} else {
return null;
}
}
27 changes: 27 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Youtube thumbnail grabber App</title>
<link rel="stylesheet" href="assets/css/main.css">
</head>
<body class="bg-[#030637]">
<header class="text-white p-5">
<h1 class="text-2xl font-semibold">YoutubeThumbGrab</h1>
</header>
<div class="bg-[#3C0753] max-w-2xl text-white p-5 mx-auto mt-10 rounded h-fit">
<div class="font-semibold text-lg">Paste the youtube link here</div>
<input
type="url"
id="youtubeLink"
name="url"
class="w-full px-4 py-2 rounded mt-3 text-[#720455] bg-gray-200 outline-none">
<button class="w-full mt-3 py-2 bg-[#720455] rounded font-medium hover:bg-[#61084a]">Grab the thumbnail</button>
<div class="mt-5 rounded" id="youtubeThumbnail"></div>
</div>

<script type="module" src="/assets/js/main.js"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import './style.css'
import javascriptLogo from './javascript.svg'
import viteLogo from '/vite.svg'
import { setupCounter } from './counter.js'

document.querySelector('#app').innerHTML = `
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="${viteLogo}" class="logo" alt="Vite logo" />
</a>
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" target="_blank">
<img src="${javascriptLogo}" class="logo vanilla" alt="JavaScript logo" />
</a>
<h1>Hello Vite!</h1>
<div class="card">
<button id="counter" type="button"></button>
</div>
<p class="read-the-docs">
Click on the Vite logo to learn more
</p>
</div>
`

setupCounter(document.querySelector('#counter'))
Loading

0 comments on commit f7ff0f5

Please sign in to comment.