File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed
Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change 88 getFonts ,
99 getFiles
1010} from "./font" ;
11- import { callTypeX , showReloadAnimation } from "./popup" ;
11+ import { callTypeX , showReloadAnimation , activateExtension } from "./popup" ;
1212import { defaultFonts } from "./recursive-fonts.js" ;
1313
1414const localFonts : Record < string , FontFile > = { } ;
@@ -194,9 +194,27 @@ export async function addFormElement(
194194 } ;
195195 } ) ;
196196
197+ // Auto-enable extension when interacting with font controls
198+ const fontDetails = el . querySelector ( ".font-details" ) ;
199+ if ( fontDetails ) {
200+ const formElements = fontDetails . querySelectorAll (
201+ "input, select, textarea"
202+ ) ;
203+ formElements . forEach ( element => {
204+ element . addEventListener ( "change" , autoEnableExtension ) ;
205+ } ) ;
206+ }
207+
197208 usedFonts . prepend ( el ) ;
198209}
199210
211+ async function autoEnableExtension ( ) {
212+ let { extensionActive } = await chrome . storage . local . get ( "extensionActive" ) ;
213+ if ( ! extensionActive ) {
214+ await activateExtension ( true ) ;
215+ }
216+ }
217+
200218async function changeFont (
201219 parent : HTMLFieldSetElement ,
202220 newFontFileName : string
Original file line number Diff line number Diff line change @@ -89,13 +89,19 @@ async function showStatus() {
8989 activateFonts . classList . toggle ( "active" , ! ! extensionActive ) ;
9090}
9191
92- // Toggle extension on/off using the button
93- activateFonts . onclick = async ( ) => {
92+ // Set extension state ( on/off) or toggle it
93+ export async function activateExtension ( setActive ?: boolean ) {
9494 let { extensionActive } = await chrome . storage . local . get ( "extensionActive" ) ;
95+ const active = setActive !== undefined ? setActive : ! extensionActive ;
9596 await chrome . storage . local . set ( {
96- extensionActive : ! extensionActive
97+ extensionActive : active
9798 } ) ;
9899 await callTypeX ( ) ;
100+ }
101+
102+ // Toggle extension on/off using the button
103+ activateFonts . onclick = async ( ) => {
104+ await activateExtension ( ) ;
99105} ;
100106
101107export async function callTypeX ( ) {
You can’t perform that action at this time.
0 commit comments