Skip to content
Merged
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
20 changes: 19 additions & 1 deletion src/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getFonts,
getFiles
} from "./font";
import { callTypeX, showReloadAnimation } from "./popup";
import { callTypeX, showReloadAnimation, activateExtension } from "./popup";
import { defaultFonts } from "./recursive-fonts.js";

const localFonts: Record<string, FontFile> = {};
Expand Down Expand Up @@ -194,9 +194,27 @@ export async function addFormElement(
};
});

// Auto-enable extension when interacting with font controls
const fontDetails = el.querySelector(".font-details");
if (fontDetails) {
const formElements = fontDetails.querySelectorAll(
"input, select, textarea"
);
formElements.forEach(element => {
element.addEventListener("change", autoEnableExtension);
});
}

usedFonts.prepend(el);
}

async function autoEnableExtension() {
let { extensionActive } = await chrome.storage.local.get("extensionActive");
if (!extensionActive) {
await activateExtension(true);
}
}

async function changeFont(
parent: HTMLFieldSetElement,
newFontFileName: string
Expand Down
12 changes: 9 additions & 3 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,19 @@ async function showStatus() {
activateFonts.classList.toggle("active", !!extensionActive);
}

// Toggle extension on/off using the button
activateFonts.onclick = async () => {
// Set extension state (on/off) or toggle it
export async function activateExtension(setActive?: boolean) {
let { extensionActive } = await chrome.storage.local.get("extensionActive");
const active = setActive !== undefined ? setActive : !extensionActive;
await chrome.storage.local.set({
extensionActive: !extensionActive
extensionActive: active
});
await callTypeX();
}

// Toggle extension on/off using the button
activateFonts.onclick = async () => {
await activateExtension();
};

export async function callTypeX() {
Expand Down