Skip to content

[Question] How do I init defaults for GM_config? #4

@TuTAH1

Description

@TuTAH1

I made a configFields

let actionList = ["hide", "filter"]

var configFields = {
	"action": {
		"label": "Action",
		"type": "select",
		"default": "filter",
		"options": actionList
	},
	"filter": {
		"label": "Filter",
		"type": "text",
		"default": "opacity(0.2)"
	},
	"timeToWatch": {
		"label": "Time to watch",
		"type": "number",
		"default": 1000
	},
	"watchIfPreview": {
		"label": "Watch if preview",
		"type": "checkbox",
		"default": false
	},
	"logging": {
		"label": "Logging",
		"type": "checkbox",
		"default": true
	}
}

and initialized GM_config

GM_config.init({
	id: "script-name_config",
	title: "script name",
	fields: configFields,
})

then try to get the settings values

let action = GM_config.get("action")
let filter = GM_config.get("filter")
let timeToWatch = GM_config.get("timeToWatch")
let watchIfPreview = GM_config.get("watchIfPreview")
let logging = GM_config.get("logging")

but getting Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'value'). So I'm guessing the default values aren't set automatically. How do I do it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions