-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtabcloser.js
More file actions
95 lines (77 loc) · 2.75 KB
/
Copy pathtabcloser.js
File metadata and controls
95 lines (77 loc) · 2.75 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
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
let status;
let allowTime =7200000; //ms
let closeTime =600000; // ms
let leftTime = allowTime / 1000; //s
let showTime = 2 + "h "+ 0+"m "+ 0+ " s";
let myDiv;
let myP;
// save the status var in the browser local storage
if(localStorage.getItem('status') === null) {
status = true
} else {
status = JSON.parse(localStorage.getItem('status'));
}
// set the status
function allow(status) {
let statusStr=JSON.stringify(status);
localStorage.setItem('status', statusStr);
}
// get out
function getOut() {
let reactRoot = document.getElementById("react-root")
reactRoot?.remove();
document.title = "Go Away"
myDiv = document.createElement("div");
myDiv.innerText = `You have work to do! \n You may leave here. NOW!`;
myDiv.style.cssText = "width : 100%; height : 100%; text-align : center; color :red; font-weight:bold; font-size:40px; padding-top: 100px; background-color:black;"
myP = document.createElement("p");
myP.innerHTML =`I'll let you back <span id="showTime"></span> after closing or stop refreshing this tab!`;
myP.style.color = "green";
document.body.appendChild(myDiv).appendChild(myP)
document.body.style.backgroundColor = "black"
document.getElementById("showTime").style.color = "red"
}
//get out after a specific time
function showTimeEverySec() {
allow(false)
getOut()
//show the initial time
document.getElementById("showTime").innerText = showTime;
//show time every second
let eveySec = setInterval(() => {
let hours = Math.floor(leftTime / (60 * 60));
let minutes = Math.floor((leftTime % (60 * 60)) / 60);
let seconds = Math.floor(leftTime % 60);
showTime = ((hours != 0)?(hours + "h "):"") + ((minutes !=0)?(minutes + "m "):"") + seconds + "s ";
if(leftTime == 0 ){
myP.innerText = `Now you can refresh the page and have fun for 10 min`
}
else{
document.getElementById("showTime").innerText = showTime;
leftTime = leftTime - 1;
}
}, 1000)
setTimeout(() => {
clearInterval(eveySec)
}, (allowTime + 3000));
}
setTimeout(() => {
showTimeEverySec()
}, closeTime );
// allow again every XXX seconds
setInterval(() => {
allow(true)
}, (allowTime + closeTime));
// get out, if the status is false
if(!status){
showTimeEverySec()
}
// Hide the notification Number
let checkNotificationsLoad = setInterval(hideIfExist, 100);
function hideIfExist() {
let el = document.querySelector('[aria-live]')
document.title = "Twitter"
if(el != null) {
el.style.visibility = "hidden"
clearInterval(checkNotificationsLoad)}
}