-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
147 lines (132 loc) · 4.23 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
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
const hamburger = document.querySelector('.header .nav-bar .nav-list .hamburger');
const mobile_menu = document.querySelector('.header .nav-bar .nav-list ul');
const menu_item = document.querySelectorAll('.header .nav-bar .nav-list ul li a');
const header = document.querySelector('.header.con');
const inputbar = document.querySelector('.search');
const inputbartext = document.querySelector('#searchtxt');
const img = document.querySelector('#img');
const title = document.querySelector('#title');
const messsage = document.querySelector('#Result #msg');
const body = document.querySelector('#body_modal');
let i=0;
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
mobile_menu.classList.toggle('active');
});
document.addEventListener('scroll', () => {
var scroll_position = window.scrollY;
if (scroll_position > 250) {
header.style.backgroundColor = '#29323c';
} else {
header.style.backgroundColor = 'transparent';
}
});
menu_item.forEach((item) => {
item.addEventListener('click', () => {
hamburger.classList.toggle('active');
mobile_menu.classList.toggle('active');
});
});
inputbar.addEventListener('click', () => {
url = inputbartext.value;
if(url!="")
{
if(check_url(url)==true)
{
$("#Success").modal('show');
document.getElementsByTagName('body')[0].readOnly=true;
detect_url(url);
}
else
{
if(i==0)
{
$("#Error").modal('show');
i=1;
}
else
{
i=0;
}
}
}
});
function check_url(myURL)
{
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ //port
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i');
return pattern.test(myURL);
}
function detect_url(myUrl)
{
console.log("Entered Successfull");
$.ajax({
type:"POST",
url:"https://phishsheild.herokuapp.com/post ",
dataType:'json',
data :
{
URL:myUrl
},
complete: function(data)
{
inputbartext.value="";
$("#Success").modal('hide');
console.log(data['responseText'])
if(data['responseText']=="-1")
{
img.style.background="url(img/fail.png)";
img.style.backgroundRepeat="no-repeat";
img.style.backgroundSize="contain";
title.innerHTML="UNSAFE URL";
messsage.innerHTML="The Url is detected as a Phishing Url.Please We Request not to Visit the Url.For More Information Click Read More."
$("#Result").modal('show');
}
else if(data['responseText']=="0")
{
img.style.background="url(img/success.png)";
img.style.backgroundRepeat="no-repeat";
img.style.backgroundSize="contain";
title.innerHTML="Not Recognized URL";
messsage.innerHTML="The Url is not recognized but url is safe to visit.You can safely Visit the url.For More Information Click Read More."
$("#Result").modal('show');
}
else
{
img.style.background="url(img/notrecognized.png)";
img.style.backgroundRepeat="no-repeat";
img.style.backgroundSize="contain";
title.innerHTML="SAFE URL";
messsage.innerHTML="The Url is detected as a Safe Url (Not Phishing Url).You can safely Visit the url.For More Information Click Read More."
$("#Result").modal('show');
}
},
error: function(xhr,textStatus,err)
{
console.log("readyState: " + xhr.readyState);
console.log("responseText: "+ xhr.responseText);
console.log("status: " + xhr.status);
console.log("text status: " + textStatus);
console.log("error: " + err);
}
});
}
/*
function fadeout() {
var fade= document.getElementById("body");
var intervalID = setInterval(function () {
if (!fade.style.opacity) {
fade.style.opacity = 1;
}
if (fade.style.opacity > 0) {
fade.style.opacity -= 0.1;
}
else {
clearInterval(intervalID);
}
}, 200);
*/