-
Notifications
You must be signed in to change notification settings - Fork 0
/
moosify.js
178 lines (165 loc) · 5.81 KB
/
moosify.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
var moosify_count = 0;
var numImages = 7;
var moosify_add = function() {
moosify_count += 1;
var div = document.createElement('div');
div.style.position = 'fixed';
var numType = 'px';
var heightRandom = Math.random() * .75;
var windowHeight = 768;
var windowWidth = 1024;
var height = 0;
var width = 0;
var de = document.documentElement;
if (typeof(window.innerHeight) == 'number') {
windowHeight = window.innerHeight;
windowWidth = window.innerWidth;
} else if (de && de.clientHeight) {
windowHeight = de.clientHeight;
windowWidth = de.clientWidth;
} else {
numType = '%';
height = Math.round(height * 100) + '%';
}
div.onclick = moosify_add;
div.style.zIndex = 10;
div.style.outline = 0;
if (moosify_count == 15) {
div.style.top = Math.max(0, Math.round((windowHeight - 530) / 2)) + 'px';
div.style.left = Math.round((windowWidth - 530) / 2) + 'px';
div.style.zIndex = 1000;
} else {
if (numType == 'px') div.style.top = Math.round(windowHeight * heightRandom) + numType;
else div.style.top = height;
div.style.left = Math.round(Math.random() * 90) + '%';
}
var img = document.createElement('img');
var currentTime = new Date();
var submitTime = currentTime.getTime();
var random = submitTime % numImages;
img.setAttribute('src', 'moose-' + random.toString(10) + ".png");
var ease = "all .1s linear";
div.style.WebkitTransition = ease;
div.style.WebkitTransform = "rotate(1deg) scale(1.01,1.01)";
div.style.transition = "all .1s linear";
div.onmouseover = function() {
var size = 1 + Math.round(Math.random() * 10) / 100;
var angle = Math.round(Math.random() * 20 - 10);
var result = "rotate(" + angle + "deg) scale(" + size + "," + size + ")";
this.style.transform = result;
this.style.WebkitTransform = result;
};
div.onmouseout = function() {
var size = .9 + Math.round(Math.random() * 10) / 100;
var angle = Math.round(Math.random() * 6 - 3);
var result = "rotate(" + angle + "deg) scale(" + size + "," + size + ")";
this.style.transform = result;
this.style.WebkitTransform = result;
};
var body = document.getElementsByTagName('body')[0];
body.appendChild(div);
div.appendChild(img);
// Add stylesheet.
if (moosify_count == 5) {
var cssExisting = document.getElementById('__moosify_css');
if (!cssExisting) {
var head = document.getElementsByTagName("head")[0];
var css = document.createElement('link');
css.id = '__moosify_css';
css.type = 'text/css';
css.rel = 'stylesheet';
css.href = 'moosify.css';
css.media = 'screen';
head.appendChild(css);
}
moosify_replace();
}
moosify_updatecount();
};
var moosify_updatecount = function() {
var p = document.getElementById('moosifycount');
if (p == null) {
var p = document.createElement('p');
p.id = 'moosifycount';
p.style.position = 'fixed';
p.style.bottom = '5px';
p.style.left = '0px';
p.style.right = '0px';
p.style.zIndex = '1000000000';
p.style.color = '#D2691E';
p.style.textShadow = "-1px -1px 0px #000,1px -1px 0px #000,-1px 1px 0px #000,1px 1px 0px #000";
p.style.textAlign = 'center';
p.style.fontSize = '24px';
p.style.fontFamily = '"Helvetica Neue", Helvetica, Arial, sans-serif';
var body = document.getElementsByTagName('body')[0];
body.appendChild(p);
}
p.innerHTML = moosify_count + ' MOOSE CREATED';
if (Math.random() >= 0.5) p.innerHTML = moosify_count + ' MEESE CREATED';
moosify_setcookie('moosify', moosify_count + '', 1000);
};
var moosify_setcookie = function(name, value, days) {
var d = new Date();
d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toGMTString();
document.cookie = name + "=" + value + "; " + expires;
};
var moosify_getcookie = function(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i].trim();
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
};
moosify_count = parseInt(moosify_getcookie('moosify'));
if (isNaN(moosify_count)) {
moosify_count = 0;
}
var moosify_replace = function() {
// Replace text.
var hc = 6;
var hs;
var h;
var k;
var words = ['Majestic', 'Fierce', 'Silly', 'Goofy', 'Large', 'Charming', 'Cute', 'Fantastic', 'Amazing', 'Wonderful'];
while (hc >= 1) {
hs = document.getElementsByTagName('h' + hc);
for (k = 0; k < hs.length; k++) {
h = hs[k];
h.innerHTML = words[Math.floor(Math.random() * words.length)] + ' ' + h.innerHTML;
}
hc -= 1;
}
};
/*
* Adapted from http://www.snaptortoise.com/konami-js/
*/
var moosenami = {
input: "",
// moose
pattern: "7779798369",
clear: setTimeout('moosenami.clear_input()', 5000),
load: function() {
window.document.onkeydown = function(e) {
if (moosenami.input == moosenami.pattern) {
moosify_add();
clearTimeout(moosenami.clear);
return;
} else {
moosenami.input += e ? e.keyCode : event.keyCode;
if (moosenami.input == moosenami.pattern) moosify_add();
clearTimeout(moosenami.clear);
moosenami.clear = setTimeout("moosenami.clear_input()", 5000);
}
};
},
clear_input: function() {
moosenami.input = "";
clearTimeout(moosenami.clear);
}
};
moosenami.load();