-
Notifications
You must be signed in to change notification settings - Fork 1
/
Go-Back-No-Popup.txt
58 lines (51 loc) · 1.79 KB
/
Go-Back-No-Popup.txt
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
// ==UserScript==
// @name URL Change Alert
// @namespace https://github.com/NullPounce
// @version 1.0
// @description goes back one page without notice if the user changes urls twice witin 10 seconds.
// @author Your Name
// @match *://*/*
// @grant none
// ==/UserScript==
let urlChanges = 0;
let lastUrl = window.location.href;
let timerId;
setInterval(function() {
if (window.location.href !== lastUrl) {
urlChanges++;
lastUrl = window.location.href;
if (urlChanges >= 2) {
let popup = document.createElement('div');
popup.textContent = 'You have changed URLs 2 times within 10 seconds. You will be redirected to the previous page in 3 seconds...';
popup.style.position = 'fixed';
popup.style.bottom = '50px';
popup.style.left = '50%';
popup.style.transform = 'translate(-50%, 0)';
popup.style.backgroundColor = 'white';
popup.style.padding = '10px';
document.body.appendChild(popup);
let closePopup = function() {
popup.parentNode.removeChild(popup);
clearInterval(timerId);
};
timerId = setInterval(function() {
closePopup();
history.back();
urlChanges = 0;
}, 3000);
popup.addEventListener('click', function() {
closePopup();
history.back();
urlChanges = 0;
});
}
} else {
urlChanges = 0;
if (!timerId) {
timerId = setTimeout(function() {
urlChanges = 0;
timerId = null;
}, 10000);
}
}
}, 5000);