chamesle

chamesle.org: the site of Chamesle, a small Linux distribution
git clone https://github.com/tortr-rs/chamesle
Log | Files | Refs | README

egg.js (3835B)


      1 // click the logo three times
      2 (function () {
      3   var img = document.querySelector('.brand img'), clicks = 0, timer, gone = false;
      4   if (!img) return;
      5   img.addEventListener('click', function (e) {
      6     e.preventDefault();
      7     clicks++;
      8     clearTimeout(timer);
      9     timer = setTimeout(function () { clicks = 0; }, 1200);
     10     if (clicks < 3 || gone) return;
     11     gone = true;
     12     var r = img.getBoundingClientRect();
     13     // off it goes, up and to the right
     14     img.style.transition = 'transform .8s cubic-bezier(.5,-.4,.8,.6)';
     15     img.style.transform = 'translate(' + window.innerWidth + 'px,' + (-r.bottom - 60) + 'px) rotate(900deg)';
     16     setTimeout(function () {
     17       // something else comes back from the left
     18       img.style.transition = 'none';
     19       img.src = 'img/egg.png';
     20       img.style.transform = 'translateX(' + (-r.right - 80) + 'px) rotate(-540deg)';
     21       requestAnimationFrame(function () {
     22         requestAnimationFrame(function () {
     23           img.style.transition = 'transform 1s cubic-bezier(.2,.9,.3,1.25)';
     24           img.style.transform = 'none';
     25         });
     26       });
     27     }, 1400);
     28   });
     29 })();
     30 
     31 // up up down down left right left right b a
     32 (function () {
     33   var code = 'arrowup arrowup arrowdown arrowdown arrowleft arrowright arrowleft arrowright b a';
     34   var keys = [], typed = '';
     35   function banner(text, color, sub) {
     36     var d = document.createElement('div');
     37     d.style.cssText = 'position:fixed;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;' +
     38       'background:linear-gradient(transparent 35%,rgba(0,0,0,.75) 45%,rgba(0,0,0,.75) 55%,transparent 65%);' +
     39       'pointer-events:none;opacity:0;transition:opacity 1.2s;z-index:99;font-family:Georgia,"Times New Roman",serif';
     40     d.innerHTML = '<div style="font-size:clamp(28px,6vw,64px);letter-spacing:.08em;color:' + color + ';text-shadow:0 0 18px ' +
     41       color + '88">' + text + '</div>' + (sub ? '<div style="color:#ddd;font-size:18px;margin-top:8px;font-style:italic">' +
     42       sub + '</div>' : '');
     43     document.body.appendChild(d);
     44     requestAnimationFrame(function () { d.style.opacity = 1; });
     45     setTimeout(function () { d.style.opacity = 0; }, 3200);
     46     setTimeout(function () { d.remove(); }, 4600);
     47   }
     48   document.addEventListener('keydown', function (e) {
     49     if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') return;
     50     // the last ten keys, any case, so an extra press at the start doesn't matter
     51     keys = keys.concat(e.key.toLowerCase()).slice(-10);
     52     if (keys.join(' ') === code) {
     53       keys = [];
     54       banner('GREAT ENEMY FELLED', '#e8c872');
     55     }
     56     if (e.key.length === 1) {
     57       typed = (typed + e.key.toLowerCase()).slice(-6);
     58       if (typed === 'margit') banner('MARGIT, THE FELL OMEN', '#d6c79a', 'Put these foolish ambitions to rest!');
     59     }
     60   });
     61 })();
     62 
     63 // type chum
     64 (function () {
     65   var typed = '';
     66   document.addEventListener('keydown', function (e) {
     67     if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' || e.key.length !== 1) return;
     68     typed = (typed + e.key.toLowerCase()).slice(-4);
     69     if (typed !== 'chum') return;
     70     typed = '';
     71     var img = document.createElement('img');
     72     img.src = (location.pathname.indexOf('/') === 0 ? '/' : '') + 'img/chum.png';
     73     var y = 15 + Math.random() * 55;
     74     img.style.cssText = 'position:fixed;width:160px;height:160px;left:100vw;top:' + y + 'vh;z-index:99;' +
     75       'pointer-events:none;transition:left 9s linear,top 9s ease-in-out';
     76     document.body.appendChild(img);
     77     requestAnimationFrame(function () {
     78       requestAnimationFrame(function () {
     79         // he drifts, slowly, and not quite straight
     80         img.style.left = '-200px';
     81         img.style.top = (y + (Math.random() * 20 - 10)) + 'vh';
     82       });
     83     });
     84     setTimeout(function () { img.remove(); }, 9500);
     85   });
     86 })();
     87