milje.js: demo page support

This commit is contained in:
He4eT 2024-08-15 04:48:46 +02:00
commit c2fa9d3031

View file

@ -1,16 +1,31 @@
/** start()
* Sorry, you are not allowed to use import in the content_script :c
* Copy'n'paste here!
*/
const storage = (browser ?? window.chrome)['storage']
/* */ /* */
storage.local.get(['params']) function start () {
.then(({params}) => params) Promise.resolve()
.catch(() => {}) .then(getParamsFromStorage)
.catch((e) => {
console.error(e)
console.log('An error occurred. Milje will use the default params.')
return {}
})
.then(assureParams) .then(assureParams)
.then(run) .then(run)
}
/* Params */
function getParamsFromStorage () {
/**
* Sorry, you are not allowed to use import in the content_script :c
* Copy'n'paste of storage here!
*/
const storage = (browser ?? window.chrome)['storage']
return storage.local.get(['params'])
.then(({params}) => params)
}
function assureParams(params) { function assureParams(params) {
const assureNumber = (rawValue, defaultValue, min, max) => { const assureNumber = (rawValue, defaultValue, min, max) => {
@ -22,6 +37,7 @@ function assureParams(params) {
return value return value
} }
const randomSeed = assureNumber(params.randomSeed, 0, 0, Infinity) const randomSeed = assureNumber(params.randomSeed, 0, 0, Infinity)
return { return {
@ -91,6 +107,7 @@ function generatePattern(halfPatternSize, gridSize, randomSeed) {
} }
} }
} }
return matrix return matrix
} }