diff --git a/index.html b/index.html index 5d9fd94..450fa8d 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,6 @@ Neomojimixer (BETA) -

Neomojimixer (BETA)

@@ -29,7 +28,7 @@ - +

Neomojis are from the following sources:

Sourcecode on Codeberg: Neomojimixer -

This work is licensed under CC BY-NC-SA 4.0

- +

This work is licensed under CC BY-NC-SA 4.0

+ - + - - diff --git a/neomojimixer.js b/neomojimixer.js index e44dd98..013ee58 100644 --- a/neomojimixer.js +++ b/neomojimixer.js @@ -225,6 +225,14 @@ const NeomojiMixer = (function(NeomojiMixer) { //Randomize initial view randomize(); + // If there was a hash, restore as a direct permalink. + if (document.location.hash != "") { + loadFromHash(document.location.hash); + } + window.addEventListener("hashchange", () => { + loadFromHash(document.location.hash); + }); + //Show little statistic var sum = 0; var variety = 1; @@ -244,6 +252,26 @@ const NeomojiMixer = (function(NeomojiMixer) { } + function loadFromHash(hash) { + let parts = hash + .slice(1) // the first character is always the '#' sign + .split('+'); + + // define a constant order for the parts to appear in the hash + const parts_order = ["body", "eyes", "mouth", "arms"]; + + if (parts.length == parts_order.length) { + // convert the part names to part indices + parts = parts.map((name, i) => + Array.from(part_handlers[parts_order[i]].name_element.options).findIndex(x => x.value === name) + ); + if (parts.every(x => x != -1)) { + // all part names were found + parts.forEach((part_index, i) => part_handlers[parts_order[i]].setIndex(part_index)); + } + } + } + function randomize() { //Randomize which parts are shown for (const i in part_handlers) { part_handlers[i].randomize(); @@ -255,7 +283,9 @@ const NeomojiMixer = (function(NeomojiMixer) { ctx.clearRect(0, 0, canvas.width, canvas.height); - neomoji_name.value = part_handlers.body.getSelectedEntry()[0] + "_" + part_handlers.eyes.getSelectedEntry()[0] + "_" + part_handlers.mouth.getSelectedEntry()[0] + "_" + part_handlers.arms.getSelectedEntry()[0]; //Set name for the emoji to use as the image name and to show as shortcode + //Set name for the emoji to use as the image name and to show as shortcode + neomoji_name.innerText = part_handlers.body.getSelectedEntry()[0] + "_" + part_handlers.eyes.getSelectedEntry()[0] + "_" + part_handlers.mouth.getSelectedEntry()[0] + "_" + part_handlers.arms.getSelectedEntry()[0]; + neomoji_name.href = new URL("#" + part_handlers.body.getSelectedEntry()[0] + "+" + part_handlers.eyes.getSelectedEntry()[0] + "+" + part_handlers.mouth.getSelectedEntry()[0] + "+" + part_handlers.arms.getSelectedEntry()[0], document.location.href) let export_layers = [ part_handlers.body.createExportImage(), diff --git a/parts.json b/parts.json index 4872db1..661be64 100644 --- a/parts.json +++ b/parts.json @@ -13,7 +13,7 @@ {"name": "devil", "url": "/parts/eyes_devil.png"}, {"name": "drowsy", "url": "/parts/eyes_drowsy.png"}, {"name": "evil", "url": "/parts/eyes_evil.png"}, - {"name": ">_<", "url": "/parts/eyes_><.png"}, + {"name": ">_<", "url": "/parts/eyes_squint.png"}, {"name": "cry", "url": "/parts/eyes_cry.png"}, {"name": "owo", "url": "/parts/eyes_owo.png"}, {"name": "sad", "url": "/parts/eyes_sad.png"}, diff --git a/parts/eyes_><.png b/parts/eyes_squint.png similarity index 100% rename from parts/eyes_><.png rename to parts/eyes_squint.png