mirror of
https://github.com/He4eT/browser-milje-2077.git
synced 2026-05-04 17:07:24 +00:00
milje.js: demo page support
This commit is contained in:
parent
da25d7a819
commit
c2fa9d3031
1 changed files with 27 additions and 10 deletions
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue