-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
46 lines (42 loc) · 1.77 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cat Screen Saver</title>
</head>
<!-- TODO: hiding the mouse cursor would be nice, but cursor: none doesn't work -->
<!-- Also, don't use the style attribute, ever. Okay, maybe just this time... -->
<body id="body" style="background-color: black; background-size: cover;">
<script>
// require ipc to tell the app to close when needed
var ipc = require('ipc');
var sendQuit = function(){
ipc.send('sendQuit');
}
document.addEventListener('keydown', sendQuit);
document.addEventListener('mousedown', sendQuit);
// Also quit on mouse movement, but delay mousemove tracking, otherwise we'll close immediately
setTimeout( function() {
var treshold = 5;
document.addEventListener('mousemove', function(e) {
if (treshold * treshold < e.movementX * e.movementX
+ e.movementY * e.movementY) {
sendQuit();
}
});
}, 3000);
// And now the fun part – the actual thing the screensaver displays. Replace this with your own creation!
var body = document.getElementById("body"); //you now, I wanted to be lazy on this
var changeImage = function() {
var url = "http://lorempixel.com/" + innerWidth + "/" + innerHeight + "/cats/" + Math.ceil(Math.random() * 10);
var preloader = new Image();
preloader.src = url;
preloader.onload = function() {
body.style.backgroundImage = "url('" + url + "')";
setTimeout(changeImage, 2000);
};
}
changeImage();
</script>
</body>
</html>