From 02914b7bba7ee26da27e0ce5e003e466e1215e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Gillstr=C3=B6m?= Date: Wed, 11 May 2016 18:24:02 +0200 Subject: [PATCH] Save current seed in URL Fixes #2. --- browser.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/browser.js b/browser.js index 0c4ad7b..e0ad756 100644 --- a/browser.js +++ b/browser.js @@ -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); @@ -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(); @@ -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);