-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathContent.js
413 lines (392 loc) · 9.01 KB
/
Content.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
const earth = `.center{
position: absolute;
background-color: #39beff;
width: 30vh;
height: 30vh;
border-radius: 30vh;
overflow: hidden;
}
.con{
background-color: #238f35;
}
.sea{
background-color: #39beff;
}
#c0{
border-radius: 29% 44% 100% 0% / 43% 75% 51% 41% ;
margin-top: -1px;
width: 15vh;
height: 15vh;
}
#c1{
border-radius:35% 100% 100% 100% / 53% 74% 41% 0% ;
width: 25vh;
height: 25vh;
margin-top: 8vh;
margin-left: 3vh;
}
#c2{
border-radius:100% 83% 100% 78% / 69% 95% 21% 74% ;
width: 15vh;
height: 10vh;
margin-top: -28vh;
margin-left: 1vh;
}
#s0{
border-radius: 100% 83% 100% 78% / 69% 95% 21% 74% ;
width: 20vh;
height: 10vh;
margin-top: -13.2vh;
margin-left: 15.4vh;
}
#c3{
border-radius: 100% 83% 100% 78% / 69% 95% 21% 74% ;
width: 20vh;
height: 20vh;
margin-top: -28vh;
margin-left: 23.9vh;
}
.orbit{
position: absolute;
background-color: #ff009500;
width: 55vh;
height: 55vh;
border-radius: 55vh;
display: flex;
align-items: center;
animation: spin-right 30s linear infinite;
}
@keyframes spin-right {
100%{
transform: rotate(360deg);
}
} `
// contentscript.js
const css = [
/* heart */
`${earth}
#edge1 {
position: relative;
width: 10vh;
height: 9vh;
rotate: -90deg;
margin-left: 4vh;
}
#edge1:before,
#edge1:after {
position: absolute;
content: "";
left: 5vh;
top: 0;
width: 5vh;
height: 8vh;
background: red;
border-radius: 5vh 5vh 0 0;
transform: rotate(-135deg);
transform-origin: 0 100%;
}
#edge1:after {
left: 0;
transform: rotate(-45deg);
transform-origin: 100% 100%;
}`
,
/* moon 3*/
`${earth}
#edge1 {
margin-left: -2vh;
width: 8vh;
height: 8vh;
border-radius: 50%;
box-shadow: 2vh 2vh 0 0 rgb(255, 238, 0);
} `,
/* tree 2*/
`${earth}
#edge1{
background-color: #116b20;
width: 8vh;
height: 8vh;
border-radius: 8vh;
}
#edge2{
margin-left: -4vh;
width: 0;
height: 0;
border-top: 2vh solid transparent;
border-bottom: 2vh solid transparent;
border-right: 9vh solid #4e3728;
} `,
/* 턴테이블 ver 3*/
`.center{
position: absolute;
background-color: #414141;
width: 30vh;
height: 30vh;
border-radius: 30vh;
display: flex;
align-items: center;
justify-content: center;
animation: spin-right 30s linear infinite;
}
#c1{
position: absolute;
background-color: #000000;
width: 4vh;
height: 4vh;
border-radius: 4vh;
}
#c0{
position: absolute;
background-color: #cf5739;
width: 10vh;
height: 10vh;
border: 0.5vh solid #fff;
border-radius: 10vh;
}
#c2{
position: absolute;
background-color: transparent;
width: 17vh;
height: 17vh;
border-radius: 17vh;
border: 1vh solid transparent;
border-top: .8vh solid rgb(44, 44, 44);
border-right: .8vh solid rgb(44, 44, 44);
border-left: .8vh solid rgb(44, 44, 44);
}
#c3{
position: absolute;
background-color: transparent;
width: 23vh;
height: 23vh;
border-radius: 23vh;
border: 1vh solid transparent;
border-right: .8vh solid rgb(44, 44, 44);
border-top: .8vh solid rgb(150, 150, 150);
border-left: .8vh solid rgb(44, 44, 44);
}
#s0{
position: absolute;
background-color: transparent;
width: 20vh;
height: 20vh;
border-radius: 20vh;
border: 1vh solid transparent;
border-bottom: .8vh solid rgb(150, 150, 150);
}
.orbit{
position: absolute;
background-color: #ff009500;
width: 55vh;
height: 55vh;
border-radius: 55vh;
display: flex;
align-items: center;
}
@keyframes spin-right {
100%{
transform: rotate(360deg);
}
}
#edge1{
background-color: #f3cf00;
width: 5vh;
height: 3vh;
border-radius: 3vh;
transform: rotate(30deg);
margin-left: 15vh;
margin-top: 10vh;
}
#edge2{
background-color: #f3cf00;
width: 10vh;
height: 1vh;
border-radius: 1vh;
transform: rotate(30deg);
margin-left: -12vh;
margin-top: 4.5vh;
}
#edge3{
background-color: #f3cf00;
width: 1vh;
height: 15vh;
border-radius: 1vh;
margin-left: -9.5vh;
margin-top: -14vh;
} `
]
const generateSTYLES = (theme) => {
return `<style>@import url(https://fonts.googleapis.com/css?family=opensans:500);
body {
background: #15095c;
color: #fff;
font-family: "Open Sans", sans-serif;
max-height: 700px;
overflow: hidden;
}
.top{
width: 100%;
height: 60vh;
display: flex;
align-items: center;
justify-content: center;
margin-top: 2vh;
}
${css[theme]}
.bottom {
text-align: center;
display: block;
position: relative;
width: 80%;
margin-left: 10%;
margin-top: 2vh;
}
._1 {
text-align: center;
display: block;
position: relative;
letter-spacing: 12px;
font-size: 4em;
line-height: 80%;
padding: 10px;
}
._2 {
text-align: center;
display: block;
position: relative;
font-size: 20px;
padding: 10px;
}
hr {
padding: 0;
border: none;
border-top: 5px solid #fff;
color: #fff;
text-align: center;
margin: 0px auto;
width: 420px;
height: 10px;
z-index: -10;
}
hr:after {
display: inline-block;
position: relative;
top: -0.75em;
font-size: 2em;
padding: 0 0.2em;
background: #33cc99;
}
.btn{
color: #fff;
border: none;
margin: 20px;
padding: 20px 30px;
font-size: 18px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 4px;
cursor: pointer;
border-radius: 5px;
transition: 0.5s;
transition-property: box-shadow;
}
.btn-primary{
background: #50A7FF;
box-shadow: 0 0 25px #50A7FF;
}
.btn-primary:hover{
box-shadow: 0 0 5px #50A7FF,
0 0 25px #50A7FF,
0 0 50px #50A7FF,
0 0 100px #50A7FF;
}
</style>`;
};
const generateHTML = (pageName) => {
return `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>ScreenSaver</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="screen.css">
</head>
<body>
<div class="top">
<div class="center">
<div class="con" id="c0"></div>
<div class="con" id="c1"></div>
<div class="con" id="c2"></div>
<div class="sea" id="s0"></div>
<div class="con" id="c3"></div>
</div>
<div class="orbit">
<div id="edge1"></div>
<div id="edge2"></div>
<div id="edge3"></div>
</div>
</div>
<div class='bottom'>
<hr>
<div class='_1'>GET BACK TO WORK</div>
<div class='_2'>STUDYING > ${pageName}</div>
<button type="button" class="btn btn-primary active" id="gameBtn">게임해서 잠금해제</button>
</div>
</body>
</html>
`;
};
function gameBtnFunc(){
chrome.runtime.sendMessage({hostname: window.location.hostname, isgame: true}, (response) => {
if(response.blocked == "game blocked"){
alert("오늘은 더 이상 게임을 시도할 수 없습니다.")
// document.location.href = `http://192.249.18.156:443/spacegame?id=${response.userid}&hostname=${window.location.hostname}&time=240000` // 1분 안에 통과해야 함
}
else{
document.location.href= `http://192.249.18.156:443/spacegame?id=${response.userid}&hostname=${window.location.hostname}&time=240000` // 1분 안에 통과해야 함
// should remove after debugging!!
}
})
}
function drawHTML(theme){
document.head.innerHTML = generateSTYLES(theme);
document.body.innerHTML = generateHTML("This Page is Blocked");
const btn = document.getElementById("gameBtn")
btn.addEventListener('click',()=>{
gameBtnFunc()
})
}
const GAMEHOST = "192.249.18.156"
if(window.location.hostname!==GAMEHOST){
chrome.runtime.sendMessage({hostname: window.location.hostname, isgame: false}, (response) => {
// 처음 접속에서 blocked인지 확인
console.log(window.location.hostname)
console.log(response.blocked);
userid = response.userid
if(response.blocked === "blocked"){
// 만약 blocked이면 blocked로 두면 됨
let theme = response.theme
drawHTML(theme)
}
else if(response.blocked === "not yet"){
// 아직 blocked가 아닌 경우, 인터벌마다 다시 bloked인지 확인함.
setTimeout(function run(){
chrome.runtime.sendMessage({hostname: window.location.hostname}, (response) => {
console.log(response.blocked);
if(response.blocked === "blocked"){
// 만약 blocked가 되면 timeout 지우고 blocked로 두기.
clearTimeout() // TODO timeout 바꾸기
let theme = response.theme
drawHTML(theme)
}
})
setTimeout(run, 30000); // 1분 (60초) 마다
}, 30000);
}
else{
// 만약 blocked site가 아닌 경우 걍 아무 동작도 하지 않고 함수 끝냄.
}
})
}