Chrome Extension의 뼈대같은 존재인 manifest.json 작성!
manifest만 작성해도 Chrome Extension에 올려 앱을 확인할 수 있다.
{
"name": "Docong",
"description": "Docong Extension",
"version": "1.0",
"manifest_version": 3",
"action": {
"default_popup": "popup.html"
}
}
아이콘 클릭 시, 보여질 popup HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* ... */
</style>
</head>
<body>
<div id="container">
<div id="add">
<form id="add_form">
<input class="add_rec_input" type="text" name="url" id="url" placeholder="URL">
<br>
<br>
<button type="submit">Add</button>
<button id="deleteAll">초기화</button>
</form>
</div>
<div>
<table>
<tbody id ="list" >
</tbody>
</table>
</div>
</div>
<script src="js/jquery-3.6.0.min.js"></script>
<script src="js/popup.js"></script>
</body>
Popup HTML 에서 사용하는 JQuery code
// Dom Load
$(document).ready(()=>{makeList();})
// Add URL Data
$(document).on('submit', '#add_form', (e)=>{
e.preventDefault();
const form_data = new FormData(document.getElementById('add_form'));
var url = form_data.get('url');
chrome.storage.sync.set({
[url]:url
});
makeList();
})
// Clear Storage
$(document).on('click', '#deleteAll', (e)=>{
chrome.storage.sync.clear();
makeList();
})
// Delete List
$(document).on('click', '.listItem', (e)=>{
chrome.storage.sync.remove($(e.target).val());
makeList();
})
const makeList = () => {
chrome.storage.sync.get((result) => {
listHtml = "";
for(value in result){
listHtml += "<tr>";
listHtml += "<td>"+value+"</td>";
listHtml += "<td><button class='listItem' value="+value+">X</button></td>";
listHtml += "</tr>";
}
$("#list").html(listHtml);
});
}
/* manifest.json */
...
"permissions":[
"storage"
],
...
More: https://developer.chrome.com/docs/extensions/reference/storage/