-
Notifications
You must be signed in to change notification settings - Fork 1
/
Go-Back-URL-Alert-Counter.txt
127 lines (118 loc) · 4.13 KB
/
Go-Back-URL-Alert-Counter.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
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
// ==UserScript==
// @name URL Change Alert
// @namespace https://github.com/NullPounce
// @version 1.0
// @description Alerts the user if they change URLs 2 times within ten seconds then goes back a page. If there have been 5 popups, a non-closeable popup is displayed for 15 seconds.
// @author NullPounce
// @match *://*/*
// @grant none
// ==/UserScript==
let popupCounter = 0;
let urlChanges = 0;
let lastUrl = window.location.href;
let timerId;
let uncloseablePopup = null;
setInterval(function() {
if (window.location.href !== lastUrl) {
urlChanges++;
lastUrl = window.location.href;
if (urlChanges >= 2) {
popupCounter++; // Increment the counter for each popup displayed
console.log('Popup displayed ' + popupCounter + ' times.');
if (popupCounter >= 5) {
if (!uncloseablePopup) {
uncloseablePopup = document.createElement('div');
uncloseablePopup.style.cssText = `
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: white;
z-index: 9999;
display: flex;
align-items: center;
justify-content: center;
`;
const message = document.createElement('p');
message.textContent = '⌚️Time-Out: You are lucky to be doing school at Home on a computer💻. Wait longer before changing pages.';
message.style.cssText = `
font-size: 24px;
text-align: center;
margin: 20px;
`;
uncloseablePopup.appendChild(message);
document.body.appendChild(uncloseablePopup);
setTimeout(() => {
document.body.removeChild(uncloseablePopup);
uncloseablePopup = null;
popupCounter = 0;
}, 15000);
}
} else {
let alertBox = document.createElement('div');
alertBox.style.cssText = `
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: flex;
align-items: center;
justify-content: center;
`;
let alertContainer = document.createElement('div');
alertContainer.style.cssText = `
width: 300px;
background-color: white;
border-radius: 5px;
padding: 20px;
text-align: center;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
`;
let alertMessage = document.createTextNode('🤖 You are changing pages too fast. Please slow down and focus 🧠💪');
let okButton = document.createElement('button');
okButton.textContent = 'OK';
let cancelButton = document.createElement('button');
cancelButton.textContent = 'Cancel';
let buttons = [okButton, cancelButton];
function disableButtons() {
buttons.forEach(button => {
button.disabled = true;
});
setTimeout(() => {
buttons.forEach(button => {
button.disabled = false;
});
}, 5000);
}
okButton.addEventListener('click', () => {
disableButtons();
history.back();
alertBox.style.display = 'none';
});
cancelButton.addEventListener('click', () => {
disableButtons();
alertBox.style.display = 'none';
});
alertContainer.appendChild(alertMessage);
alertContainer.appendChild(document.createElement('br'));
buttons.forEach(button => {
alertContainer.appendChild(button);
});
alertBox.appendChild(alertContainer);
document.body.appendChild(alertBox);
}
}
} else {
urlChanges = 0;
if (!timerId) {
timerId = setTimeout(function() {
urlChanges = 0;
timerId = null;
}, 10000);
}
}
}, 5000);