-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e00f2c
commit 779c9aa
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/.gitattributes | ||
/jsstp.min.js | ||
/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>Sample</title> | ||
<!-- 引用"jsstp.js"文件 --> | ||
<script type="text/javascript" src="./jsstp.min.js"></script> | ||
<script> | ||
// 获取输入框的值并转换为object,如有报错则弹窗 | ||
function getjson() { | ||
try { | ||
return JSON.parse(document.getElementById("json").value); | ||
} catch (e) { | ||
alert(e); | ||
} | ||
} | ||
function gettype() { | ||
return document.getElementById("type").value; | ||
} | ||
function send() { | ||
return jsstp[gettype()](getjson()).then((result) => { | ||
// 设置回显框的值 | ||
document.getElementById("result").value = JSON.stringify(result, null, "\t"); | ||
}); | ||
} | ||
// 解析并处理url参数 | ||
async function args_handler() { | ||
// 获取url参数 | ||
let args = location.search; | ||
// 如果没有参数则返回 | ||
if (!args) return; | ||
// 去掉开头的"?"并分割参数 | ||
args = args.substring(1).split("&"); | ||
// 遍历参数并存于map | ||
let argv = {}; | ||
args.forEach((pair)=>{ | ||
pair = pair.split("="); | ||
// 对参数值解码 | ||
argv[pair[0]] = decodeURIComponent(pair[1]); | ||
}); | ||
// 如果有"json"参数则设置输入框的值 | ||
if (argv.json) | ||
document.getElementById("json").value = argv.json; | ||
// 如果有"type"参数则设置下拉选单的值 | ||
if (argv.type) | ||
document.getElementById("type").value = argv.type; | ||
// 如果有"send"参数则调用send函数 | ||
if (argv.send) | ||
await send().catch((e)=>{}); | ||
// 如果有"jumpback"参数则跳转到该参数指定的url | ||
if (argv.jumpback) | ||
window.location = argv.jumpback; | ||
} | ||
args_handler(); | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<h1>Sample</h1> | ||
<!-- 一个下拉选单,用于选择sstp类型 --> | ||
<select id="type"> | ||
<option value="NOTIFY">NOTIFY</option> | ||
<option value="SEND">SEND</option> | ||
<option value="COMMUNICATE">COMMUNICATE</option> | ||
<option value="EXECUTE">EXECUTE</option> | ||
<option value="GIVE">GIVE</option> | ||
</select> | ||
<br> | ||
<!-- 一个多行的有默认内容的输入框 --> | ||
<textarea id="json" cols="50" rows="10"> | ||
{ | ||
"Event": "OnTest", | ||
"Script": "\\0Hello, World!\\e" | ||
} | ||
</textarea> | ||
<br> | ||
<button onclick="send()">send</button> | ||
<br> | ||
<!-- 用于回显的不可编辑的多行输入框 --> | ||
<textarea id="result" cols="50" rows="10" readonly></textarea> | ||
<br> | ||
<br> | ||
<!-- github link --> | ||
<a href="https://github.com/ukatech/jsstp-lib">github: jsstp-lib</a> | ||
<br> | ||
made by <a href="https://github.com/ukatech/">ukatecher</a> with (buggy) love. | ||
</body> | ||
|
||
</html> |