-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
249 lines (162 loc) · 7.38 KB
/
script.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
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
const el = document.querySelector(".searchterm");
var authData;
/* Initialising typeahead-standalone.js: https://typeahead.digitalfortress.tech/ */
typeahead({
input: el,
source: {
remote: {
url: "https://apiurl-theta.vercel.app/api/products?alias=%QUERY",
wildcard: "%QUERY",
requestOptions: {}
},
identifier: 'alias',
transform: (data) => {
return data.Source;
},
identity: (suggestion) => `${suggestion.name}`
},
display: (item, event) => {
return `${item.name}`;
},
debounceRemote: 300,
highlight: true,
className: 'typeahead-sgst',
minLength: 3,
preventSubmit: false,
limit:25,
hint: false,
autoSelect: false,
templates: {
suggestion: (authifyURL) => (
`<div class="single-item">
<img src=${authifyURL.logo} style="background-color:${authifyURL.bg}; font-size:12px;" loading="lazy">
<div class="details">
<div class="company_name"><span>${authifyURL.name}</span><span> <img class="badge" src="images/goldbadge.svg"></span></div>
<div class="company_type">${authifyURL.cat}: ${authifyURL.origin} </div>
</div></div>`
),
header: (resultSet) => `Results for <span style="color:#A2FB15; background-color:#1f282d; text-transform: uppercase;">" ${resultSet.query} "</span> : ${resultSet.count} `,
notFound: (resultSet) => { return `Nothing found for <span style="color:yellow; background-color:#1f282d; text-transform: uppercase;">" ${resultSet.query} "</span>. `;},
footer:() => 'an <a href="https://authifyweb.com" target="_blank" style="color:goldenrod; font-size:14px;"> authifyWeb.com</a> project ',
loader: () => '<div style="text-align: center"><img src="images/loader.svg" /></div>',
/*empty: (resultSet) => {
return `<div style="font-size:12px;">Enter organisation name and click enter</div>`;
},*/
},
onSubmit: (e, selectedSuggestion) => {
if (selectedSuggestion) {
//Clear previous data
data.innerHTML = "";
disclaimer.innerHTML = "";
error_message.innerHTML="";
const myJSON = JSON.stringify(selectedSuggestion);
const outp=JSON.parse(myJSON);
const {name, urls,type,id,official} = outp;
authData=outp;
//document.getElementById('output').innerHTML ="";
document.getElementById("compatible").innerHTML ="";
document.getElementById("verify_your_company").innerHTML ="";
document.getElementById('naam').innerHTML = `<p style="font-size:1em;"> Submit URL below to verify whether the site belongs to <span style="color:#DFB014 "> ${name} </span></> </p>`;
var form=`<input type='url' id='link_id' autocomplete="off" placeholder="Paste the URL" > `;
var btn = `<input type="submit" id="search_btn" value="Search 🔍"> <p style="color:white; font-size:12px; padding-top:2px;">Please use a valid URL format (with https://). Otherwise, no data will be displayed.</p><div class="refresh_btn_box" style="margin-top:5px; margin-bottom:5px;"><button type="button" id="refresh_btn">Search Another Link</button></div> `;
input_form.innerHTML=form;
document.getElementById('input_btn').addEventListener('click', searchNow);
input_btn.innerHTML=btn;
no_promote.innerHTML="";
if ("own" in authData) {var Disclaimer=`All data sourced from public domain`;}
else { var Disclaimer=`Official data submitted by the organisation above.`; }
disclaimer.innerHTML = Disclaimer;
document.getElementById('refresh_btn').addEventListener('click', function() {
window.location.reload();
});
}
}
});
input_form.addEventListener("keydown", (event) => {
if (event.defaultPrevented) {
return; // Do nothing if the event was already processed
}
switch (event.key) {
case "Enter":
searchNow();
link_id.blur();
break;
case "Esc": // IE/Edge specific value
case "Escape":
// Do something for "esc" key press.
break;
default:
return; // Quit when this doesn't handle the key event.
}
// Cancel the default action to avoid it being handled twice
event.preventDefault();
}, true);
function searchNow()
{ var input = document.getElementById('link_id').value;
document.getElementById("data").innerHTML ="";
document.getElementById("disclaimer").innerHTML ="";
document.getElementById("error_message").innerHTML = "";
try {
var url = new URL(input);
// URL format is valid, continue with your code logic
} catch (error) {
// URL format is not valid, show an error message
var err_msg= `<p id="err_msg"style="margin-top:5px;">Submit a valid URL (eg https://url.authifyweb.com).</p>`;
error_message.innerHTML=err_msg;
return; // stop further execution
}
var hostname = url.hostname;
var protocol = url.protocol;
var origin = url.origin;
var href= url.href;
var pathname= url.pathname;
var search = url.search;
var domain = filterdomain_from_hostname(hostname);
var output= filtering(url, href, origin, hostname,protocol,pathname,search,domain);
data.innerHTML = (output || "...Verifying");
}
function filterdomain_from_hostname(hostname)
{
var parts = hostname.split('.');
var domain;
if (parts.length > 2) {
if (parts[parts.length - 2].length === 2 || parts[parts.length - 2].length === 3) {
domain = parts.slice(-3).join('.');
} else {
domain = parts.slice(-2).join('.');
}
} else {
domain = hostname;
}
return domain;
}
function compare(link,display_link){
var json = authData;
var cl= json.urls;
console.log(json)
var conditionMet = false; // Flag variable to track if the condition is met
for (var i = 0; i < cl.length; i++) {
if (json.urls[i] === link) {
var Data = `<div style="color:white;font-size:12px; background-color:#1f282d;">` + display_link + `</br> <p> <span style="color:#A2FB15; font-size: 14px; ">Verified by authifyURL.</span> <span class="tooltip" > ✅ <span class="tooltiptext">This website is valid and legal. </span> </p></br> <p><span style="font-size:14px; color:white;">The page you submitted belongs to: </span><br> <span class="op_logo"><img src="${json.logo}"></span><span style="font-size:18px; color: #DFb014"> ${json.name}</span></p></br></div>`;
if ("own" in authData) {var Disclaimer=`All data sourced from public domain`;}
else { var Disclaimer=`Official data submitted by the organisation above.`; }
disclaimer.innerHTML = Disclaimer;
data.innerHTML = Data;
disclaimer.innerHTML = Disclaimer;
no_promote.innerHTML = "";
conditionMet = true; // Set the flag to true indicating the condition is met
break; // Exit the loop since the condition is met
}
}
if (!conditionMet) {
var Data = `<div style="color:white; background-color:#1f282d; font-size:12px;" >` + display_link+`<p><br><span style="color:red; font-size: 18px;"> The page you submitted doesn't belong to the organization selected above</span> <span class="tooltip"> ❌ <span class="tooltiptext">Possibly a scam. Report the page directly to the owner. </span> </p> </div>`;
if ("own" in authData) {var Disclaimer=`All data sourced from public domain`;}
else { var Disclaimer=`Official data submitted by the organisation above.`; }
disclaimer.innerHTML = Disclaimer;
data.innerHTML = Data;
disclaimer.innerHTML = Disclaimer;
no_promote.innerHTML = "";
}
return Data;
}
/* Loader or the svg spinner is modified from the works of Utkarsh Verma https://github.com/n3r4zzurr0/svg-spinners (MIT) */