-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwos.html
165 lines (149 loc) · 5.05 KB
/
wos.html
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE html>
<html>
<head>
<title>Write or Thrive</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f0f0f0;
}
#writing-area {
width: 80%;
height: 200px;
padding: 10px;
font-size: 16px;
margin: 20px auto;
border: 1px solid #ccc;
border-radius: 5px;
}
#word-count, #timer {
font-size: 18px;
margin: 10px;
}
#word-target, #time-limit {
font-size: 16px;
margin: 5px;
padding: 5px;
}
#word-count {
font-weight: bold;
}
.input-container {
margin: 20px;
}
.button {
background-color: #0074D9;
color: white;
font-size: 16px;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Write or Thrive</h1>
<textarea id="writing-area" placeholder="Start writing..."></textarea>
<div id="word-count">Word Count: 0</div>
<div class="input-container">
<label for="word-target">Word Target:</label>
<input type="number" id="word-target" min="1" value="500">
</div>
<div class="input-container">
<label for="time-limit">Time Limit (in minutes):</label>
<input type="number" id="time-limit" min="1" value="15">
</div>
<div id="timer">Time Left: 15:00</div>
<button class="button" id="start-button">Start</button>
<audio id="scream-audio" src="https://www.partnersinrhyme.com/files/sounds1/WAV/human/screamf1.wav"></audio>
<script>
let inactivityTimer;
let countdownTimer;
let isScreenRed = false;
let wordCount = 0;
let timeLimit = 15; // Default time limit is 15 minutes
let timeLeft = timeLimit * 60; // Convert minutes to seconds
let isStarted = false;
const writingArea = document.getElementById('writing-area');
const wordCountDisplay = document.getElementById('word-count');
const wordTargetInput = document.getElementById('word-target');
const timeLimitInput = document.getElementById('time-limit');
const timerDisplay = document.getElementById('timer');
const startButton = document.getElementById('start-button');
const screamAudio = document.getElementById('scream-audio');
function playScream() {
screamAudio.play();
}
function stopScream() {
screamAudio.pause();
screamAudio.currentTime = 0;
}
function turnScreenRed() {
document.body.style.backgroundColor = 'red';
playScream();
isScreenRed = true;
}
function resetScreen() {
document.body.style.backgroundColor = 'white';
isScreenRed = false;
stopScream();
}
function startInactivityTimer() {
clearTimeout(inactivityTimer);
if (isStarted) {
inactivityTimer = setTimeout(turnScreenRed, 10000); // 10 seconds
}
}
function startCountdownTimer() {
clearInterval(countdownTimer);
timeLeft = timeLimit * 60;
updateTimerDisplay();
countdownTimer = setInterval(updateTimer, 1000);
}
function updateTimer() {
timeLeft--;
updateTimerDisplay();
if (timeLeft === 0) {
clearInterval(countdownTimer);
alert('Time limit reached!');
}
}
function updateTimerDisplay() {
const minutes = Math.floor(timeLeft / 60);
const seconds = timeLeft % 60;
timerDisplay.textContent = `Time Left: ${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
}
function updateWordCount() {
const text = writingArea.value;
const words = text.trim().split(/\s+/);
wordCount = words.length;
wordCountDisplay.textContent = `Word Count: ${wordCount}`;
}
function checkWordTarget() {
const target = parseInt(wordTargetInput.value, 10);
if (wordCount >= target) {
alert(`Word target of ${target} reached!`);
}
}
writingArea.addEventListener('input', function() {
startInactivityTimer();
resetScreen();
updateWordCount();
checkWordTarget();
});
wordTargetInput.addEventListener('input', checkWordTarget);
timeLimitInput.addEventListener('input', function() {
timeLimit = parseInt(timeLimitInput.value, 10);
startInactivityTimer();
startCountdownTimer();
});
startButton.addEventListener('click', function() {
isStarted = true;
startInactivityTimer();
startCountdownTimer();
});
</script>
</body>
</html>