-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread-localstorage.js
More file actions
174 lines (159 loc) · 5.35 KB
/
read-localstorage.js
File metadata and controls
174 lines (159 loc) · 5.35 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env node
/**
* LocalStorage 设置读取脚本
*
* 读取视频生成器的所有持久化设置
*
* 使用方法:
* node read-localstorage.js
*
* 注意: 此脚本需要在应用运行时打开 DevTools Console 执行,
* 或者作为 HTML 页面在浏览器中运行
*/
const STORAGE_KEYS = {
'generator-rules': '拼接规则',
'generator-output': '输出设置',
'generator-output-path': '输出路径',
'generator-output-filename': '输出文件名',
'generator-segments-path': '中间文件路径',
'generator-volume-balance': '音量均衡配置',
'generator-transitions': '转场配置'
};
/**
* 读取并显示所有 localStorage 设置
* (在浏览器控制台中执行此函数)
*/
function readAllSettings() {
console.log('='.repeat(80));
console.log('🎬 视频生成设置 - LocalStorage 读取');
console.log('='.repeat(80));
console.log('');
let settingsCount = 0;
let totalSize = 0;
for (const [key, label] of Object.entries(STORAGE_KEYS)) {
const value = localStorage.getItem(key);
console.log(`\n📋 ${label}`);
console.log(` 键名: ${key}`);
if (value) {
settingsCount++;
totalSize += value.length;
try {
const parsed = JSON.parse(value);
console.log(` 大小: ${(value.length / 1024).toFixed(2)} KB`);
console.log(` 内容:`);
console.log(JSON.stringify(parsed, null, 2).split('\n').map(line => ' ' + line).join('\n'));
} catch (e) {
console.log(` 内容: ${value}`);
}
} else {
console.log(` 状态: ❌ 未设置`);
}
console.log('-'.repeat(80));
}
console.log('\n' + '='.repeat(80));
console.log('📊 统计信息');
console.log('='.repeat(80));
console.log(`已保存设置: ${settingsCount} / ${Object.keys(STORAGE_KEYS).length}`);
console.log(`总大小: ${(totalSize / 1024).toFixed(2)} KB`);
console.log('='.repeat(80));
// 返回所有设置的对象
const allSettings = {};
for (const key of Object.keys(STORAGE_KEYS)) {
const value = localStorage.getItem(key);
if (value) {
try {
allSettings[key] = JSON.parse(value);
} catch (e) {
allSettings[key] = value;
}
}
}
return allSettings;
}
/**
* 导出设置为 JSON 文件
* (在浏览器控制台中执行)
*/
function exportSettings() {
const settings = readAllSettings();
const jsonStr = JSON.stringify(settings, null, 2);
const blob = new Blob([jsonStr], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `generator-settings-${new Date().toISOString().slice(0,10)}.json`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
console.log('✅ 设置已导出到下载文件夹');
}
/**
* 清空所有设置
* (在浏览器控制台中执行)
*/
function clearAllSettings() {
let count = 0;
for (const key of Object.keys(STORAGE_KEYS)) {
if (localStorage.getItem(key)) {
localStorage.removeItem(key);
count++;
}
}
console.log(`✅ 已清空 ${count} 个设置项`);
return count;
}
/**
* 导入设置
* (在浏览器控制台中执行)
*
* @param {Object} settings - 设置对象
*/
function importSettings(settings) {
let count = 0;
for (const [key, value] of Object.entries(settings)) {
if (STORAGE_KEYS[key]) {
localStorage.setItem(key, JSON.stringify(value));
count++;
console.log(`✅ 已导入: ${key}`);
} else {
console.warn(`⚠️ 未知键: ${key}`);
}
}
console.log(`✅ 成功导入 ${count} 个设置项`);
}
// Node.js 环境下的说明
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
STORAGE_KEYS,
readAllSettings,
exportSettings,
clearAllSettings,
importSettings
};
console.log('='.repeat(80));
console.log('📖 使用说明');
console.log('='.repeat(80));
console.log('');
console.log('此脚本需要在浏览器环境中运行(通过 DevTools Console)');
console.log('');
console.log('方法 1: 使用 HTML 页面');
console.log(' 1. 在浏览器中打开: read-generator-settings.html');
console.log(' 2. 页面会自动读取并显示所有设置');
console.log(' 3. 可以导出为 JSON 文件');
console.log('');
console.log('方法 2: 在应用中打开 DevTools');
console.log(' 1. 运行应用: npm run dev:desktop');
console.log(' 2. 打开 DevTools (Ctrl+Shift+I 或 F12)');
console.log(' 3. 切换到 Console 标签');
console.log(' 4. 复制并粘贴此文件的内容到 Console');
console.log(' 5. 执行: readAllSettings()');
console.log('');
console.log('可用命令:');
console.log(' - readAllSettings() 读取并显示所有设置');
console.log(' - exportSettings() 导出设置为 JSON 文件');
console.log(' - clearAllSettings() 清空所有设置');
console.log(' - importSettings(obj) 导入设置对象');
console.log('');
console.log('='.repeat(80));
}