๐๋ ธ๋ง๋์ฝ๋ ํฌ๋กฌ์ฑ ๋ง๋ค๊ธฐ๐
๐๋
ธ๋ง๋์ฝ๋ ํฌ๋กฌ์ฑ ๋ง๋ค๊ธฐ๐
๐๊ณ๊ธฐ
์น๊ตฌ์ ํ ์ดํ๋ก์ ํธ๋ฅผ ๊ฐ๋ณ๊ฒ ์งํ์ค์ธ๋ฐ, ํ๋ก ํธ์๋์ ์คํ์ ๋ฆฌ์กํธ๋ก ์ฌ์ฉํด์ผ๊ฒ ๋ค~ ๊ฒฐ์ ํ์ง๋ง ์น์ ์ ๋ง ์ฒ์์ด๋ผโฆ ๊ธฐ์ด๋ ํ๊ณ ๊ฐ์ผ๊ฒ ๋ค๋ ์๊ฐ์ด ๋ค์์ต๋๋ค๐
๋ฐ๋ก ๋ฆฌ์กํธ๋ฅผ ๊ณต๋ถํ๋ฉด์ ํด๋ดค๋๋ฐ, ๊ตฌ๋ฆ์์์ ์ฝ๋ฉํ๋ ๋ฏ์ด(โฆ) ๋ญ๊ฐ๋ญ์ง ์ ๋ชจ๋ฅด๊ฒ ์ด์ ์ฐจ๊ทผ์ฐจ๊ทผ ํ๋ ๊ฒ์ ๋ํ ์ค์์ฑ์ ๊นจ๋ฌ์์ต๋๋ค๐คฃ
ํด์ ์ ํํ ๊ฒ์ด ๋
ธ๋ง๋์ฝ๋ ํฌ๋กฌ์ฑ ๊ฐ์! ์๋๋ฐ, ๋ค์ด๋ณด๋๊น ํ์คํ ๋ญ ์ด๋ป๊ฒ ํด์ผํ ์ง ๊ฐ์ด ์กํ๋ ๋๋์ด์๋ค์!๐๐
์ด์ ๋ฐ๋๋ผ ์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ์ด์ฉํด ํ ์ดํ๋ก์ ํธ 2๊ฐ ์ ๋๋ฅผ ์ง์ ์งํํด๋ณด๊ณ ๋ฆฌ์กํธ๋ก ๋์ด๊ฐ๋ คํฉ๋๋ค.
๐์ฝ๋
๐ index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/style.css" />
<title>Momentum App</title>
</head>
<body>
<div id="weather">
<span class="weat"></span>
<span class="home"></span>
</div>
<h2 id="clock">00:00:00</h2>
<form class="hidden" id="login-form">
<input
required
maxlength="15"
type="text"
placeholder="What is your name?"
/>
<button>Log In</button>
</form>
<h1 id="greeting" class="hidden"></h1>
<form id="todo-form">
<input type="text" placeholder="Write a To Do" required />
</form>
<ul id="todo-list"></ul>
<div id="quote">
<span></span><br />
<span></span>
</div>
<script src="js/greetings.js"></script>
<script src="js/clock.js"></script>
<script src="js/quotes.js"></script>
<script src="js/background.js"></script>
<script src="js/todo.js"></script>
<script src="js/secret.js"></script>
<script src="js/weather.js"></script>
</body>
</html>
๐ greeting.js
const loginForm = document.querySelector("#login-form");
const loginInput = document.querySelector("#login-form input");
const greeting = document.querySelector("#greeting");
const HIDDEN_CLASSNAME = "hidden";
const USERNAME_KEY = "username";
function onLoginSubmit(event) {
event.preventDefault();
loginForm.classList.add(HIDDEN_CLASSNAME);
localStorage.setItem(USERNAME_KEY, loginInput.value);
paintGreetings();
}
function paintGreetings() {
const username = localStorage.getItem(USERNAME_KEY);
greeting.innerText = `Hello ${username}`;
greeting.classList.remove(HIDDEN_CLASSNAME);
}
const savedUsername = localStorage.getItem(USERNAME_KEY);
console.log(savedUsername);
if (savedUsername === null) {
loginForm.classList.remove(HIDDEN_CLASSNAME);
loginForm.addEventListener("submit", onLoginSubmit);
} else {
paintGreetings();
}
๐ quotes.js
const quotes = [
{
quote: "I never dreamed about success, I worked for it.",
author: "Estee Lauder",
},
{
quote: "Do not try to be original, just try to be good.",
author: "Paul Rand",
},
{
quote: "Do not be afraid to give up the good to go for the great.",
author: "John D. Rockefeller",
},
{
quote:
"If you cannot fly then run. If you cannot run, then walk. And, if you cannot walk, then crawl, but whatever you do, you have to keep moving forward.",
author: "Martin Luther King Jr.",
},
{
quote:
"Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.",
author: "Thomas Edison",
},
{
quote:
"The fastest way to change yourself is to hang out with people who are already the way you want to be.",
author: "Reid Hoffman",
},
{
quote:
"Money is like gasoline during a road trip. You do not want to run out of gas on your trip, but you 're not doing a tour of gas stations.",
author: "Tim O'Reilly",
},
{
quote:
"Some people dream of success, while other people get up every morning and make it happen.",
author: "Wayne Huizenga",
},
{
quote:
"The only thing worse than starting something and failing ... is not starting something.",
author: "Seth Godin",
},
{
quote:
"If you really want to do something, you'll find a way. If you do not, you'll find an excuse.",
author: "Jim Rohn",
},
];
const quote = document.querySelector("#quote span:first-child");
const author = document.querySelector("#quote span:last-child");
const todaysQuote = quotes[Math.floor(Math.random() * quotes.length)];
quote.innerText = todaysQuote.quote;
author.innerText = todaysQuote.author;
๐ background.js
const images = ["0.jpg", "1.jpg", "2.jpg", "3.jpg"];
const chosenImage = images[Math.floor(Math.random() * images.length)];
const bgImage = document.createElement("img");
bgImage.src = `img/${chosenImage}`;
bgImage.classList.add("bgImage");
document.body.appendChild(bgImage);
๐ todo.js
const toDoForm = document.querySelector("#todo-form");
const toDoInput = toDoForm.querySelector("input"); //document.querySelector("#todo-iform input");
const toDoList = document.querySelector("#todo-list");
const TODOS_KEY = "todos";
let toDos = [];
function saveToDos() {
localStorage.setItem(TODOS_KEY, JSON.stringify(toDos));
}
function deleteToDo(event) {
const li = event.target.parentElement;
li.remove();
toDos = toDos.filter((toDo) => toDo.id !== parseInt(li.id));
saveToDos();
}
function paintToDo(newTodo) {
const li = document.createElement("li");
li.id = newTodo.id;
const span = document.createElement("span");
span.innerText = newTodo.text;
const button = document.createElement("button");
button.innerText = "โ";
button.addEventListener("click", deleteToDo);
li.appendChild(span);
li.appendChild(button);
toDoList.appendChild(li);
}
function handleToDoSubmit(event) {
event.preventDefault();
const newTodo = toDoInput.value;
toDoInput.value = "";
const newTodoObj = {
text: newTodo,
id: Date.now(),
};
toDos.push(newTodoObj);
paintToDo(newTodoObj);
saveToDos();
}
toDoForm.addEventListener("submit", handleToDoSubmit);
const savedToDos = localStorage.getItem(TODOS_KEY);
if (savedToDos) {
const parsedToDos = JSON.parse(savedToDos);
toDos = parsedToDos;
parsedToDos.forEach(paintToDo);
}
๐ weather.js
function onGeoOk(position) {
const lat = position.coords.latitude;
const lon = position.coords.longitude;
console.log("You live it", lat, lon);
const url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${API_KEY}&units=metric`;
fetch(url)
.then((response) => response.json())
.then((data) => {
const weather = document.querySelector("#weather span:first-child");
const city = document.querySelector("#weather span:last-child");
city.innerText = data.name;
weather.innerText = data.weather[0].main;
});
}
function onGeoError() {
alert("Can't find you. No weather for you.");
}
navigator.geolocation.getCurrentPosition(onGeoOk, onGeoError);
๐ style.css
.hidden {
display: none;
}
body {
background-color: #2d3436;
text-align: center;
color: #ecf0f1;
padding: 1%;
}
h2 {
font-size: 5rem;
margin-top: 8%;
}
h1 {
font-size: 3rem;
font-style: italic;
}
input {
border: none;
background: transparent;
font-size: 20px;
margin: 3px;
text-align: center;
color: #ecf0f1;
border-bottom: 2px solid #ecf0f1;
}
button {
border: none;
background: transparent;
font-size: 22px;
}
ul {
margin-left: 42%;
}
li {
list-style: none;
font-size: 20px;
text-align: left;
color: #ecf0f1;
}
li:before {
content: "๐";
display: inline;
vertical-align: left;
padding: 5px;
}
.bgImage {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
animation: fadeIn 0.5s linear;
}
.weat {
padding-left: 90%;
}
.home {
padding-left: 90%;
}
๐์์ฑ
์์ฉ๋๋ค!
๐ํ๊ธฐ
๊ฐ์๋ฅผ ๋ค์ผ๋ฉด์ ๋ ๊น๊ฒ ๊ณต๋ถํด์ผํ ๊ฒ์ด๋, ์ค์ํ๋ค๊ณ ์๊ฐ์ด ๋๋ ๋ถ๋ถ์ ๋ฐ๋ก ๋ฉ๋ชจ๋ฅผํ์ต๋๋ค.
๋๋ฌด ์ฃผ์ ์ฃผ์ ์ ๋ง ์์ ๋ณผ ์ ์๊ฒ ์ ๋ฆฌํด์ ๋ฐ๋ก ์
๋ก๋ ํ๊ธด ์ด๋ ต๊ฒ ์ง๋ง ์ฒ์ฒํ ๋ณต์ตํ๊ณ ์์๊ฒ ํฌ์คํ
ํด๋ณผ ์๊ฐ์
๋๋ค.
์๊ฐ๋ณด๋ค ๋๋ฌด ์ฌ๋ฐ๋ ๊ฐ์์๊ณ , HTML CSS JS ๋ชจ๋ ์ฒ์์ด๊ธด ํ์ง๋ง ๋ฆฌ์กํธ๋ฅผ ๋ง์ง๋ฉด์ ๋~์ถฉ ์๊ณ ์๋ ๊ฒ์ด ์์ด์ ๊ทธ๋ฐ๊ฐ ์ด๋ ค์์ ๋ค์๋ค์ด๋ณด๊ฑฐ๋ ํ๋ ๊ฑด ์์์ด์!
์ด์ ๊ฐ์์์ ๋ฐฐ์ด ๊ฒ์ ํ ๋๋ก ์๋ก์ด ์น ์ฑ์ ์ ์ํด๋ณผ ์๊ฐ์ ๋๋ค!
- ํ๋ฃจ ํ ์ค ์ผ๊ธฐ
- ๋๋ง์ ๋์ง ํ์ด์ง
์ด๋ฒ์ฃผ์์ ์์ฑํ๋๊ฒ ๋ชฉํ์
๋๋ค๐
ํ์ดํ
๐คธโโ๏ธ๐คธโโ๏ธ
Author And Source
์ด ๋ฌธ์ ์ ๊ดํ์ฌ(๐๋ ธ๋ง๋์ฝ๋ ํฌ๋กฌ์ฑ ๋ง๋ค๊ธฐ๐), ์ฐ๋ฆฌ๋ ์ด๊ณณ์์ ๋ ๋ง์ ์๋ฃ๋ฅผ ๋ฐ๊ฒฌํ๊ณ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ ๋ณด์๋ค https://velog.io/@igun0423/chromeapp์ ์ ๊ท์: ์์์ ์ ๋ณด๊ฐ ์์์ URL์ ํฌํจ๋์ด ์์ผ๋ฉฐ ์ ์๊ถ์ ์์์ ์์ ์ ๋๋ค.
์ฐ์ํ ๊ฐ๋ฐ์ ์ฝํ ์ธ ๋ฐ๊ฒฌ์ ์ ๋ (Collection and Share based on the CC Protocol.)
์ข์ ์นํ์ด์ง ์ฆ๊ฒจ์ฐพ๊ธฐ
๊ฐ๋ฐ์ ์ฐ์ ์ฌ์ดํธ ์์ง
๊ฐ๋ฐ์๊ฐ ์์์ผ ํ ํ์ ์ฌ์ดํธ 100์ ์ถ์ฒ ์ฐ๋ฆฌ๋ ๋น์ ์ ์ํด 100๊ฐ์ ์์ฃผ ์ฌ์ฉํ๋ ๊ฐ๋ฐ์ ํ์ต ์ฌ์ดํธ๋ฅผ ์ ๋ฆฌํ์ต๋๋ค