-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
763 lines (686 loc) · 26.4 KB
/
Copy pathindex.html
File metadata and controls
763 lines (686 loc) · 26.4 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
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Link Inspector - check a URL before you click it</title>
<meta name="description" content="Paste any link and get a plain-language safety report. Runs entirely in your browser — nothing is sent anywhere.">
<style>
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;0,500;0,600;0,700;1,400&family=IBM+Plex+Serif:ital,wght@0,400;0,500;0,600;1,400&display=swap');
:root{
--paper: #f1ead7;
--paper-dark: #e6dcc3;
--ink: #18140f;
--ink-soft: #4a4338;
--line: #cdbf9c;
--stamp-red: #a3322a;
--stamp-green: #3f5d3a;
--stamp-amber: #a9701e;
--paper-shadow: rgba(24,20,15,0.18);
}
*{box-sizing:border-box;}
html,body{margin:0;padding:0;}
body{
background:
radial-gradient(ellipse at top left, rgba(255,255,255,0.35), transparent 55%),
var(--paper);
color:var(--ink);
font-family:'IBM Plex Serif', Georgia, serif;
min-height:100vh;
padding:48px 20px 80px;
line-height:1.5;
}
.sheet{
max-width:720px;
margin:0 auto;
background:var(--paper);
border:1px solid var(--line);
box-shadow: 0 1px 0 var(--line), 0 18px 40px -24px var(--paper-shadow);
position:relative;
}
.sheet::before{
content:"";
position:absolute;
inset:10px;
border:1px solid rgba(24,20,15,0.18);
pointer-events:none;
}
header{
padding:34px 38px 22px;
border-bottom:1px solid var(--line);
}
.case-no{
font-family:'IBM Plex Mono', monospace;
font-size:11px;
letter-spacing:0.14em;
text-transform:uppercase;
color:var(--ink-soft);
display:flex;
justify-content:space-between;
}
h1{
font-family:'IBM Plex Mono', monospace;
font-weight:700;
font-size:26px;
letter-spacing:0.01em;
margin:14px 0 6px;
}
.tagline{
color:var(--ink-soft);
font-size:15px;
max-width:48ch;
}
form{
padding:30px 38px;
border-bottom:1px solid var(--line);
}
label{
display:block;
font-family:'IBM Plex Mono', monospace;
font-size:11px;
letter-spacing:0.14em;
text-transform:uppercase;
color:var(--ink-soft);
margin-bottom:10px;
}
.input-row{
display:flex;
gap:10px;
}
input[type=text]{
flex:1;
font-family:'IBM Plex Mono', monospace;
font-size:15px;
padding:13px 14px;
background:#fbf8ef;
border:1px solid var(--ink);
color:var(--ink);
outline:none;
}
input[type=text]:focus{
box-shadow: 0 0 0 2px var(--stamp-amber);
}
input[type=text]::placeholder{color:#9a8f78;}
button{
font-family:'IBM Plex Mono', monospace;
font-weight:600;
font-size:13px;
letter-spacing:0.06em;
text-transform:uppercase;
padding:0 22px;
background:var(--ink);
color:var(--paper);
border:1px solid var(--ink);
cursor:pointer;
transition:transform .08s ease;
}
button:hover{background:#2c241a;}
button:active{transform:translateY(1px);}
button:focus-visible, a:focus-visible{outline:2px solid var(--stamp-amber); outline-offset:2px;}
.hint{
margin-top:10px;
font-size:12.5px;
color:var(--ink-soft);
font-family:'IBM Plex Mono', monospace;
}
#report{display:none;}
#report.show{display:block;}
.verdict-zone{
padding:36px 38px 10px;
position:relative;
min-height:120px;
}
.stamp{
font-family:'IBM Plex Mono', monospace;
font-weight:700;
font-size:30px;
letter-spacing:0.08em;
text-transform:uppercase;
display:inline-block;
padding:10px 22px;
border:4px solid currentColor;
border-radius:4px;
transform:rotate(-4deg);
position:relative;
}
.stamp::after{
content:"";
position:absolute;
inset:5px;
border:1px solid currentColor;
border-radius:2px;
opacity:0.6;
}
.stamp.safe{color:var(--stamp-green);}
.stamp.caution{color:var(--stamp-amber);}
.stamp.danger{color:var(--stamp-red);}
.verdict-sub{
font-family:'IBM Plex Mono', monospace;
font-size:12px;
color:var(--ink-soft);
margin-top:14px;
letter-spacing:0.04em;
}
.target-line{
font-family:'IBM Plex Mono', monospace;
font-size:13px;
color:var(--ink-soft);
margin-top:6px;
word-break:break-all;
}
.findings{
padding:6px 38px 34px;
}
.findings h2{
font-family:'IBM Plex Mono', monospace;
font-size:11px;
letter-spacing:0.14em;
text-transform:uppercase;
color:var(--ink-soft);
border-bottom:1px dashed var(--line);
padding-bottom:8px;
margin:18px 0 4px;
}
.item{
display:flex;
gap:14px;
padding:13px 0;
border-bottom:1px solid var(--line);
align-items:flex-start;
}
.item:last-child{border-bottom:none;}
.mark{
font-family:'IBM Plex Mono', monospace;
font-weight:700;
font-size:15px;
width:20px;
text-align:center;
flex-shrink:0;
line-height:1.6;
}
.mark.ok{color:var(--stamp-green);}
.mark.warn{color:var(--stamp-amber);}
.mark.bad{color:var(--stamp-red);}
.item-text strong{display:block; font-family:'IBM Plex Mono', monospace; font-size:13.5px; font-weight:600;}
.item-text span{display:block; font-size:14px; color:var(--ink-soft); margin-top:2px;}
footer{
padding:22px 38px 32px;
font-family:'IBM Plex Mono', monospace;
font-size:11.5px;
color:var(--ink-soft);
letter-spacing:0.02em;
}
footer a{color:var(--ink-soft);}
.err{
padding:24px 38px;
font-family:'IBM Plex Mono', monospace;
color:var(--stamp-red);
font-size:13px;
display:none;
}
.err.show{display:block;}
.advanced{
padding:18px 38px 26px;
border-bottom:1px solid var(--line);
}
.advanced summary{
font-family:'IBM Plex Mono', monospace;
font-size:11px;
letter-spacing:0.1em;
text-transform:uppercase;
color:var(--ink-soft);
cursor:pointer;
}
.advanced-body{margin-top:14px;}
.advanced p{font-size:13px; color:var(--ink-soft); margin:0 0 12px;}
.advanced a{color:var(--ink);}
.key-row{display:flex; gap:10px;}
input[type=password]{
flex:1;
font-family:'IBM Plex Mono', monospace;
font-size:13px;
padding:10px 12px;
background:#fbf8ef;
border:1px solid var(--line);
color:var(--ink);
outline:none;
}
input[type=password]:focus{box-shadow: 0 0 0 2px var(--stamp-amber);}
.key-status{
margin-top:8px;
font-family:'IBM Plex Mono', monospace;
font-size:11.5px;
color:var(--ink-soft);
}
.key-status.on{color:var(--stamp-green);}
.threat-row{
margin:0 38px 0;
padding:16px 0;
border-bottom:1px solid var(--line);
display:flex;
gap:14px;
align-items:flex-start;
}
.threat-row .mark{font-size:18px;}
.threat-row .item-text strong{font-size:14px;}
.spinner{
display:inline-block;
width:11px;height:11px;
border:2px solid var(--ink-soft);
border-top-color:transparent;
border-radius:50%;
animation:spin .7s linear infinite;
margin-right:6px;
vertical-align:-1px;
}
@keyframes spin{to{transform:rotate(360deg);}}
@media (prefers-reduced-motion: reduce){
.spinner{animation:none;}
}
.copy-btn{
font-family:'IBM Plex Mono', monospace;
font-size:11px;
letter-spacing:0.08em;
text-transform:uppercase;
background:transparent;
color:var(--ink-soft);
border:1px solid var(--line);
padding:7px 12px;
}
.copy-btn:hover{border-color:var(--ink); color:var(--ink);}
@media (max-width:560px){
header,form,.verdict-zone,.findings,footer{padding-left:22px;padding-right:22px;}
h1{font-size:21px;}
.stamp{font-size:22px;padding:8px 14px;}
}
@media (prefers-reduced-motion: reduce){
button{transition:none;}
}
</style>
</head>
<body>
<div class="sheet">
<header>
<div class="case-no">
<span>FILE NO. LI-001</span>
<span id="clock"></span>
</div>
<h1>Link Inspector</h1>
<p class="tagline">Paste a link before you click it. Everything is checked right here in your browser - the URL is never sent anywhere.</p>
</header>
<form id="inspect-form" autocomplete="off">
<label for="url-input">URL to inspect</label>
<div class="input-row">
<input type="text" id="url-input" name="url" placeholder="paste a link, e.g. https://example.com/reset-password" inputmode="url">
<button type="submit">Inspect</button>
</div>
<p class="hint">Works on full links from texts, emails, or DMs — paste the whole thing.</p>
</form>
<details class="advanced">
<summary>Real-time threat database (optional, recommended)</summary>
<div class="advanced-body">
<p>The checklist below only catches obvious tricks. To check a link against Google's live database of known phishing and malware sites - the same one Chrome uses - add a free Safe Browsing API key. It's stored only in this browser tab's memory; nothing is saved or sent anywhere except Google's lookup endpoint when you inspect a link. <a href="https://developers.google.com/safe-browsing/v4/get-started" target="_blank" rel="noopener">Get a free key →</a></p>
<div class="key-row">
<input type="password" id="api-key" placeholder="paste your Safe Browsing API key">
</div>
<p class="key-status" id="key-status">No key set - only the heuristic checklist will run.</p>
</div>
</details>
<div class="err" id="error-box"></div>
<div id="report">
<div class="verdict-zone">
<div class="stamp" id="stamp">SAFE</div>
<div class="verdict-sub" id="verdict-sub">0 of 0 checks flagged</div>
<div class="target-line" id="target-line"></div>
</div>
<div class="threat-row" id="threat-row" style="display:none;">
<div class="mark" id="threat-mark">…</div>
<div class="item-text">
<strong id="threat-title">Threat database</strong>
<span id="threat-detail"></span>
</div>
</div>
<div class="findings">
<h2>Heuristic checklist</h2>
<div id="items"></div>
<div style="margin-top:18px;">
<button class="copy-btn" id="copy-btn" type="button">Copy report</button>
</div>
</div>
</div>
<footer>
Heuristic checks explain *why* a link looks off but can't see live threat data. The Safe Browsing check above is what actually catches real, currently-active phishing - turn it on for results you can trust. A clean report still isn't a guarantee. When in doubt, type the address in yourself instead of clicking.
</footer>
</div>
<script>
(function(){
const form = document.getElementById('inspect-form');
const input = document.getElementById('url-input');
const report = document.getElementById('report');
const errorBox = document.getElementById('error-box');
const stamp = document.getElementById('stamp');
const verdictSub = document.getElementById('verdict-sub');
const targetLine = document.getElementById('target-line');
const itemsBox = document.getElementById('items');
const clock = document.getElementById('clock');
const apiKeyInput = document.getElementById('api-key');
const keyStatus = document.getElementById('key-status');
const threatRow = document.getElementById('threat-row');
const threatMark = document.getElementById('threat-mark');
const threatTitle = document.getElementById('threat-title');
const threatDetail = document.getElementById('threat-detail');
const copyBtn = document.getElementById('copy-btn');
let lastReportText = '';
apiKeyInput.addEventListener('input', function(){
if(apiKeyInput.value.trim()){
keyStatus.textContent = 'Key set for this session — live threat check will run on inspect.';
keyStatus.classList.add('on');
} else {
keyStatus.textContent = 'No key set — only the heuristic checklist will run.';
keyStatus.classList.remove('on');
}
});
function stampClock(){
const d = new Date();
clock.textContent = d.toLocaleDateString(undefined,{year:'numeric',month:'2-digit',day:'2-digit'});
}
stampClock();
// A list of widely-impersonated domains for lookalike detection.
const KNOWN_DOMAINS = [
'google.com','accounts.google.com','gmail.com','apple.com','icloud.com',
'microsoft.com','outlook.com','live.com','office.com','amazon.com',
'paypal.com','facebook.com','instagram.com','whatsapp.com','netflix.com',
'bankofamerica.com','chase.com','wellsfargo.com','citibank.com','capitalone.com',
'irs.gov','usps.com','fedex.com','ups.com','dhl.com','linkedin.com',
'dropbox.com','github.com','steamcommunity.com','coinbase.com','binance.com',
'twitter.com','x.com','tiktok.com','snapchat.com','discord.com','telegram.org',
'spotify.com','adobe.com','yahoo.com','aol.com','protonmail.com',
'hsbc.com','barclays.co.uk','santander.com','americanexpress.com','venmo.com',
'zelle.com','cashapp.com','robinhood.com','schwab.com','fidelity.com',
'ebay.com','etsy.com','walmart.com','target.com','bestbuy.com',
'airbnb.com','booking.com','expedia.com','uber.com','lyft.com','doordash.com',
'indeed.com','linkedin.com','glassdoor.com','docusign.com','zoom.us',
'wellsfargoonline.com','metamask.io','trustwallet.com','blockchain.com',
'godaddy.com','namecheap.com','cloudflare.com','wordpress.com','squarespace.com'
];
const SUSPICIOUS_TLDS = ['zip','mov','top','xyz','tk','gq','cf','ml','ga','work','click','country','rest','quest','support','loan','win'];
const SHORTENERS = ['bit.ly','tinyurl.com','t.co','goo.gl','ow.ly','is.gd','buff.ly','rebrand.ly','cutt.ly','rb.gy','shorturl.at'];
function levenshtein(a, b){
const m = a.length, n = b.length;
const dp = Array.from({length: m+1}, () => new Array(n+1).fill(0));
for(let i=0;i<=m;i++) dp[i][0]=i;
for(let j=0;j<=n;j++) dp[0][j]=j;
for(let i=1;i<=m;i++){
for(let j=1;j<=n;j++){
const cost = a[i-1]===b[j-1] ? 0 : 1;
dp[i][j] = Math.min(dp[i-1][j]+1, dp[i][j-1]+1, dp[i-1][j-1]+cost);
}
}
return dp[m][n];
}
function registrableDomain(hostname){
const parts = hostname.split('.').filter(Boolean);
if(parts.length <= 2) return hostname;
return parts.slice(-2).join('.');
}
function isIPAddress(host){
return /^(\d{1,3}\.){3}\d{1,3}$/.test(host) || /^[0-9a-fA-F:]+$/.test(host) && host.includes(':');
}
function inspect(raw){
let urlText = raw.trim();
if(!/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(urlText)){
urlText = 'http://' + urlText; // assume scheme for parsing only; we still flag missing https below using original text
}
let url;
try{
url = new URL(urlText);
}catch(e){
return null;
}
const originalHadHttps = /^https:\/\//i.test(raw.trim());
const originalHadHttp = /^http:\/\//i.test(raw.trim());
const hostname = url.hostname.toLowerCase();
const findings = [];
// 1. Protocol
if(originalHadHttps){
findings.push({level:'ok', title:'Encrypted connection', detail:'The link uses HTTPS, so the connection itself is encrypted.'});
} else if(originalHadHttp){
findings.push({level:'warn', title:'Not encrypted', detail:'The link uses plain HTTP. Avoid entering passwords or card details on it.'});
} else {
findings.push({level:'warn', title:'No protocol specified', detail:'No http:// or https:// was given — treated as http for this check.'});
}
// 2. @ symbol trick
if(raw.includes('@') && raw.indexOf('@') < raw.indexOf(hostname.length ? hostname : '')){
findings.push({level:'bad', title:'Hidden destination trick', detail:'The link uses an "@" before the real address, a common way to disguise where it actually goes.'});
} else if(raw.match(/\/\/[^\/]*@/)){
findings.push({level:'bad', title:'Hidden destination trick', detail:'The link uses an "@" before the real address, a common way to disguise where it actually goes.'});
} else {
findings.push({level:'ok', title:'No hidden-destination trick', detail:'No "@" disguise found in front of the address.'});
}
// 3. IP address as host
if(isIPAddress(hostname)){
findings.push({level:'bad', title:'Raw IP address', detail:'The link points to a numeric IP address instead of a named website — unusual for legitimate sites.'});
} else {
findings.push({level:'ok', title:'Named domain', detail:'The link points to a regular domain name, not a raw IP address.'});
}
// 4. Punycode / IDN
if(hostname.includes('xn--')){
findings.push({level:'bad', title:'Internationalized domain', detail:'The domain uses punycode encoding, sometimes used to mimic familiar letters with look-alike characters.'});
} else {
findings.push({level:'ok', title:'Standard characters', detail:'The domain doesn\u2019t use disguised international character encoding.'});
}
// 5. Lookalike of a known domain
const reg = registrableDomain(hostname);
let lookalike = null;
for(const known of KNOWN_DOMAINS){
const knownReg = registrableDomain(known);
if(reg === knownReg) { lookalike = null; break; }
const dist = levenshtein(reg, knownReg);
if(dist > 0 && dist <= 2 && Math.abs(reg.length - knownReg.length) <= 2){
lookalike = knownReg;
break;
}
}
if(lookalike){
findings.push({level:'bad', title:'Looks like a known brand', detail:'The domain "' + reg + '" is suspiciously close to "' + lookalike + '" — a common impersonation tactic.'});
} else {
findings.push({level:'ok', title:'No brand lookalike detected', detail:'The domain doesn\u2019t closely resemble a commonly impersonated site.'});
}
// 6. Suspicious TLD
const tld = hostname.split('.').pop();
if(SUSPICIOUS_TLDS.includes(tld)){
findings.push({level:'warn', title:'Uncommon top-level domain', detail:'The ".' + tld + '" ending is frequently used in spam and phishing campaigns. Not proof of harm, but worth noting.'});
} else {
findings.push({level:'ok', title:'Common top-level domain', detail:'The domain ending ("' + tld + '") is a common, widely-used one.'});
}
// 7. URL shortener
if(SHORTENERS.includes(reg)){
findings.push({level:'warn', title:'Shortened link', detail:'This is a link shortener. The real destination is hidden until you click — there\u2019s no way to verify it from the link alone.'});
} else {
findings.push({level:'ok', title:'Destination is visible', detail:'This isn\u2019t a shortened link, so the destination domain is visible up front.'});
}
// 8. Excessive subdomains
const subdomainCount = hostname.split('.').length - 2;
if(subdomainCount >= 3){
findings.push({level:'warn', title:'Many subdomains', detail:'The address has an unusually long chain of subdomains, sometimes used to bury the real domain out of view.'});
} else {
findings.push({level:'ok', title:'Normal subdomain structure', detail:'The subdomain structure looks ordinary.'});
}
// 9. Credential-bait keywords combined with not-https
const fullLower = raw.toLowerCase();
const baitWords = ['login','verify','secure','account','password','update-billing','confirm','unlock'];
const hasBait = baitWords.some(w => fullLower.includes(w));
if(hasBait && !originalHadHttps){
findings.push({level:'bad', title:'Account-related wording, no encryption', detail:'The link mentions account or login terms but isn\u2019t using HTTPS — a frequent pattern in credential phishing.'});
} else if(hasBait){
findings.push({level:'warn', title:'Account-related wording', detail:'The link contains words like "login" or "verify" — not dangerous alone, but worth a second look before entering credentials.'});
} else {
findings.push({level:'ok', title:'No credential-bait wording', detail:'No suspicious account/login keywords found in the link text.'});
}
// 10. Excessive digits/hyphens in domain
const labelToCheck = hostname.split('.').slice(0,-2).join('.') + reg.split('.')[0];
const digitHyphenRatio = (labelToCheck.match(/[\d-]/g) || []).length / Math.max(labelToCheck.length,1);
if(digitHyphenRatio > 0.3 && labelToCheck.length > 6){
findings.push({level:'warn', title:'Unusual domain pattern', detail:'The domain has a high mix of digits and hyphens, a pattern sometimes seen in disposable or generated phishing domains.'});
} else {
findings.push({level:'ok', title:'Ordinary domain pattern', detail:'The domain name doesn\u2019t show an unusual digit/hyphen pattern.'});
}
return {hostname, reg, findings};
}
async function checkSafeBrowsing(apiKey, rawUrl){
const endpoint = 'https://safebrowsing.googleapis.com/v4/threatMatches:find?key=' + encodeURIComponent(apiKey);
const body = {
client: { clientId: 'link-inspector', clientVersion: '1.0.0' },
threatInfo: {
threatTypes: ['MALWARE','SOCIAL_ENGINEERING','UNWANTED_SOFTWARE','POTENTIALLY_HARMFUL_APPLICATION'],
platformTypes: ['ANY_PLATFORM'],
threatEntryTypes: ['URL'],
threatEntries: [{ url: rawUrl }]
}
};
const res = await fetch(endpoint, {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify(body)
});
if(!res.ok){
throw new Error('Safe Browsing API returned ' + res.status);
}
const data = await res.json();
return data.matches || [];
}
function renderThreatRow(state, matches){
threatRow.style.display = 'flex';
if(state === 'loading'){
threatMark.className = 'mark';
threatMark.innerHTML = '<span class="spinner"></span>';
threatTitle.textContent = 'Checking Google Safe Browsing…';
threatDetail.textContent = 'Looking this URL up against the live threat database.';
} else if(state === 'error'){
threatMark.className = 'mark warn';
threatMark.textContent = '!';
threatTitle.textContent = 'Threat database unavailable';
threatDetail.textContent = 'Couldn\u2019t reach Safe Browsing (bad key, rate limit, or network/CORS issue). Falling back to heuristics only.';
} else if(state === 'skipped'){
threatRow.style.display = 'none';
} else if(state === 'clean'){
threatMark.className = 'mark ok';
threatMark.textContent = '✓';
threatTitle.textContent = 'Not on Google\u2019s threat list';
threatDetail.textContent = 'No known malware or phishing match found for this exact URL right now.';
} else if(state === 'flagged'){
threatMark.className = 'mark bad';
threatMark.textContent = '✕';
const types = matches.map(m => m.threatType.replace(/_/g,' ').toLowerCase()).join(', ');
threatTitle.textContent = 'Flagged by Google Safe Browsing';
threatDetail.textContent = 'Listed as: ' + types + '. Treat this as confirmed dangerous, not a maybe.';
}
}
function score(findings){
let s = 100;
findings.forEach(f => {
if(f.level === 'bad') s -= 28;
if(f.level === 'warn') s -= 10;
});
return Math.max(s, 0);
}
function render(result, threatState, threatMatches){
const badCount = result.findings.filter(f => f.level === 'bad').length;
const warnCount = result.findings.filter(f => f.level === 'warn').length;
const flagged = badCount + warnCount;
let verdict = 'safe', label = 'LOOKS OK';
if(badCount > 0){ verdict = 'danger'; label = 'HIGH RISK'; }
else if(warnCount >= 2){ verdict = 'caution'; label = 'USE CAUTION'; }
else if(warnCount === 1){ verdict = 'caution'; label = 'MINOR FLAGS'; }
// A confirmed Safe Browsing match overrides the heuristic verdict entirely.
if(threatState === 'flagged'){
verdict = 'danger';
label = 'CONFIRMED THREAT';
}
stamp.className = 'stamp ' + verdict;
stamp.textContent = label;
verdictSub.textContent = flagged + ' of ' + result.findings.length + ' heuristic checks flagged';
targetLine.textContent = 'destination domain: ' + result.hostname;
renderThreatRow(threatState, threatMatches);
itemsBox.innerHTML = '';
result.findings.forEach(f => {
const row = document.createElement('div');
row.className = 'item';
const mark = document.createElement('div');
mark.className = 'mark ' + (f.level === 'ok' ? 'ok' : f.level === 'warn' ? 'warn' : 'bad');
mark.textContent = f.level === 'ok' ? '✓' : f.level === 'warn' ? '!' : '✕';
const text = document.createElement('div');
text.className = 'item-text';
const strong = document.createElement('strong');
strong.textContent = f.title;
const span = document.createElement('span');
span.textContent = f.detail;
text.appendChild(strong);
text.appendChild(span);
row.appendChild(mark);
row.appendChild(text);
itemsBox.appendChild(row);
});
report.classList.add('show');
errorBox.classList.remove('show');
const lines = [];
lines.push('LINK INSPECTOR REPORT');
lines.push('Destination: ' + result.hostname);
lines.push('Verdict: ' + label);
if(threatState === 'flagged'){
lines.push('Safe Browsing: FLAGGED — ' + threatMatches.map(m=>m.threatType).join(', '));
} else if(threatState === 'clean'){
lines.push('Safe Browsing: no known match');
} else if(threatState === 'error'){
lines.push('Safe Browsing: check unavailable');
} else {
lines.push('Safe Browsing: not checked (no API key)');
}
lines.push('');
result.findings.forEach(f => {
const tag = f.level === 'ok' ? '[ok]' : f.level === 'warn' ? '[!]' : '[x]';
lines.push(tag + ' ' + f.title + ' — ' + f.detail);
});
lastReportText = lines.join('\n');
}
form.addEventListener('submit', async function(e){
e.preventDefault();
const raw = input.value;
if(!raw.trim()){
return;
}
const result = inspect(raw);
if(!result){
errorBox.textContent = 'That doesn\u2019t look like a valid link — check the address and try again.';
errorBox.classList.add('show');
report.classList.remove('show');
return;
}
const apiKey = apiKeyInput.value.trim();
if(!apiKey){
render(result, 'skipped', []);
return;
}
render(result, 'loading', []);
try{
const matches = await checkSafeBrowsing(apiKey, raw.trim());
render(result, matches.length ? 'flagged' : 'clean', matches);
}catch(err){
render(result, 'error', []);
}
});
copyBtn.addEventListener('click', async function(){
if(!lastReportText) return;
try{
await navigator.clipboard.writeText(lastReportText);
const original = copyBtn.textContent;
copyBtn.textContent = 'Copied';
setTimeout(() => { copyBtn.textContent = original; }, 1500);
}catch(err){
copyBtn.textContent = 'Copy failed';
}
});
})();
</script>
</body>
</html>