refactoring and added history

This commit is contained in:
yoannchb-pro
2024-02-28 15:24:26 -05:00
parent 3ee84f0b31
commit b4372ca422
4 changed files with 18 additions and 13 deletions
+4
View File
@@ -115,6 +115,10 @@
<input id="infinite" type="checkbox" />
<label for="infinite">Infinite try</label>
</div>
<div class="line">
<input id="history" type="checkbox" />
<label for="history">Save history</label>
</div>
</div>
</div>
<p id="message">Message</p>
+1 -1
View File
@@ -43,7 +43,7 @@ function getLastChatGPTVersion() {
document.querySelector("#model").value = model.id;
} catch (err) {
console.error(err);
showMessage("Failed to fetch last ChatGPT version");
showMessage({ msg: "Failed to fetch last ChatGPT version", error: true });
}
});
}
+9 -4
View File
@@ -10,6 +10,7 @@ const inputsCheckbox = [
"mouseover",
"infinite",
"timeout",
"history",
];
/* Save the configuration */
@@ -17,19 +18,22 @@ saveBtn.addEventListener("click", function () {
const [apiKey, code, model] = inputsText.map((selector) =>
document.querySelector("#" + selector).value.trim()
);
const [logs, title, cursor, typing, mouseover, infinite, timeout] =
const [logs, title, cursor, typing, mouseover, infinite, timeout, history] =
inputsCheckbox.map((selector) => {
const element = document.querySelector("#" + selector);
return element.checked && element.parentElement.style.display !== "none";
});
if (!apiKey || !model) {
showMessage("Please complete all the form");
showMessage({ msg: "Please complete all the form", error: true });
return;
}
if (code.length > 0 && code.length < 3) {
showMessage("The code should at least contain 3 characters");
showMessage({
msg: "The code should at least contain 3 characters",
error: true,
});
return;
}
@@ -45,11 +49,12 @@ saveBtn.addEventListener("click", function () {
mouseover,
infinite,
timeout,
history,
mode: actualMode,
},
});
showMessage("Configuration saved", true);
showMessage({ msg: "Configuration saved" });
});
/* we load back the configuration */
+4 -8
View File
@@ -1,16 +1,12 @@
"use strict";
const message = document.querySelector("#message");
/**
* Show message into the popup
* @param {string} messageTxt
* @param {boolean} valide
* @param {boolean} infinite
*/
function showMessage(messageTxt, valide, infinite) {
message.style.color = valide ? "limegreen" : "red";
message.textContent = messageTxt;
function showMessage({ msg, error, infinite }) {
const message = document.querySelector("#message");
message.style.color = error ? "red" : "limegreen";
message.textContent = msg;
message.style.display = "block";
if (!infinite) setTimeout(() => (message.style.display = "none"), 5000);
}