-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
289 lines (247 loc) · 11.2 KB
/
index.html
File metadata and controls
289 lines (247 loc) · 11.2 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web Anyliser</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Inter:wght@400;600;700;800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
</head>
<body>
<button class="theme-toggle" id="themeToggle" type="button" aria-label="Switch to light theme" title="Switch to light theme">Light</button>
<div class="container">
<header>
<div class="brand">Web Anyliser</div>
<h1>Check every <span>link & image</span></h1>
<p class="subtitle">Audit broken links and missing images on any webpage.</p>
</header>
<div class="search-bar">
<input type="text" id="urlInput" placeholder="https://example.com" autocomplete="off">
<button class="btn" id="scanBtn">Scan</button>
</div>
<div class="alert" id="alertBox"></div>
<div class="loader" id="loader">
<div class="spinner"></div>
<p>Scanning links & images…</p>
</div>
<div class="stats fade-in" id="stats">
<div class="stats-grid">
<div class="stat-card">
<span class="stat-num" id="s-total">—</span>
<span class="stat-label">Total</span>
</div>
<div class="stat-card">
<span class="stat-num green" id="s-working">—</span>
<span class="stat-label">Working</span>
</div>
<div class="stat-card">
<span class="stat-num red" id="s-broken">—</span>
<span class="stat-label">Broken</span>
</div>
<div class="stat-card">
<span class="stat-num purple" id="s-health">—</span>
<span class="stat-label">Health</span>
</div>
</div>
</div>
<div class="health-bar fade-in" id="healthBar">
<div class="health-bar-top">
<span>Health Score</span>
<span class="health-pct" id="healthPct">0%</span>
</div>
<div class="health-track">
<div class="health-fill" id="healthFill"></div>
</div>
</div>
<div class="img-stats fade-in" id="imgStats">
<div class="stat-card">
<span class="stat-num" id="is-total">—</span>
<span class="stat-label">Images</span>
</div>
<div class="stat-card">
<span class="stat-num green" id="is-working">—</span>
<span class="stat-label">Loading</span>
</div>
<div class="stat-card">
<span class="stat-num red" id="is-broken">—</span>
<span class="stat-label">Broken</span>
</div>
</div>
<div class="toolbar fade-in" id="toolbar">
<button class="tab-btn active" data-tab="links">Links</button>
<button class="tab-btn" data-tab="images">Images</button>
<div class="separator"></div>
<button class="filter-btn active" data-filter="all">All</button>
<button class="filter-btn" data-filter="ok">Working</button>
<button class="filter-btn" data-filter="broken">Broken</button>
<button class="csv-btn" id="csvBtn">Export CSV</button>
</div>
<div id="resultsList"></div>
</div>
<footer>
<p>
<a href="https://github.com/JaivPatel07/LINK-CHECKER" target="_blank" rel="noopener" class="source-link">
<svg viewBox="0 0 24 24" width="15" height="15" aria-hidden="true" focusable="false">
<path fill="currentColor" d="M12 0.3a12 12 0 0 0-3.79 23.38c0.6 0.11 0.82-0.26 0.82-0.58v-2.02c-3.34 0.73-4.04-1.42-4.04-1.42-0.55-1.38-1.33-1.75-1.33-1.75-1.09-0.74 0.08-0.73 0.08-0.73 1.2 0.08 1.84 1.22 1.84 1.22 1.08 1.82 2.84 1.3 3.53 0.99 0.11-0.77 0.42-1.3 0.77-1.6-2.67-0.3-5.47-1.32-5.47-5.88 0-1.3 0.47-2.37 1.23-3.2-0.12-0.3-0.53-1.53 0.12-3.18 0 0 1.01-0.32 3.3 1.22a11.6 11.6 0 0 1 6.01 0c2.29-1.54 3.29-1.22 3.29-1.22 0.66 1.66 0.25 2.89 0.12 3.18 0.77 0.83 1.23 1.9 1.23 3.2 0 4.57-2.8 5.58-5.48 5.87 0.43 0.37 0.82 1.1 0.82 2.23v3.3c0 0.32 0.22 0.7 0.83 0.58A12 12 0 0 0 12 0.3Z"/>
</svg>
<span>Source</span>
</a>
</p>
</footer>
<script>
const $ = id => document.getElementById(id);
let allLinks = [], allImages = [];
let activeTab = 'links', activeFilter = 'all';
const THEME_KEY = 'web-anyliser-theme';
function applyTheme(theme) {
const isLight = theme === 'light';
document.body.classList.toggle('light-theme', isLight);
const toggle = $('themeToggle');
toggle.textContent = isLight ? 'Dark' : 'Light';
toggle.setAttribute('aria-label', isLight ? 'Switch to dark theme' : 'Switch to light theme');
toggle.setAttribute('title', isLight ? 'Switch to dark theme' : 'Switch to light theme');
}
function initTheme() {
const saved = localStorage.getItem(THEME_KEY);
if (saved === 'light' || saved === 'dark') {
applyTheme(saved);
return;
}
const prefersLight = window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches;
applyTheme(prefersLight ? 'light' : 'dark');
}
function toggleTheme() {
const nextTheme = document.body.classList.contains('light-theme') ? 'dark' : 'light';
applyTheme(nextTheme);
localStorage.setItem(THEME_KEY, nextTheme);
}
function escapeHtml(s) {
return String(s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
}
function statusClass(item) {
if (item.ok) return 'ok';
if (typeof item.status === 'number' && item.status >= 300 && item.status < 400) return 'warn';
return 'broken';
}
function showAlert(msg) {
$('alertBox').textContent = msg;
$('alertBox').style.display = 'block';
}
function hideAlert() { $('alertBox').style.display = 'none'; }
function renderList(items) {
const list = $('resultsList');
const filtered = activeFilter === 'all'
? items
: items.filter(i => activeFilter === 'ok' ? i.ok : !i.ok);
if (!filtered.length) {
list.innerHTML = '<div class="empty">No items match this filter.</div>';
list.style.display = 'block';
return;
}
list.innerHTML = filtered.map(item => {
const cls = statusClass(item);
const t = item.time_ms ? `<span class="time">${item.time_ms}ms</span>` : '';
return `<div class="result-item">
<div class="dot ${cls}"></div>
<a href="${escapeHtml(item.url)}" target="_blank" rel="noopener" class="url-text" title="${escapeHtml(item.url)}">${escapeHtml(item.url)}</a>
${t}<span class="badge ${cls}">${item.status} ${item.label}</span>
</div>`;
}).join('');
list.style.display = 'block';
}
function setHealthBar(pct) {
const fill = $('healthFill');
const color = pct >= 80 ? 'var(--green)' : pct >= 50 ? 'var(--warn)' : 'var(--red)';
fill.style.background = color;
setTimeout(() => {
fill.style.width = pct + '%';
$('healthPct').textContent = pct + '%';
}, 50);
}
async function scan() {
const raw = $('urlInput').value.trim();
if (!raw) { showAlert('Please enter a URL.'); return; }
hideAlert();
const url = raw.startsWith('http') ? raw : 'https://' + raw;
$('stats').style.display = 'none';
$('healthBar').style.display = 'none';
$('imgStats').style.display = 'none';
$('toolbar').style.display = 'none';
$('resultsList').style.display = 'none';
$('resultsList').innerHTML = '';
$('loader').style.display = 'block';
$('scanBtn').disabled = true;
$('healthFill').style.width = '0%';
activeFilter = 'all';
try {
const res = await fetch('http://localhost:5000/check', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url })
});
const data = await res.json();
if (data.error) { showAlert(data.error); return; }
allLinks = data.links || [];
allImages = data.images || [];
$('s-total').textContent = data.total;
$('s-working').textContent = data.working;
$('s-broken').textContent = data.broken;
$('s-health').textContent = data.health + '%';
$('stats').style.display = 'block';
setHealthBar(data.health);
$('healthBar').style.display = 'block';
if (data.image_stats) {
$('is-total').textContent = data.image_stats.total;
$('is-working').textContent = data.image_stats.working;
$('is-broken').textContent = data.image_stats.broken;
$('imgStats').style.display = 'grid';
}
$('toolbar').style.display = 'flex';
activeTab = 'links';
document.querySelectorAll('.tab-btn').forEach((b, i) => b.classList.toggle('active', i === 0));
document.querySelectorAll('.filter-btn').forEach((b, i) => b.classList.toggle('active', i === 0));
renderList(allLinks);
} catch {
showAlert('Cannot reach API. Make sure api.py is running on port 5000.');
} finally {
$('loader').style.display = 'none';
$('scanBtn').disabled = false;
}
}
function exportCSV() {
const items = activeTab === 'links' ? allLinks : allImages;
if (!items.length) return;
const rows = ['URL,Status,Label,OK,Response(ms)'];
items.forEach(i => rows.push(`"${i.url}",${i.status},${i.label},${i.ok},${i.time_ms || ''}`));
const blob = new Blob([rows.join('\n')], { type: 'text/csv' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = `web-anyliser-${activeTab}-${new Date().toISOString().slice(0,10)}.csv`;
a.click();
URL.revokeObjectURL(a.href);
}
$('scanBtn').addEventListener('click', scan);
$('urlInput').addEventListener('keydown', e => { if (e.key === 'Enter') scan(); });
$('csvBtn').addEventListener('click', exportCSV);
$('themeToggle').addEventListener('click', toggleTheme);
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.addEventListener('click', () => {
activeTab = btn.dataset.tab;
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
renderList(activeTab === 'links' ? allLinks : allImages);
});
});
document.querySelectorAll('.filter-btn').forEach(btn => {
btn.addEventListener('click', () => {
activeFilter = btn.dataset.filter;
document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
renderList(activeTab === 'links' ? allLinks : allImages);
});
});
initTheme();
</script>
</body>
</html>