Skip to content

Commit

Permalink
feat(fonts): allow user to apply and reset their customization choices
Browse files Browse the repository at this point in the history
…#22

- Add the logic for "Apply Fonts" and "Reset Fonts" functionality, allowing users to preview and reset their font customization choices.

Changes summary:
- Implemented the ability for users to apply and reset font customizations, providing a dynamic preview of their font choices and the option to revert to default settings if desired.
  • Loading branch information
itsmartashub committed May 28, 2024
1 parent ad5eb26 commit 34f225b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
31 changes: 29 additions & 2 deletions build/dev/chromium-mv3/content.12730647.js

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions src/js/app/customFonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,26 @@ export let fontHtmlCode = `
</div>
<div class="gap-2 mt-4 grid">
<button id="resetFont" class="btn block relative btn-secondary text-center">Reset to Default</button>
<button id="applyFont" class="btn block relative btn-primary text-center">Apply Fonts</button>
</div>
</section>
`

function setCSSVariables({ fontFamily, fontSize = '16px' }) {
console.log(fontFamily, fontSize)
document.documentElement.style.setProperty('--f-family', fontFamily)
document.documentElement.style.setProperty('--f-size', fontSize)
}

function setInputFields({ fontFamily, fontSize = '16' }) {
document.getElementById('fontFamily').value = fontFamily
document.getElementById('fontSize').value = fontSize
}
export function applyFont() {
const fontFamily = document.getElementById('fontFamily').value
const fontSize = document.getElementById('fontSize').value + 'px'

// Create the <link> in <head> which will fetch the selected font from Google Fonts

// Apply CSS variables
setCSSVariables({ fontFamily, fontSize })

Expand All @@ -66,3 +71,16 @@ export function applyFont() {
fontSize: fontSize,
})
}
export function resetFont() {
// Reset CSS variables to default values
setCSSVariables({ fontFamily: fontFamilyDefault, fontSize: '16px' })

// Reset input fields to default values
// document.getElementById('fontFamily').value =
setInputFields({ fontFamily: 'Default', fontSize: '16' })

// Remove custom font link from the head

// Remove custom font settings from chrome.storage
chrome.storage.sync.remove(['fontFamily', 'fontSize'])
}
4 changes: 3 additions & 1 deletion src/js/app/floatingBtn.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { icon_sun, icon_moon, icon_moon_full, icon_settings, icon_paint } from '
// import gpthToggleImg from '../../img/gpth-toggle-circled.webp'
import { hexToHSL } from '../utils/hexToHSL'

import { fontHtmlCode } from './customFonts'
import { fontHtmlCode, applyFont, resetFont } from './customFonts'
// console.log(fontHtmlCode)

// let isOptionsShown = false
Expand Down Expand Up @@ -185,6 +185,8 @@ function renderSettings() {
$resetAllBtn.disabled = true

$settings.querySelector('#resetAllSettings').addEventListener('click', resetAllSettings)
document.getElementById('applyFont').addEventListener('click', applyFont)
document.getElementById('resetFont').addEventListener('click', resetFont)
}

function openSettings() {
Expand Down

0 comments on commit 34f225b

Please sign in to comment.