From 7f5a05c98780694c5295e802053bf6935f00d6a2 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 9 Jan 2024 20:57:37 +0000 Subject: [PATCH 1/2] feat: Display SVG icon for each class type in char --- assets/svg | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 assets/svg diff --git a/assets/svg b/assets/svg new file mode 100644 index 0000000..a0288d9 --- /dev/null +++ b/assets/svg @@ -0,0 +1,32 @@ +// No new file is created in this task. However, the 'wtf.js' file is modified as follows: + +// Import the 'fs' module at the top of the file +const fs = require('fs'); + +// Modify the 'generate' function +function generate() { + var type, text, part, iter = 0, // Safety mechanism + idea = randomItem( templates ), + item = regex.exec( idea ), + copy = cloneCorpus(); + + while ( item && ++iter < 1000 ) { + type = item[ 0 ]; + text = item[ 1 ]; + part = randomItem( copy[ text ], true ); + idea = idea.replace( type, part ); + regex.lastIndex = 0; + item = regex.exec( idea ); + } + + // Read the SVG file that corresponds to the class of the character + var svgIcon = fs.readFileSync(`assets/svg/${text}.svg`, 'utf8'); + + // Update output to include the SVG icon + dom.generate.text( randomItem( responses ) ); + dom.output.html('
' + idea + '.
' + svgIcon); + + // Toggle animation + setTimeout( showOutput, 0 ); + hideOutput(); +} From 6a156828516a01eb3b6e5f7c6fb874704fc07a3f Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 9 Jan 2024 20:58:35 +0000 Subject: [PATCH 2/2] feat: Updated scripts/wtf.js --- scripts/wtf.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/wtf.js b/scripts/wtf.js index 9d3952f..a4e2046 100644 --- a/scripts/wtf.js +++ b/scripts/wtf.js @@ -218,6 +218,7 @@ var WTF = (function() { var type, text, part, iter = 0, // Safety mechanism idea = randomItem( templates ), + icon = "assets/svg/" + text + ".svg"; item = regex.exec( idea ), copy = cloneCorpus(); @@ -228,6 +229,7 @@ var WTF = (function() { part = randomItem( copy[ text ], true ); idea = idea.replace( type, part ); + idea = idea.replace("@icon", icon); regex.lastIndex = 0; item = regex.exec( idea ); @@ -236,7 +238,7 @@ var WTF = (function() { // Update output dom.generate.text( randomItem( responses ) ); - dom.output.html('' + idea + '.
'); + dom.output.html('' + idea + '.