Spaces:
Sleeping
Sleeping
Youngger9765
commited on
Commit
·
38ab2ef
1
Parent(s):
d51ce68
更新 index.html 模板,新增本地儲存功能以保存和載入變數設定
Browse files- 在生成 HTML 前將變數儲存至 localStorage,並在頁面加載時自動載入
- 增加錯誤處理以確保儲存和載入過程的穩定性
此次更新旨在提升用戶體驗,使用戶能夠方便地保存和恢復設定。
- templates/index.html +29 -0
templates/index.html
CHANGED
@@ -2079,6 +2079,15 @@
|
|
2079 |
console.log('========== 開始生成 HTML ==========');
|
2080 |
showProgress();
|
2081 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2082 |
try {
|
2083 |
// Step 1: 驗證表單資料
|
2084 |
updateStep(1, 'active', '正在檢查表單資料...');
|
@@ -2282,6 +2291,26 @@
|
|
2282 |
showToast('檔案下載中...', 'success');
|
2283 |
}
|
2284 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2285 |
// Don't auto-generate on page load
|
2286 |
// Wait for user to click the button
|
2287 |
</script>
|
|
|
2079 |
console.log('========== 開始生成 HTML ==========');
|
2080 |
showProgress();
|
2081 |
|
2082 |
+
// Save to localStorage
|
2083 |
+
try {
|
2084 |
+
const variablesContent = document.getElementById('variables').value;
|
2085 |
+
localStorage.setItem('lsw-html-variables', variablesContent);
|
2086 |
+
console.log('變數已儲存到 localStorage');
|
2087 |
+
} catch (e) {
|
2088 |
+
console.error('無法儲存到 localStorage:', e);
|
2089 |
+
}
|
2090 |
+
|
2091 |
try {
|
2092 |
// Step 1: 驗證表單資料
|
2093 |
updateStep(1, 'active', '正在檢查表單資料...');
|
|
|
2291 |
showToast('檔案下載中...', 'success');
|
2292 |
}
|
2293 |
|
2294 |
+
// Load saved variables from localStorage on page load
|
2295 |
+
window.addEventListener('DOMContentLoaded', function() {
|
2296 |
+
try {
|
2297 |
+
const savedVariables = localStorage.getItem('lsw-html-variables');
|
2298 |
+
if (savedVariables) {
|
2299 |
+
document.getElementById('variables').value = savedVariables;
|
2300 |
+
|
2301 |
+
// If in form mode, update form from JSON
|
2302 |
+
if (variableMode === 'form') {
|
2303 |
+
updateFormFromJson();
|
2304 |
+
}
|
2305 |
+
|
2306 |
+
console.log('已從 localStorage 載入變數');
|
2307 |
+
showToast('已載入上次儲存的設定', 'info');
|
2308 |
+
}
|
2309 |
+
} catch (e) {
|
2310 |
+
console.error('無法從 localStorage 載入:', e);
|
2311 |
+
}
|
2312 |
+
});
|
2313 |
+
|
2314 |
// Don't auto-generate on page load
|
2315 |
// Wait for user to click the button
|
2316 |
</script>
|