-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheck.php
More file actions
165 lines (159 loc) · 5.33 KB
/
Check.php
File metadata and controls
165 lines (159 loc) · 5.33 KB
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
<?php
include 'common.php';
include 'header.php';
include 'menu.php';
$stat = Typecho_Widget::widget('Widget_Stat');
$user = Typecho_Widget::widget('Widget_User');
if (!$user->pass('administrator')) {
die('未登录用户!');
}
?>
<head>
<style type="text/css">
.description {
margin: .5em 0 1em;
color: #999;
font-size: .92857em;
}
.main-content {
padding: 20px;
}
.check-button {
margin-bottom: 20px;
}
.invalid-links, .valid-links {
margin-top: 20px;
}
.invalid-links {
float: left;
width: 45%;
background: #ffe6e6;
padding: 10px;
border-radius: 5px;
}
.valid-links {
float: right;
width: 45%;
background: #e6ffe6;
padding: 10px;
border-radius: 5px;
}
.link-item {
margin-bottom: 10px;
}
.link-item a {
text-decoration: none;
}
.link-item button {
margin-left: 10px;
}
.loading {
text-align: center;
font-size: 1.2em;
color: #555;
}
</style>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script type="text/javascript">
var urls_arr = [];
var errurls_arr = [];
var validurls_arr = [];
var currentIndex = 0;
function check() {
$('.loading').show();
$.ajax({
type: "GET",
url: "/action/Linkdetection_action?action=links",
success: function(data) {
urls_arr = JSON.parse(data);
checkNext();
},
error: function() {
alert('无法获取友链数据,请稍后再试。');
$('.loading').hide();
}
});
}
function checkNext() {
if (currentIndex < urls_arr.length) {
var value = urls_arr[currentIndex];
$('#checking-status').text('正在检查: ' + value.name + ' (' + value.url + ')');
$.ajax({
type: "POST",
url: "/action/Linkdetection_action?action=check",
data: { url: value.url },
success: function(res) {
if (res !== '200') {
errurls_arr.push({ ...value, status: res });
} else {
validurls_arr.push(value);
}
currentIndex++;
updateDisplay();
checkNext();
},
error: function() {
errurls_arr.push({ ...value, status: '检查失败' });
currentIndex++;
updateDisplay();
checkNext();
}
});
} else {
$('#checking-status').text('检查完成');
$('.loading').hide();
$.ajax({
type: "POST",
url: "/action/Linkdetection_action?action=post",
dataType: "json",
data: { data: JSON.stringify(errurls_arr) },
});
}
}
function updateDisplay() {
var invalidLinksHtml = '';
errurls_arr.forEach(function(link) {
invalidLinksHtml += '<div class="link-item"><a href="' + link.url + '" target="_blank">' + link.name + '</a> 【' + link.status + '】 <button onclick="markInvalid(' + link.lid + ')">设为无效</button></div>';
});
$('.invalid-links').html(invalidLinksHtml);
var validLinksHtml = '';
validurls_arr.forEach(function(link) {
validLinksHtml += '<div class="link-item"><a href="' + link.url + '" target="_blank">' + link.name + '</a></div>';
});
$('.valid-links').html(validLinksHtml);
}
function markInvalid(lid) {
$.ajax({
type: "POST",
url: "/action/Linkdetection_action?action=del",
data: { data: JSON.stringify([lid]) },
success: function() {
errurls_arr = errurls_arr.filter(link => link.lid !== lid);
updateDisplay();
}
});
}
</script>
</head>
<div class="main">
<div class="body container">
<div class="typecho-page-title">
<h2>异常友链检查</h2>
</div>
<div class="main-content">
<button onclick="check()" class="btn primary check-button">立即检查</button>
<p class="description">如果友链较多,检查速度可能较慢</p>
<p id="checking-status"></p>
<div class="loading" style="display:none;">正在加载,请稍候...</div>
<div style="display: flow-root;">
<div class="invalid-links"></div>
<div class="valid-links"></div>
</div>
</div>
</div>
</div>
<?php
include 'copyright.php';
include 'common-js.php';
include 'footer.php';
?>