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
- Giảm dung lượng PDF dễ dàng với PDF24 Creator – Miễn phí và hiệu quả
- Chuyển đổi Pdf dạng bản scan sang MS Excel chuẩn không bị lỗi font và giữ nguyên định dạng
- Chuyển định dạng file pdf dạng scan – dạng chụp hình ảnh sang MS Word định dạng chuẩn 99.9%
- Phím tắt vào BIOS và Boot Options của các hãng máy tính phổ biến
- Google sheet webapp | Form đăng ký Tự động gửi ID và QR code Check in qua địa chỉ mail
- Cách tắt Windows update và Windows Defender cực đơn giả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
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>