Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable user to add more fumo replacements #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ function capitalize(text) {
return text.charAt(0).toUpperCase() + text.substring(1);
}

const { body } = document;
(async () => {
const { body } = document;
if (!body) return;

if (body) {
let terms = {
const settings = await browser.storage.sync.get();

let terms = Object.assign({
"AI": "Fumo",
"artificial intelligence": "Fumo",
"Artificial Intelligence": "Fumo",
Expand All @@ -26,7 +29,7 @@ if (body) {
"Anthropic": "FumoCo",
"AGI": "Cirno",
"artificial general intelligence": "Cirno",
};
}, settings.more_fumo && JSON.parse(settings.more_fumo));

// Add matches for capitalized and pluralized versions of terms
for (const [term, replacement] of Object.entries(terms)) {
Expand Down Expand Up @@ -54,4 +57,4 @@ if (body) {
node.textContent = node.textContent.replace(regex, (match) => terms[match]);
}
}
}
})();
6 changes: 6 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@
"strict_min_version": "109.0"
}
},
"permissions": [
"storage"
],
"options_ui": {
"page": "settings.html"
},
"minimum_chrome_version": "88"
}
22 changes: 22 additions & 0 deletions src/settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>

<html>

<head>
<meta charset="utf-8" />
</head>

<body>
<form>
<div>
<label>More Fumo</label>
<textarea id="more-fumo" placeholder='{ "GPT": "Fumo" }'></textarea>
</div>

<button type="submit">Save</button>
</form>

<script src="settings.js"></script>
</body>

</html>
21 changes: 21 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
async function loadSettings() {
const settings = await browser.storage.sync.get();

document.querySelector("#more-fumo").value = settings.more_fumo;
}

function updateSettings(e) {
e.preventDefault();
const more_fumo = document.querySelector("#more-fumo").value;
try {
JSON.parse(more_fumo);
} catch (err) {
alert("More Fumo: JSON Parse Error: " + err);
return;
}

browser.storage.sync.set({ more_fumo });
}

document.addEventListener("DOMContentLoaded", loadSettings);
document.querySelector("form").addEventListener("submit", updateSettings);