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