代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LocalStorage Manager</title>
<style>
body {
font-family: 'Roboto', sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f5f5f5;
}
.container {
width: 100%;
max-width: 600px;
padding: 24px;
background-color: #fff;
border-radius: 12px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
h1 {
font-size: 24px;
margin-bottom: 16px;
color: #212121;
}
h2 {
font-size: 18px;
margin-top: 24px;
margin-bottom: 12px;
color: #212121;
}
button {
background-color: #6750a4; /* MD3 主色调 */
border: none;
color: white;
padding: 12px 32px;
border-radius: 9999px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #4a3c8c; /* 悬停时的深色 */
}
textarea {
width: 100%;
min-height: 150px;
border: 1px solid #d0d5dd;
border-radius: 8px;
font-size: 16px;
margin-top: 8px;
resize: vertical;
}
.section {
margin-bottom: 24px;
}
.section > button {
margin-top: 8px;
}
</style>
</head>
<body>
<div class="container">
<h1>LocalStorage Manager</h1>
<div class="section">
<h2>导出 LocalStorage</h2>
<button id="exportButton">导出</button>
<textarea id="exportTextarea" readonly></textarea>
</div>
<div class="section">
<h2>导入 LocalStorage</h2>
<textarea id="importTextarea" placeholder="粘贴 JSON 格式的 LocalStorage 数据"></textarea>
<button id="importButton">导入</button>
</div>
</div>
<script>
document.getElementById('exportButton').addEventListener('click', function() {
const localStorageData = {};
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
localStorageData[key] = localStorage.getItem(key);
}
const jsonStr = JSON.stringify(localStorageData, null, 2);
document.getElementById('exportTextarea').value = jsonStr;
});
document.getElementById('importButton').addEventListener('click', function() {
const importTextarea = document.getElementById('importTextarea');
try {
const data = JSON.parse(importTextarea.value);
for (const key in data) {
if (data.hasOwnProperty(key)) {
localStorage.setItem(key, data[key]);
}
}
alert('导入成功!');
} catch (e) {
alert('导入失败:' + e.message);
}
});
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。