|
| 1 | +/* |
| 2 | +
|
| 3 | + _______ ,-----. .-------. ,---. .--..-./`) ________ ____ __ |
| 4 | + / __ \ .' .-, '. | _ _ \ | \ | |\ .-.')| | \ \ / / |
| 5 | + | ,_/ \__) / ,-.| \ _ \ | ( ' ) | | , \ | |/ `-' \| .----' \ _. / ' |
| 6 | +,-./ ) ; \ '_ / | :|(_ o _) / | |\_ \| | `-'`"`| _|____ _( )_ .' |
| 7 | +\ '_ '`) | _`,/ \ _/ || (_,_).' __ | _( )_\ | .---. |_( )_ | ___(_ o _)' |
| 8 | + > (_) ) __: ( '\_/ \ ;| |\ \ | || (_ o _) | | | (_ o._)__|| |(_,_)' |
| 9 | +( . .-'_/ )\ `"/ \ ) / | | \ `' /| (_,_)\ | | | |(_,_) | `-' / |
| 10 | + `-'`-' / '. \_/``".' | | \ / | | | | | | | | \ / |
| 11 | + `._____.' '-----' ''-' `'-' '--' '--' '---' '---' `-..-' |
| 12 | +
|
| 13 | + This script has been modified by @wesbos because |
| 14 | + https://twitter.com/wesbos/status/1657012836403388416 |
| 15 | +
|
| 16 | +*/ |
| 17 | + |
| 18 | +var cornify_count = 0; |
| 19 | +var cornify_add = function (options) { |
| 20 | + // Track how often we cornified. |
| 21 | + cornify_count += 1; |
| 22 | + |
| 23 | + // Prepare our lovely variables. |
| 24 | + var cornify_url = "https://www.cornify.com/"; |
| 25 | + var numType = "px"; |
| 26 | + var heightRandom = Math.random() * 0.75; |
| 27 | + var windowHeight = 768; |
| 28 | + var windowWidth = 1024; |
| 29 | + var height = 0; |
| 30 | + var width = 0; |
| 31 | + var de = document.documentElement; |
| 32 | + var transform = "translate(-50%, -50%)"; |
| 33 | + var showGrandUnicorn = cornify_count == 15; |
| 34 | + |
| 35 | + // Create a container for our 'corn or 'bow. |
| 36 | + var div = document.createElement("div"); |
| 37 | + div.style.position = "fixed"; |
| 38 | + div.className = "__cornify_unicorn"; |
| 39 | + div.style.zIndex = 143143; |
| 40 | + div.style.outline = 0; |
| 41 | + div.onclick = cornify_add; // Click for more magic. |
| 42 | + |
| 43 | + // Get the window width and height - requires some cross browser checking. |
| 44 | + if (typeof window.innerHeight == "number") { |
| 45 | + windowHeight = window.innerHeight; |
| 46 | + windowWidth = window.innerWidth; |
| 47 | + } else if (de && de.clientHeight) { |
| 48 | + windowHeight = de.clientHeight; |
| 49 | + windowWidth = de.clientWidth; |
| 50 | + } else { |
| 51 | + numType = "%"; |
| 52 | + height = Math.round(height * 100) + "%"; |
| 53 | + } |
| 54 | + |
| 55 | + if (showGrandUnicorn) { |
| 56 | + // Clicking 15 times summons the grand unicorn - which is centered on the screen. |
| 57 | + div.style.top = "50%"; |
| 58 | + div.style.left = "50%"; |
| 59 | + div.style.zIndex = 143143143; |
| 60 | + } else { |
| 61 | + // Otherwise we randomize the position. |
| 62 | + div.style.top = Math.round(Math.random() * 100) + "%"; |
| 63 | + div.style.left = Math.round(Math.random() * 100) + "%"; |
| 64 | + |
| 65 | + transform += " rotate(" + Math.round(Math.random() * 10 - 5) + "deg)"; |
| 66 | + } |
| 67 | + |
| 68 | + // Create the image element. |
| 69 | + var img = document.createElement("img"); |
| 70 | + img.style.opacity = 0; |
| 71 | + img.style.transition = "all .1s linear"; |
| 72 | + img.alt = "A lovely unicorn or rainbow"; |
| 73 | + img.onload = function () { |
| 74 | + img.style.opacity = 1; |
| 75 | + }; |
| 76 | + |
| 77 | + // Used as a cache buster so the browser makes a new request every time instead of usign the previous, cached one. |
| 78 | + var currentTime = new Date(); |
| 79 | + var submitTime = currentTime.getTime(); |
| 80 | + |
| 81 | + if (showGrandUnicorn) { |
| 82 | + // Caching doesn't matter for the Grand Unicorn. |
| 83 | + submitTime = 0; |
| 84 | + } |
| 85 | + |
| 86 | + // Construct our unicorn & rainbow request. |
| 87 | + var url = `https://www.cornify.com/corns/${ |
| 88 | + Math.random() > 0.5 ? "r" : "u" |
| 89 | + }${Math.ceil(Math.random() * 7)}.gif`; |
| 90 | + |
| 91 | + // Add younicorns if requested. |
| 92 | + if (options && (options.y || options.younicorns)) { |
| 93 | + url += "&y=" + (options.y ? options.y : options.younicorns); |
| 94 | + |
| 95 | + if (Math.random() > 0.5) { |
| 96 | + // Flip horizontally at random. |
| 97 | + if (transform.length > 0) { |
| 98 | + transform += " scaleX(-1)"; |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + div.style.transform = transform; |
| 104 | + div.style.MozTransform = transform; |
| 105 | + div.style.webkitTransform = transform; |
| 106 | + |
| 107 | + img.setAttribute("src", url); |
| 108 | + |
| 109 | + // Add a nice hover wigggle. |
| 110 | + img.style.transition = "all .1s linear"; |
| 111 | + |
| 112 | + div.onmouseover = function () { |
| 113 | + var size = 1 + Math.round(Math.random() * 10) / 100; |
| 114 | + var angle = Math.round(Math.random() * 20 - 10); |
| 115 | + var result = "rotate(" + angle + "deg) scale(" + size + "," + size + ")"; |
| 116 | + img.style.transform = result; |
| 117 | + img.style.MozTransform = result; |
| 118 | + img.style.webkitTransform = result; |
| 119 | + }; |
| 120 | + |
| 121 | + div.onmouseout = function () { |
| 122 | + var size = 0.9 + Math.round(Math.random() * 10) / 100; |
| 123 | + var angle = Math.round(Math.random() * 6 - 3); |
| 124 | + var result = "rotate(" + angle + "deg) scale(" + size + "," + size + ")"; |
| 125 | + img.style.transform = result; |
| 126 | + img.style.MozTransform = result; |
| 127 | + img.style.webkitTransform = result; |
| 128 | + }; |
| 129 | + |
| 130 | + // Append our container DIV to the page. |
| 131 | + var body = document.getElementsByTagName("body")[0]; |
| 132 | + body.appendChild(div); |
| 133 | + div.appendChild(img); |
| 134 | + |
| 135 | + // Hooray - now we have a sparkly unicorn (or rainbow) on the page. Another cornification well done. Congrats! |
| 136 | + |
| 137 | + // When clicking 5 times, add a custom stylesheet to make the page look awesome. |
| 138 | + if (cornify_count == 5) { |
| 139 | + var cssExisting = document.getElementById("__cornify_css"); |
| 140 | + |
| 141 | + if (!cssExisting) { |
| 142 | + var head = document.getElementsByTagName("head")[0]; |
| 143 | + var css = document.createElement("link"); |
| 144 | + css.id = "__cornify_css"; |
| 145 | + css.type = "text/css"; |
| 146 | + css.rel = "stylesheet"; |
| 147 | + css.href = "https://www.cornify.com/css/cornify.css"; |
| 148 | + css.media = "screen"; |
| 149 | + head.appendChild(css); |
| 150 | + } |
| 151 | + cornify_replace(); |
| 152 | + } |
| 153 | + |
| 154 | + cornify_updatecount(); |
| 155 | + |
| 156 | + // Trigger an event on the document. |
| 157 | + var event = new Event("cornify"); |
| 158 | + document.dispatchEvent(event); |
| 159 | +}; |
| 160 | + |
| 161 | +// Tracks how often we cornified. |
| 162 | +var cornify_updatecount = function () { |
| 163 | + var id = "__cornify_count"; |
| 164 | + var p = document.getElementById(id); |
| 165 | + |
| 166 | + if (p == null) { |
| 167 | + var p = document.createElement("p"); |
| 168 | + p.id = id; |
| 169 | + p.style.position = "fixed"; |
| 170 | + p.style.bottom = "5px"; |
| 171 | + p.style.left = "0px"; |
| 172 | + p.style.right = "0px"; |
| 173 | + p.style.zIndex = "1000000000"; |
| 174 | + p.style.color = "#ff00ff"; |
| 175 | + p.style.textAlign = "center"; |
| 176 | + p.style.fontSize = "24px"; |
| 177 | + p.style.fontFamily = "'Comic Sans MS', 'Comic Sans', 'Marker Felt', serif"; // Only the best! |
| 178 | + p.style.textTransform = "uppercase"; |
| 179 | + var body = document.getElementsByTagName("body")[0]; |
| 180 | + body.appendChild(p); |
| 181 | + } |
| 182 | + |
| 183 | + if (cornify_count == 1) { |
| 184 | + p.innerHTML = "You cornified!"; |
| 185 | + } else { |
| 186 | + p.innerHTML = "You cornified " + cornify_count + " times!"; |
| 187 | + } |
| 188 | + |
| 189 | + // Stores our count in a cookie for our next session. |
| 190 | + cornify_setcookie("cornify", cornify_count + "", 1000); |
| 191 | +}; |
| 192 | + |
| 193 | +var cornify_setcookie = function (name, value, days) { |
| 194 | + var d = new Date(); |
| 195 | + d.setTime(d.getTime() + days * 24 * 60 * 60 * 1000); |
| 196 | + var expires = "expires=" + d.toGMTString(); |
| 197 | + document.cookie = name + "=" + value + "; " + expires; |
| 198 | +}; |
| 199 | + |
| 200 | +var cornify_getcookie = function (cname) { |
| 201 | + var name = cname + "="; |
| 202 | + var ca = document.cookie.split(";"); |
| 203 | + for (var i = 0; i < ca.length; i++) { |
| 204 | + var c = ca[i].trim(); |
| 205 | + if (c.indexOf(name) == 0) { |
| 206 | + return c.substring(name.length, c.length); |
| 207 | + } |
| 208 | + } |
| 209 | + return ""; |
| 210 | +}; |
| 211 | + |
| 212 | +// Retrieve our click count from the cookie when we start up. |
| 213 | +cornify_count = parseInt(cornify_getcookie("cornify")); |
| 214 | +if (isNaN(cornify_count)) { |
| 215 | + cornify_count = 0; |
| 216 | +} |
| 217 | + |
| 218 | +// Adds happy words at the beginning of all headers on the page. |
| 219 | +var cornify_replace = function () { |
| 220 | + // Replace text. |
| 221 | + var hc = 6; |
| 222 | + var hs; |
| 223 | + var h; |
| 224 | + var k; |
| 225 | + var words = [ |
| 226 | + "Happy", |
| 227 | + "Sparkly", |
| 228 | + "Glittery", |
| 229 | + "Fun", |
| 230 | + "Magical", |
| 231 | + "Lovely", |
| 232 | + "Cute", |
| 233 | + "Charming", |
| 234 | + "Amazing", |
| 235 | + "Wonderful", |
| 236 | + ]; |
| 237 | + while (hc >= 1) { |
| 238 | + hs = document.getElementsByTagName("h" + hc); |
| 239 | + for (k = 0; k < hs.length; k++) { |
| 240 | + h = hs[k]; |
| 241 | + h.innerHTML = |
| 242 | + words[Math.floor(Math.random() * words.length)] + " " + h.innerHTML; |
| 243 | + } |
| 244 | + hc -= 1; |
| 245 | + } |
| 246 | +}; |
| 247 | + |
| 248 | +// Adds happy words at the beginning of all headers on the page. |
| 249 | +var cornify_replace = function () { |
| 250 | + var headerTypeIndex = 6; |
| 251 | + var headerElements; |
| 252 | + var headerElement; |
| 253 | + var i; |
| 254 | + var magicalWords = [ |
| 255 | + "Happy", |
| 256 | + "Sparkly", |
| 257 | + "Glittery", |
| 258 | + "Fun", |
| 259 | + "Magical", |
| 260 | + "Lovely", |
| 261 | + "Cute", |
| 262 | + "Charming", |
| 263 | + "Amazing", |
| 264 | + "Wonderful", |
| 265 | + ]; |
| 266 | + |
| 267 | + while (headerTypeIndex >= 1) { |
| 268 | + headerElements = document.getElementsByTagName("h" + headerTypeIndex); |
| 269 | + |
| 270 | + for (i = 0; i < headerElements.length; i++) { |
| 271 | + headerElement = headerElements[i]; |
| 272 | + headerElement.innerHTML = |
| 273 | + magicalWords[Math.floor(Math.random() * magicalWords.length)] + |
| 274 | + " " + |
| 275 | + headerElement.innerHTML; |
| 276 | + } |
| 277 | + |
| 278 | + headerTypeIndex -= 1; |
| 279 | + } |
| 280 | +}; |
| 281 | + |
| 282 | +// Clicking the rainbow cupcake button makes all the unicorns |
| 283 | +// disappear (should only be used in an emergency, since it's sad). |
| 284 | +var cornify_click_cupcake_button = function () { |
| 285 | + var doc = document; |
| 286 | + |
| 287 | + var corns = doc.getElementsByClassName("__cornify_unicorn"); |
| 288 | + if (corns) { |
| 289 | + for (var i = 0; i < corns.length; i++) { |
| 290 | + corns[i].parentNode.removeChild(corns[i]); |
| 291 | + } |
| 292 | + } |
| 293 | + |
| 294 | + // Remove our counter. |
| 295 | + var button = doc.getElementById("__cornify_count"); |
| 296 | + if (button) { |
| 297 | + button.parentNode.removeChild(button); |
| 298 | + } |
| 299 | + |
| 300 | + // Remove the cupcake button. |
| 301 | + var button = doc.getElementById("__cornify_cupcake_button"); |
| 302 | + if (button) { |
| 303 | + button.parentNode.removeChild(button); |
| 304 | + } |
| 305 | + |
| 306 | + var event = new Event("cornify-clear"); |
| 307 | + document.dispatchEvent(event); |
| 308 | +}; |
| 309 | + |
| 310 | +// Add the rainbow cupcake button to the page. |
| 311 | +var cornify_add_cupcake_button = function () { |
| 312 | + var id = "__cornify_cupcake_button"; |
| 313 | + var doc = document; |
| 314 | + var button = doc.getElementById(id); |
| 315 | + |
| 316 | + if (!button) { |
| 317 | + button = doc.createElement("div"); |
| 318 | + button.id = id; |
| 319 | + button.onclick = cornify_click_cupcake_button; |
| 320 | + button.style.position = "fixed"; |
| 321 | + button.style.top = "10px"; |
| 322 | + button.style.right = "10px"; |
| 323 | + button.style.zIndex = 2147483640; |
| 324 | + button.setAttribute("aria-label", "Hide unicorns and rainbows"); |
| 325 | + |
| 326 | + var image = document.createElement("img"); |
| 327 | + image.src = "https://www.cornify.com/assets/cornify-cupcake-button.png"; |
| 328 | + image.alt = "Cupcake button"; |
| 329 | + image.width = 50; |
| 330 | + image.height = 50; |
| 331 | + image.style.width = "50px !important"; |
| 332 | + image.style.height = "50px !important"; |
| 333 | + image.style.display = "block !important"; |
| 334 | + image.style.cursor = "pointer !important"; |
| 335 | + image.style.margin = "0 !important"; |
| 336 | + image.style.padding = "0 !important"; |
| 337 | + button.appendChild(image); |
| 338 | + |
| 339 | + doc.getElementsByTagName("body")[0].appendChild(button); |
| 340 | + } |
| 341 | +}; |
| 342 | + |
| 343 | +// Adapted from http://www.snaptortoise.com/konami-js/ |
| 344 | +var cornami = { |
| 345 | + input: "", |
| 346 | + pattern: "38384040373937396665", |
| 347 | + clear: setTimeout("cornami.clear_input()", 5000), |
| 348 | + load: function () { |
| 349 | + window.document.onkeydown = function (event) { |
| 350 | + if (cornami.input == cornami.pattern) { |
| 351 | + cornify_add(); |
| 352 | + clearTimeout(cornami.clear); |
| 353 | + return; |
| 354 | + } else { |
| 355 | + cornami.input += event.keyCode; |
| 356 | + if (cornami.input == cornami.pattern) { |
| 357 | + cornify_add(); |
| 358 | + } |
| 359 | + clearTimeout(cornami.clear); |
| 360 | + cornami.clear = setTimeout("cornami.clear_input()", 5000); |
| 361 | + } |
| 362 | + }; |
| 363 | + }, |
| 364 | + clear_input: function () { |
| 365 | + cornami.input = ""; |
| 366 | + clearTimeout(cornami.clear); |
| 367 | + }, |
| 368 | +}; |
| 369 | + |
| 370 | +cornami.load(); |
0 commit comments