Add User Settings
Summary
The add method stores or updates a value in User Settings. If the key already exists, it is overwritten with the new value.
Purpose
- Save user preferences (theme, language, display settings)
- Store user-specific configuration data
- Update existing settings with new values
Syntax
SigmaSDK.WRITER.storage.user.add({ key: "key", value: "value" })Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
key | String | Yes | The storage key |
value | String | Yes | The value to store (must be a string) |
Note: Values must be strings. Use
JSON.stringify() to store objects, and JSON.parse() to retrieve them.Basic Example
SigmaSDK.WRITER.storage.user.add({ key: "theme", value: "dark" })
.then(function() {
console.log("Theme saved");
});Storing an Object (as JSON String)
const settings = { theme: "dark", fontSize: 14, language: "en" };
SigmaSDK.WRITER.storage.user.add({
key: "userPreferences",
value: JSON.stringify(settings)
}).then(function() {
console.log("Preferences saved");
});Complete Example
<!DOCTYPE html>
<html>
<head>
<title>Settings Manager</title>
<script src="https://static.zohocdn.com/sigma/client/sdk/v3/sigma-sdk.min.js"></script>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
.setting { margin: 10px 0; display: flex; align-items: center; gap: 10px; }
button { padding: 10px 20px; cursor: pointer; }
#status { margin-top: 15px; color: green; }
</style>
</head>
<body>
<h1>Extension Settings</h1>
<div class="setting">
<label>Theme:</label>
<select id="theme">
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</div>
<div class="setting">
<label>Language:</label>
<select id="language">
<option value="en">English</option>
<option value="es">Spanish</option>
<option value="fr">French</option>
</select>
</div>
<button onclick="saveSettings()">Save Settings</button>
<p id="status"></p>
<script>
SigmaSDK.WRITER.init().then(loadSettings);
async function loadSettings() {
const theme = await SigmaSDK.WRITER.storage.user.fetch("theme");
const lang = await SigmaSDK.WRITER.storage.user.fetch("language");
if (theme) document.getElementById("theme").value = theme;
if (lang) document.getElementById("language").value = lang;
}
async function saveSettings() {
const theme = document.getElementById("theme").value;
const lang = document.getElementById("language").value;
await SigmaSDK.WRITER.storage.user.add({ key: "theme", value: theme });
await SigmaSDK.WRITER.storage.user.add({ key: "language", value: lang });
document.getElementById("status").textContent = "Settings saved!";
}
</script>
</body>
</html>