-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
175 lines (147 loc) · 4.1 KB
/
script.js
File metadata and controls
175 lines (147 loc) · 4.1 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
const resultDiv = document.getElementById("result");
const urlInput = document.getElementById("urlInput");
async function verifyURL() {
let url = urlInput.value.trim();
if (url === "") {
showResult(
"⚠ Please enter a URL",
"invalid"
);
return;
}
// Auto add https
if (
!url.startsWith("http://") &&
!url.startsWith("https://")
) {
url = "https://" + url;
}
// Validate URL structure
try {
new URL(url);
} catch {
showResult(
"❌ Invalid URL Format",
"invalid"
);
return;
}
showLoading();
setTimeout(async () => {
let riskScore = 0;
const lowerURL = url.toLowerCase();
// Suspicious Keywords
const suspiciousWords = [
"hack",
"free-money",
"crack",
"spam",
"scam",
"fake",
"phishing",
"bitcoin",
"xxx",
"darkweb",
"cheat"
];
suspiciousWords.forEach(word => {
if (lowerURL.includes(word)) {
riskScore += 40;
}
});
// Risky Domains
const riskyDomains = [
".xyz",
".tk",
".gq",
".ml",
".co",
".ga",
".ph",
".pl",
".cf"
];
riskyDomains.forEach(domain => {
if (lowerURL.includes(domain)) {
riskScore += 30;
}
});
// HTTP Warning
if (url.startsWith("http://")) {
riskScore += 35;
}
// Try Online Reachability Check
// Note: fetch with mode: 'no-cors' will not throw an error on network issues
// for cross-origin requests, making it difficult to use for reachability.
// For a more robust check, you might need a backend proxy or alternative API.
try {
await fetch(url, {
mode: "no-cors"
});
} catch (e) {
// This catch block might not be triggered for network errors in no-cors mode
// for cross-origin requests, but it's good practice to have.
console.error("Fetch error:", e);
riskScore += 25; // Add score if fetch truly fails (e.g., local network error)
}
// FINAL RESULT
if (riskScore >= 60) {
showResult(
`❌ Unsafe Website Detected<br><small>High Risk Score: ${riskScore}</small>`,
"invalid"
);
} else if (riskScore >= 30) {
showResult(
`⚠ Suspicious Website<br><small>Medium Risk Score: ${riskScore}</small>`,
"invalid"
);
} else {
showResult(
`✅ Website Appears Safe<br><small>AI Security Score Passed</small>`,
"valid"
);
}
}, 1800);
}
function showLoading() {
resultDiv.style.display = "flex";
resultDiv.className = "result loading";
resultDiv.innerHTML = `
<div class="loader"></div>
AI Scanning Website...
`;
}
function showResult(message, type) {
resultDiv.innerHTML = message;
resultDiv.className = `result ${type}`;
}
// ENTER KEY
urlInput.addEventListener("keydown", (e) => {
if(e.key === "Enter"){
e.preventDefault();
document
.getElementById("googleBtn")
.click();
}
});
function googleCheck() {
let url = urlInput.value.trim();
if (url === "") {
showResult(
"⚠ Enter a website first",
"invalid"
);
return;
}
// Remove https://
url = url.replace(/^https?:\/\//, '');
// Remove paths
url = url.split('/')[0];
// Google Search Query
const query = `is ${url} listed in the Google Safe Browsing database or not? | Answer in one word: It's Safe or It isn't Safe.`;
// Open Google Search
window.open(
`https://www.google.com/search?q=${encodeURIComponent(query)}`,
"_blank"
);
}