gemini_prompter / storage.js
SenY's picture
绠$悊鏂规硶澶夋洿
3e76749
raw
history blame contribute delete
963 Bytes
function saveToUserStorage(force = false) {
const currentTime = new Date().getTime();
const lastSaveTimestamp = parseInt(localStorage.getItem('lastSaveTimestamp') || '0');
if (!force && currentTime - lastSaveTimestamp < 5000) {
return;
}
const data = {};
document.querySelectorAll('input, textarea, select').forEach(input => {
data[input.id] = input.value;
});
localStorage.setItem('gemini_prompt', JSON.stringify(data));
localStorage.setItem('lastSaveTimestamp', currentTime.toString());
return true;
}
function loadFromUserStorage() {
const data = JSON.parse(localStorage.getItem('gemini_prompt')) || {};
document.querySelectorAll('input, textarea, select').forEach(input => {
let v = data[input.id] || "";
if (v) {
if (input.type === "number") {
v = parseInt(v);
}
input.value = v;
}
});
}