Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save current seed in URL #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var context = canvas.getContext('2d');
var loop = createLoop();
var seedContainer = document.querySelector('.seed-container');
var seedText = document.querySelector('.seed-text');
var hashSeed = location.hash.length > 0;

var isIOS = /(iPad|iPhone|iPod)/i.test(navigator.userAgent);

Expand All @@ -34,9 +35,16 @@ document.body.style.margin = '0';
document.body.style.overflow = 'hidden';
canvas.style.position = 'absolute';

const getSeed = () => {
if (hashSeed) {
hashSeed = false;
return location.hash.replace('#', '');
}
};

var randomize = (ev) => {
if (ev) ev.preventDefault();
reload(createConfig());
reload(createConfig(getSeed()));
};
randomize();
resize();
Expand Down Expand Up @@ -65,6 +73,7 @@ function reload (config) {
document.body.style.background = opts.palette[0];
seedContainer.style.color = getBestContrast(opts.palette);
seedText.textContent = opts.seedName;
location.hash = opts.seedName;

background.onload = () => {
var renderer = createRenderer(opts);
Expand Down