-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.html
177 lines (160 loc) · 6.89 KB
/
home.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>在线编辑工具</title>
<script type="text/javascript" src="./js/jquery.min.js"></script>
<script type="text/javascript" src="./js/codemirror.min.js"></script>
<script type="text/javascript" src="./js/comment.js"></script>
<script type="text/javascript" src="./js/shell.js"></script>
<script type="text/javascript" src="./js/sublime.js"></script>
<script type="text/javascript" src="./js/sweetalert2.js"></script>
<script type="text/javascript" src="./js/qrcode.min.js"></script>
<link rel="stylesheet" type="text/css" href="./css/codemirror.min.css">
<link rel="stylesheet" type="text/css" href="./css/twilight.css">
<link rel="stylesheet" type="text/css" href="./css/dracula.css">
<link rel="stylesheet" type="text/css" href="./css/main.css">
</head>
<body>
<div class="container">
<div class="diffs">
<nav>
<ul>
<li class="active"><a href="./home">配置设定</a></li>
<li><a href="./crontab">定时设定</a></li>
<li><a href="./diff">对比工具</a></li>
<li><a href="./diy">自定义脚本</a></li>
<li><a href="./run">手动执行</a></li>
<li><a href="./terminal">终端</a></li>
<li><a href="./log">日志查询</a></li>
<li><a href="./viewScripts">查看脚本</a></li>
<li><a href="./changepwd">修改密码</a></li>
<li><a href="./logout">退出</a></li>
</ul>
</nav>
<header>
<h1>在线编辑工具</h1>
<button id="save" title="保存">保存 config.sh</button>
<button id="wrap" title="切换换行">切换换行</button>
<button id="cookietools" title="手机扫描二维码登录">扫码获取Cookie</button>
</header>
<h4>config.sh</h4>
<div class="wrapper">
<textarea id="code" name="code"></textarea>
</div>
</div>
</div>
<div id="qrcontainer" class="hidden">
<div class="qframe">
<div id="refresh_qrcode" class="hidden">
<div>
<h3>二维码已失效</h3>
<div class="refresh">刷新</div>
</div>
</div>
<div id="qrcode"></div>
<div class="info">请使用京东手机APP扫码</div>
<div class="qframe-close" title="关闭">✖</div>
</div>
</div>
<script>
$.ajaxSetup({ cache: false });
var qrcode, userCookie;
$(document).ready(function () {
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
lineWrapping: true,
styleActiveLine: true,
matchBrackets: true,
mode: 'shell',
theme: 'dracula',
keyMap: 'sublime'
});
$.get('./api/config/config', function (data) {
editor.setValue(data);
});
qrcode = new QRCode(document.getElementById("qrcode"),
{
text: "sample",
correctLevel: QRCode.CorrectLevel.L
});
function copyToClip(content, message) {
var aux = document.createElement("input");
aux.setAttribute("value", content);
document.body.appendChild(aux);
aux.select();
document.execCommand("copy");
document.body.removeChild(aux);
}
function checkLogin() {
var timeId = setInterval(() => {
let timeStamp = (new Date()).getTime()
$.get('./cookie?t='+timeStamp, function (data) {
if (data.err == 0) {
clearInterval(timeId);
$("#qrcontainer").addClass("hidden");
$("#refresh_qrcode").addClass("hidden");
userCookie = data.cookie
Swal.fire({
title: "cookie已获取",
html:
'<div class="cookieCon" style="font-size:12px;">' + userCookie + '</div>',
text: userCookie,
icon: "success",
confirmButtonText: "复制",
}).then((result) => {
copyToClip(userCookie);
})
} else if (data.err == 21) {
clearInterval(timeId);
$("#refresh_qrcode").removeClass("hidden");
}
})
}, 3000)
}
function get_code() {
let timeStamp = (new Date()).getTime()
$.get('./qrcode?t='+timeStamp, function (data) {
if (data.err == 0) {
$("#qrcontainer").removeClass("hidden")
$("#refresh_qrcode").addClass("hidden")
qrcode.clear();
qrcode.makeCode(data.qrcode);
checkLogin();
} else {
Swal.fire({
text: data.msg,
icon: "error"
})
}
});
}
$('.refresh').click(get_code);
$('#cookietools').click(get_code);
$('.qframe-close').click(function () {
$("#qrcontainer").addClass("hidden");
$("#refresh_qrcode").addClass("hidden");
});
$('#save').click(function () {
var confContent = editor.getValue();
let timeStamp = (new Date()).getTime()
$.post('./api/save?t='+timeStamp, { content: confContent, name: "config.sh" }, function (data) {
let icon = (data.err == 0) ? "success" : "error"
Swal.fire({
title:data.title,
text: data.msg,
icon: icon
}).then((result) => {
window.location.reload(true);
})
});
});
$('#wrap').click(function () {
var lineWrapping = editor.getOption('lineWrapping');
editor.setOption('lineWrapping', !lineWrapping);
});
});
</script>
</body>
</html>