diff --git a/html/crafting.js b/html/crafting.js index 40b2223b4..bf58d3a29 100644 --- a/html/crafting.js +++ b/html/crafting.js @@ -26,15 +26,17 @@ $(function() { function onCraftingSelectorChanged() { var recipeName = $("#crafting_selector option:selected").val(); + var count = parseInt($("#crafting_count option:selected").val()); if (recipeName === undefined) return; + if (count === undefined) return; + + updatePageState(count, receipeName); var recipe = findRecipe(recipeName); if (recipe === undefined) { $("#crafting_error").html("Cannot find recipe for " + recipeName); $("#crafting_error").fadeIn(FADE_DURATION).delay(ERROR_DISPLAY_DURATION).fadeOut(FADE_DURATION); } else { - var count = parseInt($("#crafting_count option:selected").val()); - var inventory = createManifest(); var missingMaterials = createManifest(); for (var i = 0; i < count; i++) { @@ -129,6 +131,16 @@ function updateCraftingSelector() { } } +function updatePageState() { + var newTitle = "Crafting Guide: " + count + " " + recipeName; + var newLink = "?count=" + count + "&recipeName=" + encodeURIComponent(recipeName); + newLink = newLink.replace(/%20/g, "+"); + + document.title = newTitle; + history.pushState({count: count, name: recipeName}, newTitle, newLink); + ga('send', 'pageview'); +} + // Manifest Object //////////////////////////////////////////////////////////////////////////////////////////////////// function createManifest() {