Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Raheem committed May 16, 2023
1 parent f504215 commit 0fd362b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
Binary file modified aify.xpi
Binary file not shown.
34 changes: 15 additions & 19 deletions plugin/html/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,6 @@ const getModels = async (apiKeyInput, getModelsButton) => {
getModelsButton.disabled = true;
};

const handleDOMContentLoad = (modelSelect, apiKeyInput, actionsContainer, addActionButton, saveButton, getModelsButton, maxTokensInput, defaultButton, notesContainer) => {
browser.storage.local.get(["model", "apiKey", "actions", "maxTokens", "promptUpdated"], (data) => {
const { model = defaultModel, apiKey = '', maxTokens = 0, promptUpdated = 0, actions = defaultActions } = data;

apiKeyInput.value = apiKey;
addModelToSelect(model, modelSelect);
maxTokensInput.value = maxTokens;
handleWarning(promptUpdated, notesContainer);

actions.forEach(({ name, prompt }) => addAction(name, prompt, actionsContainer));

addActionButton.addEventListener("click", () => addAction("", "", actionsContainer));
saveButton.addEventListener("click", () => saveSettings(actionsContainer, modelSelect, apiKeyInput, maxTokensInput));
defaultButton.addEventListener("click", () => setDefaultSettings(actionsContainer, modelSelect, apiKeyInput, maxTokensInput));
getModelsButton.addEventListener("click", () => getModels(apiKeyInput, getModelsButton));
});
}

const addModelToSelect = (model, modelSelect) => {
let option = document.createElement("option");
option.value = model;
Expand All @@ -161,5 +143,19 @@ document.addEventListener("DOMContentLoaded", () => {
const defaultButton = document.getElementById("default-settings");
const notesContainer = document.getElementById("notes-container");

handleDOMContentLoad(modelSelect, apiKeyInput, actionsContainer, addActionButton, saveButton, getModelsButton, maxTokensInput, defaultButton, notesContainer);
browser.storage.local.get(["model", "apiKey", "actions", "maxTokens", "promptUpdated"], (data) => {
const { model = defaultModel, apiKey = '', maxTokens = 0, promptUpdated = 0, actions = defaultActions } = data;

apiKeyInput.value = apiKey;
addModelToSelect(model, modelSelect);
maxTokensInput.value = maxTokens;
handleWarning(promptUpdated, notesContainer);

actions.forEach(({ name, prompt }) => addAction(name, prompt, actionsContainer));

addActionButton.addEventListener("click", () => addAction("", "", actionsContainer));
saveButton.addEventListener("click", () => saveSettings(actionsContainer, modelSelect, apiKeyInput, maxTokensInput));
defaultButton.addEventListener("click", () => setDefaultSettings(actionsContainer, modelSelect, apiKeyInput, maxTokensInput));
getModelsButton.addEventListener("click", () => getModels(apiKeyInput, getModelsButton));
});
});
2 changes: 1 addition & 1 deletion plugin/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Aify",
"version": "1.10",
"version": "1.11",
"description": "A Thunderbird plugin to rewrite text based on user-selected actions using OpenAI's API.",
"author": "Ali Raheem",
"browser_specific_settings": {
Expand Down

0 comments on commit 0fd362b

Please sign in to comment.