Gathering detailed insights and metrics for webext-autooptions
Gathering detailed insights and metrics for webext-autooptions
Gathering detailed insights and metrics for webext-autooptions
Gathering detailed insights and metrics for webext-autooptions
npm install webext-autooptions
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
Zero-boilerplate wrapper for storing and retrieving user-settings in your Chrome Extension.
⚡ Built from scratch – fast, tree-shakeable, and bundler-friendly.
🔌 Syncs HTML inputs to extension settings directly. Automatically created default settings.
🧠 Supports categories, defaults, exclusions.
🛠️ Compatible with both JavaScript and TypeScript projects.
1npm install webext-autooptions
The library internally uses the chrome storage API, which requires permission in your manifest.json.
1{ 2 "permissions": ["storage"] 3}
This library requires three components to function correctly:
A default config is automatically created when the extension is first installed, using the default ao-
values from your inputs. Changes in your settings between extension versions are automatically migrated on update.
To set this up in the background script, specify:
optionsPageType
(Required, fullPage
| embedded
| popup
): Type of options page you're using.hasInstallAction
(Required, boolean): Set this option to true
if your options page defines an installAction
function, false otherwise.1import { setDefaultConfig } from "webext-autooptions"; 2 3setDefaultConfig('embedded', false);
The library automatically handles and validates HTML inputs.
id
. Radio inputs require a name
.checked
or value
. Instead, use data-ao-
attributes for configuration:
data-ao-default
: Marks an input as checked by default.data-ao-value=""
: Defines a default value for an input.data-ao-category=""
: Groups inputs under a category.data-ao-ignore
: Excludes an input from being saved.Load the configuration in the options.
1import { AutoOptions } from "webext-autooptions"; 2 3const AO = new AutoOptions({ 4 storageName: 'storageName' 5}) 6 7document.addEventListener('DOMContentLoaded', async () => { 8 await AO.loadConfig(); 9});
storageName
(Required, string): A unique namespace for storing settings. Each AutoOptions instance in your extension must use a different name.saveOnChange
(Optional, boolean): If set to false
, changes will only be saved on user input. Defaults to true
.installAction
(Optional, function): A function to run once during the initial installation.If saveOnChange
is false
, you can save manually by using:
1AO.saveAll();
Use this function to reset inputs to their default configuration:
1AO.resetToDefault();
Get the saved settings, and react to configuration changes dynamically in your scripts:
1import { StoredOptions } from "webext-autooptions"; 2 3const storedOptions = await StoredOptions.get(CONFIG_NAME); 4 5storedOptions.onValueChange(settingDetails => { 6 const { category, name, value } = settingDetails; 7 8 if (category === "ui" && name === "background-color") { 9 changeBackgroundColor(value); 10 } 11}) 12 13const storedBackgroundColor = storedOptions.getValue({ 14 category: "ui", 15 name: "background-color" 16})
AutoOptions is released under the MIT License.
No vulnerabilities found.
No security vulnerabilities found.