Skip to content

Commit

Permalink
Renamed settings.props to more semantic settings.controls ↞ [auto…
Browse files Browse the repository at this point in the history
  • Loading branch information
kudo-sync-bot committed Nov 20, 2024
1 parent e7fa850 commit 9382f8c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions starters/chrome/extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
})

// Init CONFIG
await settings.load(Object.keys(settings.props), 'skipAlert')
await settings.load(Object.keys(settings.controls), 'skipAlert')

// Define FEEDBACK functions

Expand Down Expand Up @@ -49,11 +49,11 @@
// Define SYNC function

async function syncStorageToUI() { // on toolbar popup toggles + ChatGPT tab activations
await settings.load('extensionDisabled', Object.keys(settings.props)) // load from Chrome storage to content.js config
await settings.load('extensionDisabled', Object.keys(settings.controls)) // load from Chrome storage to content.js config
if (config.extensionDisabled) {
// Remove all hacks
} else {
// Add/remove hacks to reflect each potentially updated setting per settings.props in lib/settings.js
// Add/remove hacks to reflect each potentially updated setting per settings.controls in lib/settings.js
// e.g. if you created toolbar popup toggle to hide ChatGPT footer using hiddenFooter key...
// ...here you would use config.hiddenFooter to conditionally append/remove hidden footer style...
// ...(initial style creation + append if config.hiddenFooter would go in main routine)
Expand Down
2 changes: 1 addition & 1 deletion starters/chrome/extension/lib/settings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const config = {}, settings = {

// Init SETTINGS props (for popup menu)
props: {
controls: {
// Add settings options as keys, with each key's value being an object that includes:
// - 'type': the control type (e.g. 'toggle' or 'prompt')
// - 'label': a descriptive label
Expand Down
16 changes: 8 additions & 8 deletions starters/chrome/extension/popup/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@
document.querySelector('.menu-header').insertAdjacentElement('afterend', togglesDiv)

// Create/insert settings toggles
Object.keys(settings.props).forEach(key => {
Object.keys(settings.controls).forEach(key => {

// Init elems
const menuItemDiv = dom.create.elem('div', { class: 'menu-item menu-area' }),
menuLabel = dom.create.elem('label', { class: 'menu-icon' }),
menuLabelSpan = document.createElement('span')
let menuInput, menuSlider
menuLabelSpan.textContent = settings.props[key].label
if (settings.props[key].type == 'toggle') {
menuLabelSpan.textContent = settings.controls[key].label
if (settings.controls[key].type == 'toggle') {
menuInput = dom.create.elem('input', { type: 'checkbox' })
menuInput.checked = /disabled|hidden/i.test(key) ^ config[key]
menuSlider = dom.create.elem('span', { class: 'slider' })
menuLabel.append(menuInput, menuSlider)
menuLabel.classList.add('toggle-switch')
} else if (settings.props[key].type == 'prompt') {
menuLabel.innerText = settings.props[key].symbol
} else if (settings.controls[key].type == 'prompt') {
menuLabel.innerText = settings.controls[key].symbol
menuLabel.classList.add('menu-prompt')
}

Expand All @@ -91,15 +91,15 @@
togglesDiv.append(menuItemDiv)

// Add listeners
if (settings.props[key].type == 'toggle') {
if (settings.controls[key].type == 'toggle') {
menuItemDiv.onclick = () => menuInput.click()
menuInput.onclick = menuSlider.onclick = event => // prevent double toggle
event.stopImmediatePropagation()
menuInput.onchange = () => {
settings.save(key, !config[key]) ; sync.storageToUI()
notify(`${settings.props[key].label} ${ /disabled|hidden/i.test(key) != config[key] ? 'ON' : 'OFF' }`)
notify(`${settings.controls[key].label} ${ /disabled|hidden/i.test(key) != config[key] ? 'ON' : 'OFF' }`)
}
} else if (settings.props[key].type == 'prompt') {
} else if (settings.controls[key].type == 'prompt') {
// custom logic for each prompt based on key name
}
})
Expand Down

0 comments on commit 9382f8c

Please sign in to comment.