-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
130 lines (120 loc) · 4.15 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
#inputText,
#inputFile,
#inputHash {
width: 99%;
}
#inputText {
height: 80svh;
}
nav {
position: sticky;
top: 0;
}
nav>ul {
display: flex;
margin: 0;
padding: 0;
list-style: none;
}
nav>ul>li {
margin-left: auto;
margin-right: auto;
}
main {
text-align: center;
word-break: break-all;
}
/*main>div {
min-height: 100svh;
padding-top: 10svh;
}*/
</style>
<title>Dao3 Static 工具</title>
</head>
<body>
<main>
<h1>Dao3 Static 工具</h1>
<h2 id="getFile">获取文件</h2>
<div>
<p>粘贴以Qm开头的Key。如果获取文本请加上后缀名“.json”,图片、视频等无需加后缀名</p>
<input id="inputHash" type="text" placeholder="Qmxxxxxxxxxx(.json)"><br>
<button id="getFileButton">获取</button>
</div>
<h2 id="postText">上传文本</h2>
<div>
<textarea id="inputText"></textarea><br />
<button id="postTextButton">上传</button>
</div>
<h2 id="postFile">上传文件</h2>
<div>
<input id="inputFile" type="file" multiple="false"><br />
</div>
<h2 id="result">上传记录</h2>
<div></div>
</main>
<script type="module">
import { getStorage } from "./storage.js";
import { Static } from "./static.js";
const storage = getStorage("dao3StaticTool");
const dao3Static = new Static("https://static.dao3.fun/block/");
const inputText = document.getElementById("inputText");
const inputFile = document.getElementById("inputFile");
const getFileButton = document.getElementById("getFileButton");
const postTextButton = document.getElementById("postTextButton");
inputText.value = storage.inputText ?? "";
const resultDisplay = document.querySelector("#result+div");
if (!storage.results) {
storage.results = [];
}
function refreshResult() {
resultDisplay.innerHTML = "";
for (const data of storage.results.slice(0, 20)) {
const div = document.createElement("div");
const time = document.createElement("b");
time.textContent = new Date(data.time).toLocaleString();
div.appendChild(time);
div.appendChild(document.createElement("br"));
const result = document.createElement("code");
result.textContent = JSON.stringify(data.result);
div.appendChild(result);
resultDisplay.appendChild(div);
}
}
inputText.addEventListener("change", function () {
storage.inputText = inputText.value;
});
getFileButton.addEventListener("click", function () {
const hash = document.getElementById("inputHash").value;
if (!/Qm.*/.test(hash)) return;
open(dao3Static.get(hash), "_blank");
});
async function post(data) {
const resultData = await dao3Static.post(data);
storage.results.unshift({
time: Date.now(),
result: resultData
});
prompt(JSON.stringify(resultData), resultData.Key);
refreshResult();
//location.hash = "#result";
}
inputFile.addEventListener("change", async function postFile() {
const file = inputFile.files[0];
await post(file);
});
postTextButton.addEventListener("click", async function () {
const text = document.getElementById("inputText");
const data = text.value;
if (data.length === 0) return;
await post(data);
});
refreshResult();
</script>
</body>
</html>