Apps script Webapp CSS – HTML – JS | Tạo ứng dụng Ghi chú trên nền tảng webapp – website
Giaoan.link chia sẻ một project về “Apps script Webapp CSS – HTML – JS | Tạo ứng dụng Ghi chú trên nền tảng webapp – website”. Đây là ứng dụng css, html, js nên bạn cũng có thể sử dụng trên nền tảng website, blog. Ghi chú có chức năng tạo mới và xóa. Dữ liệu được lưu trữ trên máy cục bộ (trên trình duyệt của bạn). Dưới đây là link video hướng dẫn, demo. Phần bên dưới là mã code trong project.
Bạn truy cập trang tổng hợp các projet excel, googlesheet, apps script.
Các Project ngẫu nhiên
- Web App Script CSS JS | Tạo hiệu ứng Click button Nổ tung các mảnh giấy và chuyển link
- Web App Script CSS | Tạo button Liên hệ gồm 3 option đẹp mắt cho trang web
- Web App Script Webapp | Hiệu ứng hoa rơi – Form nhập liệu Gửi nội dung đến email
- Web App Script | Thanh trạng thái Status bar – Giá trị thể hiện theo điểm và label.
- Google sheet Apps script | Data Entry Form – Tự động đọc số tiền thành chữ ở trường input
- Google sheet Apps script | Cập nhật điểm lớp học – Theo danh sách lớp và Theo từng học sinh
- Google sheet, apps script Định dạng dấu phân cách hàng ngàn cho input
- Google sheet apps script | Chọn năm và kiểu biểu đồ để Load dữ liệu lên website
- Google sheet apps script | Scan QR code – Filter and get data table display on webapp
- Google sheet apps script Filter to get data to display on webapp, fill background color for data row
Code trên trang “Code.gs”
function doGet() {
return HtmlService.createTemplateFromFile('note')
.evaluate()
.addMetaTag('viewport', 'width=device-width, initial-scale=1')
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent();
}
Code trên trang “note.html”
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<?!= include('css'); ?>
</head>
<body>
<div class="container">
<h1><img src="https://lh3.googleusercontent.com/d/1IIqdNulapU4p7hR014ov3C0tLt2vo2-I=w1000?authuser=0"> Ghi chú trên nền webapp</h1>
<button class="btn"><img src="https://lh3.googleusercontent.com/d/1LCZzGgsp6go5Y2eOlFAQ4U1mu0bLkQqL=w1000?authuser=0">Tạo ghi chú</button>
<div class="notes-container">
<!--<p contenteditable="true" class="input-box">
<img src="https://lh3.googleusercontent.com/d/1l7BxmvRg-rstOFayyvpEP85ZSAWvncVq=w1000?authuser=0">
</p> -->
</div>
</div>
<?!= include('javascript'); ?>
</body>
</html>
Code trên trang “css.html”
<style>
*{
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
box-sizing: border-box;
}
.container{
width: 100%;
min-height: 100vh;
background: linear-gradient(130deg, #cc02fe, #fadbf8);
color: #ffffff;
padding-top: 4%;
padding-left: 10%;
}
.container h1{
display: flex;
align-items: center;
font-size: 35 px;
font-weight: bold;
color: yellow;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
.container h1 img{
width: 80px;
}
.container button img{
width: 25px;
margin-right: 8px;
}
.container button{
display: flex;
align-items: center;
background: linear-gradient(#9418fd, #571094);
color: #ffffff;
font-size: 18px;
outline: 0;
border: 0;
border-radius: 40px;
padding: 10px 15px;
margin: 30px 0 20px;
cursor: pointer;
}
.input-box{
position: relative;
width: 100%;
max-width: 500px;
min-height: 150px;
background: #f1e97e;
font-size: 18px;
color: #333;
padding: 20px;
margin: 20px 0;
outline:0;
border: 1px solid #000;
box-shadow: 2px 2px 5px #464444;
border-radius: 10px;
}
.input-box img{
width: 35px;
position: absolute;
bottom: 15px;
right: 15px;
cursor: pointer;
}
</style>
Code trên trang “javascript.html”
<script>
const notesContainer = document.querySelector(".notes-container");
const createBtn = document.querySelector(".btn");
let notes = document.querySelectorAll(".input-box");
function showNotes(){
notesContainer.innerHTML = localStorage.getItem("notes");
}
showNotes();
function updateStorage(){
localStorage.setItem("notes",notesContainer.innerHTML);
}
createBtn.addEventListener("click", ()=>{
let inputBox = document.createElement("p");
let img = document.createElement("img");
inputBox.className = "input-box";
inputBox.setAttribute("contenteditable","true");
img.src = "https://lh3.googleusercontent.com/d/1Sk2OgS6gR3QMRum7Cx5kVPFzMjiIZAGi=w1000?authuser=0";
notesContainer.appendChild(inputBox).appendChild(img);
})
notesContainer.addEventListener("click", function(e){
if(e.target.tagName === "IMG"){
e.target.parentElement.remove();
updateStorage();
}else if(e.target.tagName === "P"){
notes = document.querySelectorAll(".input-box");
notes.forEach(nt =>{
nt.onkeyup = function(){
updateStorage();
}
})
}
})
document.addEventListener("keydown", event =>{
if(event.key === "Enter"){
document.execCommand("insertLineBreak");
event.preventDefault();
}
})
</script>