mirror of
https://github.com/He4eT/browser-milje-2077.git
synced 2026-05-04 17:07:24 +00:00
milje.js: tune assureNumber function
This commit is contained in:
parent
c2fa9d3031
commit
0aec11e0c0
1 changed files with 6 additions and 6 deletions
|
|
@ -21,14 +21,14 @@ function getParamsFromStorage () {
|
||||||
* Sorry, you are not allowed to use import in the content_script :c
|
* Sorry, you are not allowed to use import in the content_script :c
|
||||||
* Copy'n'paste of storage here!
|
* Copy'n'paste of storage here!
|
||||||
*/
|
*/
|
||||||
const storage = (browser ?? window.chrome)['storage']
|
const storage = (globalThis.browser ?? globalThis.chrome)['storage']
|
||||||
|
|
||||||
return storage.local.get(['params'])
|
return storage.local.get(['params'])
|
||||||
.then(({params}) => params)
|
.then(({params}) => params)
|
||||||
}
|
}
|
||||||
|
|
||||||
function assureParams(params) {
|
function assureParams(params) {
|
||||||
const assureNumber = (rawValue, defaultValue, min, max) => {
|
const assureNumber = (rawValue) => (defaultValue) => (min, max) => {
|
||||||
let value = Number(rawValue)
|
let value = Number(rawValue)
|
||||||
|
|
||||||
if (isNaN(value)) return defaultValue
|
if (isNaN(value)) return defaultValue
|
||||||
|
|
@ -38,16 +38,16 @@ 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 {
|
||||||
className: params.className ?? 'browser-milje-2077',
|
className: params.className ?? 'browser-milje-2077',
|
||||||
/**/
|
/**/
|
||||||
randomSeed: randomSeed || new Date(),
|
randomSeed: randomSeed || new Date(),
|
||||||
/**/
|
/**/
|
||||||
halfPatternSize: assureNumber(params.halfPatternSize, 16, 0, Infinity),
|
halfPatternSize: assureNumber(params.halfPatternSize)(16)(0, Infinity),
|
||||||
scaleFactor: assureNumber(params.scaleFactor, 16, 0, Infinity),
|
scaleFactor: assureNumber(params.scaleFactor)(16)(0, Infinity),
|
||||||
gridSize: assureNumber(params.gridSize, 3, 0, Infinity),
|
gridSize: assureNumber(params.gridSize)(3)(0, Infinity),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue