diff --git a/src/web/Manager.mjs b/src/web/Manager.mjs index 9c8bbc47..d33616a4 100755 --- a/src/web/Manager.mjs +++ b/src/web/Manager.mjs @@ -158,6 +158,7 @@ class Manager { document.getElementById("switch").addEventListener("click", this.output.switchClick.bind(this.output)); document.getElementById("undo-switch").addEventListener("click", this.output.undoSwitchClick.bind(this.output)); document.getElementById("maximise-output").addEventListener("click", this.output.maximiseOutputClick.bind(this.output)); + document.getElementById("magic").addEventListener("click", this.output.magicClick.bind(this.output)); document.getElementById("output-text").addEventListener("scroll", this.highlighter.outputScroll.bind(this.highlighter)); document.getElementById("output-text").addEventListener("mouseup", this.highlighter.outputMouseup.bind(this.highlighter)); document.getElementById("output-text").addEventListener("mousemove", this.highlighter.outputMousemove.bind(this.highlighter)); diff --git a/src/web/OutputWaiter.mjs b/src/web/OutputWaiter.mjs index e6076ae2..0ef5b248 100755 --- a/src/web/OutputWaiter.mjs +++ b/src/web/OutputWaiter.mjs @@ -422,6 +422,7 @@ class OutputWaiter { * Triggers the BackgroundWorker to attempt Magic on the current output. */ backgroundMagic() { + this.hideMagicButton(); const sample = this.dishStr ? this.dishStr.slice(0, 1000) : this.dishBuffer ? this.dishBuffer.slice(0, 1000) : ""; @@ -441,16 +442,57 @@ class OutputWaiter { !options[0].recipe.length) return; - //console.log(options); - const currentRecipeConfig = this.app.getRecipeConfig(); const newRecipeConfig = currentRecipeConfig.concat(options[0].recipe); const recipeURL = "#recipe=" + Utils.encodeURIFragment(Utils.generatePrettyRecipe(newRecipeConfig)); const opSequence = options[0].recipe.map(o => o.op).join(", "); log.log(`Running ${opSequence} will result in "${Utils.truncate(options[0].data, 20)}"`); - //this.app.setRecipeConfig(newRecipeConfig); - //this.app.autoBake(); + + this.showMagicButton(opSequence, options[0].data, newRecipeConfig); + } + + + /** + * Handler for Magic click events. + * + * Loads the Magic recipe. + * + * @fires Manager#statechange + */ + magicClick() { + const magicButton = document.getElementById("magic"); + this.app.setRecipeConfig(JSON.parse(magicButton.getAttribute("data-recipe"))); + window.dispatchEvent(this.manager.statechange); + this.hideMagicButton(); + } + + + /** + * Displays the Magic button with a title and adds a link to a complete recipe. + * + * @param {string} opSequence + * @param {string} result + * @param {Object[]} recipeConfig + */ + showMagicButton(opSequence, result, recipeConfig) { + const magicButton = document.getElementById("magic"); + magicButton.setAttribute("data-original-title", `Running ${opSequence} will result in "${Utils.truncate(result, 20)}"`); + magicButton.setAttribute("data-recipe", JSON.stringify(recipeConfig), null, ""); + magicButton.style.visibility = "visible"; + magicButton.style.opacity = 1; + } + + + /** + * Hides the Magic button and resets its values. + */ + hideMagicButton() { + const magicButton = document.getElementById("magic"); + magicButton.style.visibility = "hidden"; + magicButton.style.opacity = 0; + magicButton.setAttribute("data-recipe", ""); + magicButton.setAttribute("data-original-title", "Magic!"); } } diff --git a/src/web/html/index.html b/src/web/html/index.html index a7bcd1e9..9cd7a7a7 100755 --- a/src/web/html/index.html +++ b/src/web/html/index.html @@ -278,8 +278,10 @@
- access_time diff --git a/src/web/stylesheets/layout/_io.css b/src/web/stylesheets/layout/_io.css index 21d762a0..24c5db02 100755 --- a/src/web/stylesheets/layout/_io.css +++ b/src/web/stylesheets/layout/_io.css @@ -148,6 +148,12 @@ } #magic { + visibility: hidden; + transition: all 0.3s; margin-left: 5px; - display: none; + margin-bottom: 5px; +} + +#magic svg path { + fill: var(--primary-font-colour); } diff --git a/src/web/stylesheets/utils/_overrides.css b/src/web/stylesheets/utils/_overrides.css index 6de920ca..4182ae83 100755 --- a/src/web/stylesheets/utils/_overrides.css +++ b/src/web/stylesheets/utils/_overrides.css @@ -13,7 +13,7 @@ font-family: 'Material Icons'; font-style: normal; font-weight: 400; - src: local('Material Icons'), local('MaterialIcons-Regular'), url(https://fonts.gstatic.com/s/materialicons/v17/2fcrYFNaTjcS6g4U3t-Y5ZjZjT5FdEJ140U2DJYC3mY.woff2) format('woff2'); + src: url("../static/fonts/MaterialIcons-Regular.woff2") format('woff2'); } .material-icons {