forked from swapnilsparsh/30DaysOfJavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f42acfe
commit 6c7d3a1
Showing
187 changed files
with
2,879 additions
and
2,835 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
48 changes: 24 additions & 24 deletions
48
124- Lyrics Search App/index.html → 124 - Lyrics Search App/index.html
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 |
---|---|---|
@@ -1,25 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="uts-8"> | ||
<title>OLX Clone</title> | ||
<link rel="stylesheet" href="style.css"> | ||
<meta name="viewport" content="width-device=width,initial-scale=1"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css"> | ||
</head> | ||
<body> | ||
<header> | ||
<h1>Lyrics Search App</h1> | ||
<form id="form"> | ||
<input type="text" id="search" placeholder="enter song name..."> | ||
<button>Search</button> | ||
</form> | ||
</header> | ||
<div id="result" class="container"> | ||
<p>Result will be displayed here</p> | ||
</div> | ||
<div id="more" class="container centered"></div> | ||
|
||
<script src="script.js"></script> | ||
</body> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="uts-8"> | ||
<title>OLX Clone</title> | ||
<link rel="stylesheet" href="style.css"> | ||
<meta name="viewport" content="width-device=width,initial-scale=1"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css"> | ||
</head> | ||
<body> | ||
<header> | ||
<h1>Lyrics Search App</h1> | ||
<form id="form"> | ||
<input type="text" id="search" placeholder="enter song name..."> | ||
<button>Search</button> | ||
</form> | ||
</header> | ||
<div id="result" class="container"> | ||
<p>Result will be displayed here</p> | ||
</div> | ||
<div id="more" class="container centered"></div> | ||
|
||
<script src="script.js"></script> | ||
</body> | ||
</html> |
File renamed without changes
182 changes: 91 additions & 91 deletions
182
124- Lyrics Search App/script.js → 124 - Lyrics Search App/script.js
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 |
---|---|---|
@@ -1,92 +1,92 @@ | ||
const from = document.getElementById("form"); | ||
const search = document.getElementById("search"); | ||
const result = document.getElementById("result"); | ||
const more = document.getElementById("more"); | ||
|
||
const apiURL = "https://api.lyrics.ovh"; | ||
|
||
async function searchSongs(term) { | ||
const res = await fetch(`${apiURL}/suggest/${term}`); | ||
const data = await res.json(); | ||
|
||
showData(data); | ||
} | ||
|
||
function showData(data) { | ||
result.innerHTML = ` | ||
<ul class="songs"> | ||
${data.data | ||
.map( | ||
(song) => `<li> | ||
<span><strong>${song.artist.name}</strong> - ${song.title}</span> | ||
<button class="btn" data-artist="${song.artist.name}" data-songtitle="${song.title}">Get Lyrics</button> | ||
</li>` | ||
) | ||
.join("")} | ||
</ul> | ||
`; | ||
if (data.prev || data.next) { | ||
more.innerHTML = ` | ||
${ | ||
data.prev | ||
? `<button class="btn" "onclick="getMoreSongs('${data.prev}')">Prev</button>` | ||
: "" | ||
} | ||
${ | ||
data.next | ||
? `<button class="btn" onclick="getMoreSongs('${data.next}')">Next</button>` | ||
: "" | ||
} | ||
`; | ||
} else { | ||
more.innerHTML = ""; | ||
} | ||
} | ||
|
||
async function getMoreSongs(url) { | ||
const res = await fetch(`https://cors-anywhere.herokuapp.com/${url}`); | ||
const data = await res.json(); | ||
|
||
showData(data); | ||
} | ||
|
||
async function getLyrics(artist, songTitle) { | ||
const res = await fetch(`${apiURL}/v1/${artist}/${songTitle}`); | ||
const data = await res.json(); | ||
|
||
if (data.error) { | ||
result.innerHTML = data.error; | ||
} else { | ||
const lyrics = data.lyrics.replace(/(\r\n|\r|\n)/g, "<br>"); | ||
|
||
result.innerHTML = ` | ||
<h2><strong>${artist}</strong> - ${songTitle}</h2> | ||
<span>${lyrics}</span> | ||
`; | ||
} | ||
|
||
more.innerHTML = ""; | ||
} | ||
|
||
form.addEventListener("submit", (e) => { | ||
e.preventDefault(); | ||
|
||
const searchTerm = search.value.trim(); | ||
|
||
if (!searchTerm) { | ||
alert("Please type in a search term"); | ||
} else { | ||
searchSongs(searchTerm); | ||
} | ||
}); | ||
|
||
// Get lyrics button click | ||
result.addEventListener("click", (e) => { | ||
const clickedEl = e.target; | ||
if (clickedEl.tagName === "BUTTON") { | ||
const artist = clickedEl.getAttribute("data-artist"); | ||
const songTitle = clickedEl.getAttribute("data-songtitle"); | ||
|
||
getLyrics(artist, songTitle) | ||
} | ||
const from = document.getElementById("form"); | ||
const search = document.getElementById("search"); | ||
const result = document.getElementById("result"); | ||
const more = document.getElementById("more"); | ||
|
||
const apiURL = "https://api.lyrics.ovh"; | ||
|
||
async function searchSongs(term) { | ||
const res = await fetch(`${apiURL}/suggest/${term}`); | ||
const data = await res.json(); | ||
|
||
showData(data); | ||
} | ||
|
||
function showData(data) { | ||
result.innerHTML = ` | ||
<ul class="songs"> | ||
${data.data | ||
.map( | ||
(song) => `<li> | ||
<span><strong>${song.artist.name}</strong> - ${song.title}</span> | ||
<button class="btn" data-artist="${song.artist.name}" data-songtitle="${song.title}">Get Lyrics</button> | ||
</li>` | ||
) | ||
.join("")} | ||
</ul> | ||
`; | ||
if (data.prev || data.next) { | ||
more.innerHTML = ` | ||
${ | ||
data.prev | ||
? `<button class="btn" "onclick="getMoreSongs('${data.prev}')">Prev</button>` | ||
: "" | ||
} | ||
${ | ||
data.next | ||
? `<button class="btn" onclick="getMoreSongs('${data.next}')">Next</button>` | ||
: "" | ||
} | ||
`; | ||
} else { | ||
more.innerHTML = ""; | ||
} | ||
} | ||
|
||
async function getMoreSongs(url) { | ||
const res = await fetch(`https://cors-anywhere.herokuapp.com/${url}`); | ||
const data = await res.json(); | ||
|
||
showData(data); | ||
} | ||
|
||
async function getLyrics(artist, songTitle) { | ||
const res = await fetch(`${apiURL}/v1/${artist}/${songTitle}`); | ||
const data = await res.json(); | ||
|
||
if (data.error) { | ||
result.innerHTML = data.error; | ||
} else { | ||
const lyrics = data.lyrics.replace(/(\r\n|\r|\n)/g, "<br>"); | ||
|
||
result.innerHTML = ` | ||
<h2><strong>${artist}</strong> - ${songTitle}</h2> | ||
<span>${lyrics}</span> | ||
`; | ||
} | ||
|
||
more.innerHTML = ""; | ||
} | ||
|
||
form.addEventListener("submit", (e) => { | ||
e.preventDefault(); | ||
|
||
const searchTerm = search.value.trim(); | ||
|
||
if (!searchTerm) { | ||
alert("Please type in a search term"); | ||
} else { | ||
searchSongs(searchTerm); | ||
} | ||
}); | ||
|
||
// Get lyrics button click | ||
result.addEventListener("click", (e) => { | ||
const clickedEl = e.target; | ||
if (clickedEl.tagName === "BUTTON") { | ||
const artist = clickedEl.getAttribute("data-artist"); | ||
const songTitle = clickedEl.getAttribute("data-songtitle"); | ||
|
||
getLyrics(artist, songTitle) | ||
} | ||
}); |
Oops, something went wrong.