-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
37 lines (32 loc) · 1.08 KB
/
app.js
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
'use strict';
/* global XMLHttpRequest */
const path = document.location.pathname;
document.write(`It's working from path <b>${path}</b>`);
document.addEventListener('DOMContentLoaded', () => {
const tests = [
{ url: '/', name: 'index', re: /^<!DOCTYPE html>/ },
{ url: '/test', name: 'unexisting path', re: /^<!DOCTYPE html>/ },
{ url: '/file.txt', name: 'existing path', re: /^file/ }
];
const table = document.createElement('table');
const tbody = document.createElement('tbody');
table.appendChild(tbody);
document.body.appendChild(table);
tests.forEach((test) => {
const tr = document.createElement('tr');
tbody.appendChild(tr);
check(test.url, test.re, (res) => {
tr.innerHTML = `<td>${test.name}</td>`;
tr.innerHTML += `<td><a href="${test.url}">${test.url}</a></td>`;
tr.innerHTML += `<td class="${res}">${res}</td>`;
});
});
});
function check(url, re, cb) {
const xhr = new XMLHttpRequest();
xhr.addEventListener('load', () => {
cb(re.test(xhr.responseText) ? 'ok' : 'error');
});
xhr.open('GET', url);
xhr.send();
}