-
Notifications
You must be signed in to change notification settings - Fork 89
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
8031f6c
commit ae0399e
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,39 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Random Rick and Morty Character</title> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet"> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
padding: 20px; | ||
background-image: url('Rick-And-Morty.jpeg'); | ||
background-size: cover; | ||
background-position: center; | ||
min-height: 100vh; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
img { | ||
max-width: 100%; | ||
height: auto; | ||
margin-bottom: 10px; | ||
} | ||
.text-black { | ||
color: black; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="text-black"> | ||
<h1 class="text-3xl font-bold mb-4">Random Rick and Morty Character</h1> | ||
<button id="generateButton" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded">Generate Character</button> | ||
<div id="characterInfo" class="mt-4"></div> | ||
</div> | ||
|
||
<script src="script.js"></script> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,12 @@ | ||
{ | ||
"name": "Rick and Morty", | ||
"version": "0.0.1", | ||
"manifest_version": 2, | ||
"browser_action": { | ||
"default_popup": "index.html", | ||
"default_icon": "logo.png" | ||
}, | ||
"icons": { | ||
"128": "logo.png" | ||
} | ||
} |
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,30 @@ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
const generateButton = document.getElementById('generateButton'); | ||
const characterInfo = document.getElementById('characterInfo'); | ||
|
||
generateButton.addEventListener('click', async function() { | ||
const randomId = Math.floor(Math.random() * 826) + 1; | ||
const apiUrl = `https://rickandmortyapi.com/api/character/${randomId}`; | ||
|
||
try { | ||
const response = await fetch(apiUrl); | ||
const data = await response.json(); | ||
|
||
const characterName = data.name; | ||
const characterImage = data.image; | ||
|
||
const characterElement = document.createElement('div'); | ||
characterElement.innerHTML = ` | ||
<h2>${characterName}</h2> | ||
<img src="${characterImage}" alt="${characterName}"> | ||
`; | ||
|
||
characterInfo.innerHTML = ''; | ||
characterInfo.appendChild(characterElement); | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
characterInfo.innerHTML = '<p>Failed to fetch character data.</p>'; | ||
} | ||
}); | ||
}); | ||
|