-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtir.js
118 lines (106 loc) · 3.48 KB
/
tir.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
document.addEventListener("DOMContentLoaded", function () {
var attempts = 50;
var showDelay = 1200;
var hideDelayMin = 500;
var hideDelayMax = 2500;
var catchDelay = 500;
var targetSize = 12;
var targetSizeExpandMultiplier = 4;
var targetBgColor = "#cc0000";
var targetHighlightBgColor = "#ff0000";
var targetOn = true;
var attemptCounter = 0;
var catchCounter = 0;
var point;
var timeoutId;
function getClientWidth()
{
return document.compatMode === "CSS1Compat" && !window.opera
? document.documentElement.clientWidth
: document.body.clientWidth;
}
function getClientHeight()
{
return document.compatMode === "CSS1Compat" && !window.opera
? document.documentElement.clientHeight
: document.body.clientHeight;
}
function getTitle()
{
return "Catch: " + catchCounter +
", total: " + attemptCounter +
"/" + attempts +
", " + (attemptCounter ? Math.round(catchCounter / attemptCounter * 100) : 0) + "%";
}
function getTargetTop()
{
var pTop = 0;
do {
pTop = Math.round(Math.random() * 2000);
} while ((pTop + targetSize) > getClientHeight());
return pTop;
}
function getTargetLeft()
{
var pLeft = 0;
do {
pLeft = Math.round(Math.random() * 2000);
} while ((pLeft + targetSize) > getClientWidth());
return pLeft;
}
function getTargetHideDelay()
{
var delay = hideDelayMax;
do {
delay = Math.round(Math.random() * hideDelayMax);
} while (delay > hideDelayMax || delay < hideDelayMin);
return delay;
}
function switchTarget()
{
if (!targetOn) {
attemptCounter++;
point.style.display = "block";
targetOn = true;
timeoutId = setTimeout(switchTarget, showDelay);
return;
}
point.style.display = "none";
point.style.backgroundColor = targetBgColor;
point.style.width = targetSize + "px";
point.style.height = targetSize + "px";
targetOn = false;
if (attemptCounter >= attempts) {
clearTimeout(timeoutId);
var s = getTitle();
document.title = s;
alert(s);
return;
}
point.style.left = getTargetLeft() + "px";
point.style.top = getTargetTop() + "px";
timeoutId = setTimeout(switchTarget, getTargetHideDelay());
document.title = getTitle();
}
function catchTarget()
{
clearTimeout(timeoutId);
catchCounter++;
document.title = getTitle();
point.style.display = "block";
point.style.backgroundColor = targetHighlightBgColor;
point.style.width = (targetSize * targetSizeExpandMultiplier) + "px";
point.style.height = (targetSize * targetSizeExpandMultiplier) + "px";
point.style.left = (parseInt(point.style.left, 10) - targetSize) + "px";
point.style.top = (parseInt(point.style.top, 10) - targetSize) + "px";
timeoutId = setTimeout(switchTarget, catchDelay);
}
function init()
{
alert("Lets begin");
point = document.getElementById("point");
point.addEventListener("click", catchTarget);
switchTarget();
}
init();
});