mirror of
https://github.com/mue/mue.git
synced 2026-07-12 10:46:12 +02:00
feat: random colour/gradient background, fix toasts
This commit is contained in:
@@ -37,6 +37,22 @@ export function gradientStyleBuilder({ type, angle, gradient }) {
|
||||
};
|
||||
}
|
||||
|
||||
export function randomColourStyleBuilder(type) {
|
||||
// randomColour based on https://stackoverflow.com/a/5092872
|
||||
const randomColour = () => '#000000'.replace(/0/g, () => {return (~~(Math.random()*16)).toString(16)});
|
||||
let style = `background:${randomColour()};`;
|
||||
|
||||
if (type === 'random_gradient') {
|
||||
const directions = ['to right', 'to left', 'to bottom', 'to top', 'to bottom right', 'to bottom left', 'to top right', 'to top left'];
|
||||
style = `background:linear-gradient(${directions[Math.floor(Math.random() * directions.length)]}, ${randomColour()}, ${randomColour()});`;
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'colour',
|
||||
style
|
||||
}
|
||||
}
|
||||
|
||||
// source: https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#ECMAScript_.28JavaScript.2FActionScript.2C_etc..29
|
||||
export function lon2tile(lon, zoom) {
|
||||
return (Math.floor((lon + 180) / 360 * Math.pow(2, zoom)));
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// based on https://stackoverflow.com/a/47009962
|
||||
export default function interval(callback, interval, name) {
|
||||
const key = name + 'interval';
|
||||
const timeInMs = localStorage.getItem(key);
|
||||
|
||||
const ms = localStorage.getItem(key);
|
||||
const now = Date.now();
|
||||
|
||||
const executeCallback = () => {
|
||||
@@ -10,8 +9,8 @@ export default function interval(callback, interval, name) {
|
||||
callback();
|
||||
};
|
||||
|
||||
if (timeInMs) {
|
||||
const delta = now - parseInt(timeInMs);
|
||||
if (ms) {
|
||||
const delta = now - parseInt(ms);
|
||||
if (delta > interval) {
|
||||
setInterval(executeCallback, interval);
|
||||
} else {
|
||||
@@ -23,5 +22,6 @@ export default function interval(callback, interval, name) {
|
||||
} else {
|
||||
setInterval(executeCallback, interval);
|
||||
}
|
||||
|
||||
localStorage.setItem(key, now);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user