Inital Commit
This commit is contained in:
55
hex.vugu
Normal file
55
hex.vugu
Normal file
@@ -0,0 +1,55 @@
|
||||
<div class="container has-text-centered">
|
||||
<p class="title">
|
||||
Wasm Hex Converter
|
||||
</p>
|
||||
<div vg-if="c.TextToHex">
|
||||
<textarea vg-content='c.PlainText' @keyup="c.ToHex(event)" placeholder="Plaintext" rows="4" cols="50"></textarea>
|
||||
<div style="margin-bottom: 0.5rem;"></div>
|
||||
<textarea vg-content='c.HexString' placeholder="Hex" rows="4" cols="50"></textarea>
|
||||
</div>
|
||||
<div vg-if="c.HexToText">
|
||||
<textarea vg-content='c.HexString' @keyup="c.ToString(event)" placeholder="Hex" rows="4" cols="50"></textarea>
|
||||
<div style="margin-bottom: 0.5rem;"></div>
|
||||
<textarea vg-content='c.PlainText' placeholder="Plaintext" rows="4" cols="50"></textarea>
|
||||
</div>
|
||||
<a class="button is-light" @click="c.Swap(event)" style="margin-top: 0.5rem;">
|
||||
<span class="iconify" data-icon="heroicons-solid:refresh"></span> Swap
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<script type="application/x-go">
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
type Hex struct {
|
||||
HexString string `vugu:"data"`
|
||||
PlainText string `vugu:"data"`
|
||||
TextToHex bool `vugu:"data"`
|
||||
HexToText bool `vugu:"data"`
|
||||
}
|
||||
|
||||
func (c *Hex) Init() {
|
||||
c.TextToHex = true
|
||||
}
|
||||
|
||||
func (c *Hex) ToHex(event vugu.DOMEvent) {
|
||||
plaintext := event.PropString("target", "value")
|
||||
hexString := hex.EncodeToString([]byte(plaintext))
|
||||
c.PlainText = plaintext
|
||||
c.HexString = hexString
|
||||
}
|
||||
|
||||
func (c *Hex) ToString(event vugu.DOMEvent) {
|
||||
hexString := event.PropString("target", "value")
|
||||
plain, _ := hex.DecodeString(hexString)
|
||||
c.PlainText = string(plain)
|
||||
c.HexString = hexString
|
||||
}
|
||||
|
||||
func (c *Hex) Swap(event vugu.DOMEvent) {
|
||||
c.TextToHex, c.HexToText = !c.TextToHex, !c.HexToText
|
||||
}
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user