Skip to content

Commit

Permalink
Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
swapnilsparsh committed May 2, 2022
1 parent f42acfe commit 6c7d3a1
Show file tree
Hide file tree
Showing 187 changed files with 2,879 additions and 2,835 deletions.
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

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.
23 changes: 0 additions & 23 deletions 116 - Places under a Postal Code/index.html

This file was deleted.

44 changes: 0 additions & 44 deletions 116 - Places under a Postal Code/index.js

This file was deleted.

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.
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 124- Lyrics Search App/script.js → 124 - Lyrics Search App/script.js
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)
}
});
Loading

0 comments on commit 6c7d3a1

Please sign in to comment.