-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.html
More file actions
135 lines (121 loc) · 3.98 KB
/
editor.html
File metadata and controls
135 lines (121 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Storage Editor</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Inconsolata&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Inconsolata', monospace;
background: #000;
color: white;
user-select: none;
}
input, textarea {
background: transparent;
border: 1px solid #555;
padding: 0.5rem;
border-radius: 0.5rem;
width: 100%;
color: white;
}
.btn {
background: transparent;
border: 1px solid #777;
padding: 0.5rem 1rem;
border-radius: 0.5rem;
transition: 0.2s;
}
.btn:hover {
border-color: white;
}
.toast {
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
@keyframes fadein {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeout {
from { opacity: 1; transform: translateY(0); }
to { opacity: 0; transform: translateY(10px); }
}
</style>
</head>
<body class="min-h-screen flex items-center justify-center p-6">
<div class="w-full max-w-xl space-y-4">
<h1 class="text-2xl font-bold mb-4 text-white">LocalStorage Editor</h1>
<div>
<label class="text-gray-400 text-sm">Enter Key</label>
<input type="text" id="keyInput" placeholder="myKey" oninput="checkKey()" />
</div>
<div>
<label class="text-gray-400 text-sm">Value</label>
<textarea id="valueInput" rows="4" placeholder="Edit value here..."></textarea>
</div>
<div id="status" class="text-xs text-gray-500"></div>
<div class="flex gap-3">
<button onclick="saveData()" class="btn">Save</button>
<button onclick="deleteData()" class="btn">Delete</button>
</div>
</div>
<!-- Toast Container -->
<div id="toastContainer" class="fixed bottom-4 right-4 space-y-2 z-50"></div>
<script>
function showToast(message, type = 'default') {
const container = document.getElementById('toastContainer');
const toast = document.createElement('div');
toast.className = `toast px-4 py-2 rounded-lg text-sm ${
type === 'error' ? 'bg-red-600' : 'bg-white text-black'
} shadow-lg`;
toast.textContent = message;
container.appendChild(toast);
setTimeout(() => {
toast.remove();
}, 3000);
}
function checkKey() {
const key = document.getElementById('keyInput').value;
const valueBox = document.getElementById('valueInput');
const status = document.getElementById('status');
if (!key) {
valueBox.value = '';
status.textContent = '';
return;
}
if (localStorage.getItem(key) !== null) {
valueBox.value = localStorage.getItem(key);
status.textContent = 'Key exists.';
} else {
valueBox.value = '';
status.textContent = 'Key does not exist. New key will be created on save.';
}
}
function saveData() {
const key = document.getElementById('keyInput').value;
const value = document.getElementById('valueInput').value;
if (!key) return showToast('Key is required.', 'error');
localStorage.setItem(key, value);
checkKey();
showToast('Saved successfully.');
}
function deleteData() {
const key = document.getElementById('keyInput').value;
if (!key) return showToast('Enter a key to delete.', 'error');
if (localStorage.getItem(key) !== null) {
localStorage.removeItem(key);
document.getElementById('valueInput').value = '';
checkKey();
showToast('Deleted successfully.');
} else {
showToast('Key does not exist.', 'error');
}
}
window.onload = () => {
document.getElementById('keyInput').focus();
};
</script>
</body>
</html>