Skip to content

Commit

Permalink
修正HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
smilelc3 committed Oct 20, 2024
1 parent e3e5ac3 commit 30558af
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 47 deletions.
3 changes: 0 additions & 3 deletions js/Hex2Ascii.js

This file was deleted.

3 changes: 0 additions & 3 deletions js/Hex2Ascii.wasm

This file was deleted.

3 changes: 3 additions & 0 deletions js/MyLittleTool.js
Git LFS file not shown
3 changes: 3 additions & 0 deletions js/MyLittleTool.wasm
Git LFS file not shown
78 changes: 37 additions & 41 deletions markdown/小工具集合.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,67 @@ title: 小工具集合
date: 2024-10-20
---


# 小工具集合

基于项目 ,并使用 wasm 技术实现 JavaScript 调用 C/C++
基于项目 [smilelc3/MyLittleTool](https://github.com/smilelc3/MyLittleTool),并使用 [wasm](https://developer.mozilla.org/zh-CN/docs/WebAssembly/C_to_Wasm) 技术实现 `JavaScript` 调用 `C/C++`

---

{% raw %}
<div class="tool-section" id="Hex2Ascii">
<h2>16进制转字符串(Hex2Ascii)</h2>
<h3>16进制转字符串</h3>
<input type="text" placeholder="输入16进制,例如: 0x68 0x65 0x6c 0x6c 0x6f" id="inHexStr" />
<button onclick="Hex2Ascii('inHexStr', 'outAsciiStr')">提交</button>
<button onclick="summit('Hex2Ascii' 'inHexStr', 'outAsciiStr')">提交</button>
<div class="output" id="outAsciiStr"></div>
</div>

---
<hr>

<div class="tool-section" id="echo2">
<h2>Echo 2</h2>
<input type="text" placeholder="输入字符串" id="input2" />
<button onclick="submitEcho('input2', 'output2')">提交</button>
<div class="output" id="output2"></div>
<div class="tool-section" id="Ascii2Hex">
<h3>字符串转16进制</h3>
<input type="text" placeholder="输入字符串" id="inAsciiStr" />
<button onclick="summit('Ascii2Hex' 'inAsciiStr', 'outHexStr')">提交</button>
<div class="output" id="outHexStr"></div>
</div>

---
<hr>

<div class="echo-section" id="echo3">
<h2>Echo 3</h2>
<input type="text" placeholder="输入字符串" id="input3" />
<button onclick="submitEcho('input3', 'output3')">提交</button>
<div class="output" id="output3"></div>
<div class="echo-section" id="Linea11Trans">
<h3>Linear11 格式转换实数</h3>
<input type="text" placeholder="输入Linear11格式数,如:0x00dc" id="inLinear11" />
<button onclick="summit('Linea11Trans', 'inLinear11', 'outReal')">提交</button>
<div class="output" id="outReal"></div>
</div>

---
<hr>

<script src="/js/Hex2Ascii.js"></script>
<script src="/js/MyLittleTool.js"></script>
<script>
let C_Hex2Ascii;

let C_Hex2Ascii, C_Ascii2Hex, C_Linear11Trans;
// 等待 wasm 模块加载
Module.onRuntimeInitialized = async () => {
C_Hex2Ascii = Module.cwrap('C_Hex2Ascii', 'string', ['string']);
C_Ascii2Hex = Module.cwrap('C_Ascii2Hex', 'string', ['string']);
C_Linear11Trans = Module.cwrap('C_Linear11Trans', 'string', ['string']);
};

function Hex2Ascii(inputId, outputId) {
// 调用 wasm 中导出的函数
function summit(funcName, inputId, outputId) {
const input = document.getElementById(inputId).value;
const output = C_Hex2Ascii(input);
let output;
switch (funcName) {
case 'Hex2Ascii':
output = C_Hex2Ascii(input);
break;
case 'Ascii2Hex':
output = C_Ascii2Hex(input);
break;
case 'Linea11Trans':
output = C_Linear11Trans(input);
break;
}
document.getElementById(outputId).innerText = `输出: ${output}`;
}
</script>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
color: #333;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
h1 {
color: #4CAF50;
}


input[type="text"] {
width: 100%;
padding: 10px;
Expand All @@ -94,5 +90,5 @@ date: 2024-10-20
font-weight: bold;
padding-top: 10px;
}

</style>
</style>
{% endraw %}

0 comments on commit 30558af

Please sign in to comment.