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
- Apsscript Radio Button và Input – Sự phụ thuộc của input vào Radio button
- Bạn sử dụng zalo và bị báo đầy ổ đĩa,phải làm sao
- Google sheet Webapp Login form Tocken quản lý phiên đăng nhập, gửi mail lấy lại thông tin đăng nhập
- Chuyển bảng dữ liệu từ file PDF vào Excel
- Google sheet Apps script Hệ thống duyệt hồ sơ sinh viên – Form nhập liệu, Login duyêt, gửi mail
- Tool VBA Form Excel xử lí chuỗi tạo folder hàng loạt theo danh sách
- Google sheet webapp | Quản lý quán Cà phê – Phân quyền- Quét QR chấm công- Quản lý nhân viên-Báo cáo
- VBA Excel Xây dựng hàm chuyển chuỗi có dấu thành không dấu, khoản trắng thành dấu –
- Google sheet Webapp | Lấy dữ liệu trên Sheet hiển thị dạng Bảng có phân trang trùy chọn trên website
- Web App Script | Trang trắc nghiệm online hỗ trợ hình ảnh, lưu file kết quả – Form nhập bộ câu hỏi
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>