Skip to content

Commit

Permalink
show xray version, remove bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmray committed Sep 18, 2024
1 parent 12bc622 commit 06440c7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 34 deletions.
39 changes: 28 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,44 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Xray Config Validator</title>

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js"></script>
<script src="wasm_exec.js"></script>
<script>
const isReady = new Promise((resolve) => {
window.onWasmInitialized = resolve;
});

const go = new Go();
WebAssembly.instantiateStreaming(
fetch('main.wasm'),
go.importObject
).then((result) => {

(async () => {
const result = await WebAssembly.instantiateStreaming(fetch('main.wasm'), go.importObject);
go.run(result.instance);
});
await isReady;
document.getElementById("version-info").innerText = `Xray version ${XrayGetVersion()}`;
})()
</script>
<style>
* {
box-sizing: border-box;
}
html, body {
height: 100%;
padding: 0;
margin: 0;
background-color: #f8f9fa;
display: flex;
flex-direction: column;
font-family: system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue","Noto Sans","Liberation Sans",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";
}

.container {
width: 100%;
flex: 1;
display: flex;
flex-direction: column;
max-width: 800px;
margin: 0 auto;
padding: 20px;
box-sizing: border-box;
}

#editor {
Expand Down Expand Up @@ -73,17 +80,27 @@
color: #856404;
}

#nav a {
float: right;
#nav {
text-align: right;
}

h1 {
font-size: 2.5rem;
margin-bottom: 1.5rem;
font-weight: 500;
line-height: 1.2;
margin-top: 0;
text-align: center;
}
</style>
</head>

<body>
<div class="container">
<nav id="nav">
<span id="version-info">Loading Xray</span> |
<a href="https://github.com/mmmray/xray-online">GitHub</a>
<h1 class="text-center mb-4">Xray Config Validator</h1>
<h1>Xray Config Validator</h1>
</nav>
<div id="editor"></div>
<div id="output">Start typing your Xray config in the editor above.</div>
Expand Down
54 changes: 31 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package main

import (
"fmt"
"strings"
"syscall/js"
"encoding/json"
"bytes"
"io"
_ "embed"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"strings"
"syscall/js"

"github.com/xtls/xray-core/infra/conf"
"github.com/xtls/xray-core/common/platform/filesystem"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/platform/filesystem"
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/infra/conf"
json_reader "github.com/xtls/xray-core/infra/conf/json"
)

//go:embed geoip.dat
var geoipRaw []byte

//go:embed geosite.dat
var geositeRaw []byte

Expand All @@ -34,17 +36,21 @@ func main() {
return nil, errors.New(path + " cannot be opened in the browser")
}

js.Global().Set("XrayParseConfig", js.FuncOf(func(this js.Value, args []js.Value) any {
if len(args) < 1 {
fmt.Println("invalid number of args")
return nil
}
js.Global().Set("XrayGetVersion", js.FuncOf(func(this js.Value, args []js.Value) any {
return core.Version()
}))

arg := args[0]
if arg.Type() != js.TypeString {
fmt.Println("the argument should be a string")
return nil
}
js.Global().Set("XrayParseConfig", js.FuncOf(func(this js.Value, args []js.Value) any {
if len(args) < 1 {
fmt.Println("invalid number of args")
return nil
}

arg := args[0]
if arg.Type() != js.TypeString {
fmt.Println("the argument should be a string")
return nil
}

jsonConfig := &conf.Config{}
jsonReader := &json_reader.Reader{
Expand All @@ -61,11 +67,13 @@ func main() {
}

return nil
}))
}))

js.Global().Get("onWasmInitialized").Invoke()

// Prevent the program from exiting.
// Note: the exported func should be released if you don't need it any more,
// and let the program exit after then. To simplify this demo, this is
// omitted. See https://pkg.go.dev/syscall/js#Func.Release for more information.
select {}
// Prevent the program from exiting.
// Note: the exported func should be released if you don't need it any more,
// and let the program exit after then. To simplify this demo, this is
// omitted. See https://pkg.go.dev/syscall/js#Func.Release for more information.
select {}
}

0 comments on commit 06440c7

Please sign in to comment.