-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterceptor.js
More file actions
56 lines (46 loc) · 1.48 KB
/
interceptor.js
File metadata and controls
56 lines (46 loc) · 1.48 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
<script>
function interceptor() {
document.addEventListener("scroll", function(e){
var scrollPercentage = {"scroll":(e.pageY / window.scrollMaxY)*100};
console.dir(e);
var req = new XMLHttpRequest();
req.open('POST', 'http://localhost:5000/event', true);
req.setRequestHeader("Content-Type", "application/json");
req.onload = function(e) {
if (req.readyState === 4 && req.status === 200) {
console.dir(req.statusText);
console.dir(req.responseText);
}
else {
console.dir(req.statusText);
}
}
req.onerror = function(e) {
console.dir(req.statusText);
}
var body = JSON.stringify(scrollPercentage);
console.dir(body);
req.send(body);
});
document.addEventListener("click", function(e){
console.dir(e);
e.preventDefault();
e.stopPropagation();
console.dir(e)
if (e.target.href) {
var url = e.originalTarget.baseURI.match(/(http:\/\/[A-z\d:]+\/)/)[1] + e.target.href.replace('https', 'http');
console.dir(url)
window.location.href = url;
}
});
// Fix this
/* window.onpopstate(function(e){
console.dir('popstate');
console.dir(e);
e.preventDefault();
e.stopPropagation();
// window.location.href = document.location;
});*/
};
interceptor();
</script>