-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·321 lines (279 loc) · 9.1 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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Link Checker</title>
</head>
<style>
body{
font-family: Arial, Arial, Helvetica, sans-serif;
background-color: #f3f3f3;
padding: 2em 0 3em 0;
}
h1{
margin-top: 0;
font-weight: normal;
}
h2{
margin-top: 0;
font-size: normal;
font-weight: 200;
color: #777;
}
.container{
width: 98%;
margin: 0 auto;
max-width: 1400px;
}
section{
padding: 2em;
background-color: #fff;
}
textarea{
box-sizing: border-box;
width: 100%;
height: 400px;
display: block;
margin-bottom: 1em;
border: 1px solid #999;
padding: 1em;
}
button{
font-size: 1.2em;
}
#result-table{
transition: all 1s linear;
opacity: 1;
margin-top: 1em;
}
#result-table.invisible{
opacity: 0;
}
table{
width: 100%;
border-collapse: collapse;
}
td{
border-bottom: 1px solid #ccc;
}
th{
text-align: left;
border-bottom: 4px solid #ccc;
text-transform: uppercase;
font-size: 0.8em;
letter-spacing: 0.1em;
}
td,
th{
padding: 0.5em;
}
tr.done td{
text-transform: uppercase;
font-weight: bold;
color: #fff;
background-color: #48b512;
}
th.header_code{
width: 100px;
}
/* coloring status codes */
.code_200,
tr.code_200 td{
background-color: #c6f9d2;
}
.code_301,
tr.code_301 td{
background-color: #f7f9c6;
}
.code_302,
tr.code_302 td{
background-color: #f9e1c6;
}
.code_401,
.code_404,
.code_500,
tr.code_401 td,
tr.code_404 td,
tr.code_500 td{
background-color: #f7a8a7;
}
.inline-status{
display: inline-block;
padding: 0 0.5em;
border: 2px solid #000;
box-shadow: 0px 0px 2px 0px rgba(0,0,0,0.75);
}
.final-status{
border-color: #fff;
position: relative;
padding-left: 5em;
}
.final-status::before{
content: "FINAL";
position: absolute;
left: 0;
top: 0;
bottom: 0;
height: 100%;
background-color: #000;
color: #fff;
padding: 0 0.5em;
}
/* navigation & tabs */
.navigation ul{
margin: 0;
padding: 0;
list-style-type: none;
display: flex;
}
.navigation li{
cursor: pointer;
padding: 1em;
margin-right: 0.3em;
background-color: #eee;
}
.navigation li.active{
background-color: #fff;
}
section.panel{
display: none;
}
section.panel.active{
display: block;
}
</style>
<body>
<div class="container">
<h1>Simple Link Checker <small>v0.2</small></h1>
<nav class="navigation">
<ul>
<li data-target="#probe_list" class="active">URL list</li>
<li data-target="#probe_sitemap">XML Sitemap</li>
</ul>
</nav>
<section id="probe_list" class="panel active">
<h2>Check URL list</h2>
<textarea name="urls_input_list" id="urls_input_list" cols="100" rows="30" placeholder="Paste URLs here, one per line"></textarea>
<button id="submit_list" class="submitbutton">Test URLs</button>
</section>
<section id="probe_sitemap" class="panel">
<h2>Check XML sitemap</h2>
<textarea name="urls_input_sitemap" id="urls_input_sitemap" cols="100" rows="30" placeholder="Paste contents of sitemap.xml here"></textarea>
<button id="submit_sitemap" class="submitbutton">Test URLs</button>
</section>
<section id="result-table" class="invisible">
<table>
<thead>
<tr>
<th class="header_url">Request URL</th>
<th class="header_code">Status</th>
<th class="header_target">Redirect target</th>
</tr>
</thead>
<tbody id="output">
<!-- will be populated via js -->
</tbody>
</table>
</section>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
// process url list
$('#submit_list').click(function(){
var rawinput = $('#urls_input_list').val();
// check if the user accidentally pasted a XML sitemap
if(rawinput.search("<?xml")!=-1){
alert('Did you accidentally paste XML contents in the wrong field? Please check ...');
return false;
}
// text lines to array
// Source: https://stackoverflow.com/questions/8479053/convert-textareas-string-value-to-javascript-array-separated-by-new-lines
var lines = rawinput.split(/\n/);
var urls = [];
for (var i=0; i < lines.length; i++) {
// only push this line if it contains a non whitespace character.
if (/\S/.test(lines[i])) {
urls.push($.trim(lines[i]));
}
}
probeUrls(urls);
});
// process url list
$('#submit_sitemap').click(function(){
var xmlstring = $('#urls_input_sitemap').val();
// get urls betwwen <loc> tags in XML
// Source: https://stackoverflow.com/questions/11592033/regex-match-text-between-tags
var urls = xmlstring.match(/<loc>(.*?)<\/loc>/g).map(function(val){
return val.replace(/<\/?loc>/g,'');
});
probeUrls(urls);
});
// tab navigation
$('.navigation li').click(function(){
// toggle classes in nav
$('.navigation li').removeClass('active');
$(this).addClass('active');
// toggle classes in sections
$('section').removeClass('active');
var target = $(this).data('target');
$(target).addClass('active');
});
});
// function for changing UI elements while probing (show results table, disable buttons and stuff...)
function changeUWhileRunning(){
// make table visible
$('#result-table.invisible').removeClass('invisible');
// clear table body (may contain results from previous run)
$('#output').html("");
// disable submit button
$('button.submitbutton').attr("disabled", "disabled");
}
// function for probing urls from a given array (send each to proxy)
function probeUrls(urls){
// changing UI while running
changeUWhileRunning();
// send ajax requests to all that
// source: https://stackoverflow.com/questions/24705401/jquery-ajax-with-array-of-urls
$.when.apply($, urls.map(function(url) {
return $.ajax({
type: 'POST',
url: 'proxy.php',
data: url,
dataType: 'text',
success: function(responseData, textStatus, jqXHR)
{
addRowToTable(responseData, textStatus, jqXHR);
},
error: function (responseData, textStatus, errorThrown)
{
console.warn(responseData, textStatus, errorThrown);
}
})
})).done(function() {
finished();
});
}
// function for adding result row to output table
function addRowToTable(responseData, textStatus, jqXHR){
response = JSON.parse(responseData);
console.log(response);
$('<tr class="code_'+response.status+'"><td>'+response.url+'</td><td>'+response.status+'</td><td>'+response.target+'</td></tr>').appendTo($('#output'));
// scroll to results table, last row (just added)
var results_offset_top = $('#result-table').offset().top;
var results_height = $('#result-table').height();
$('html, body').animate({
scrollTop: results_offset_top+results_height
}, 30);
}
// function for adding a final line at the end of the table
function finished(){
$('<tr class="done"><td colspan="3">Done</td></tr>').appendTo($('#output'));
// re-enable submit button
$('button.submitbutton').prop("disabled", false);
}
</script>
</body>
</html>