refactoring and added history
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user