Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 181: Line 181:


(function() {
(function() {
   var typed = '';
   var answers = ['It is certain.','Ask again later.','Outlook not so good.',
  document.addEventListener('keypress', function(e) {
     'Signs point to yes.','Very doubtful.','Without a doubt.','Cannot predict now.','Yes definitely!'];
     if (['INPUT','TEXTAREA'].includes(document.activeElement.tagName)) return;
  var div = document.createElement('div');
    typed += e.key; if (typed.length > 4) typed = typed.slice(-4);
  div.style.cssText = 'text-align:center;padding:8px;border:1px solid #a2a9b1;border-radius:6px;margin:8px 0;background:#f8f9fa;';
    if (typed.toLowerCase() !== 'nyan') return;
  div.innerHTML = '<b>🎱 Magic 8-Ball</b><br><small>Think of a question...</small><br>' +
    typed = '';
    '<button id="mw-8ball" style="margin-top:6px;cursor:pointer;padding:4px 10px;">Ask!</button>' +
    var nyan = document.createElement('div');
    '<p id="mw-8ball-ans" style="font-style:italic;min-height:20px;margin:6px 0 0;"></p>';
    nyan.textContent = '🌈🐱';
  var tb = document.querySelector('#p-tb .body, #p-tb ul');
    nyan.style.cssText = 'position:fixed;top:' + (20 + Math.random()*60) + 'vh;left:-100px;font-size:2em;' +
  if (tb) tb.parentElement.insertBefore(div, tb.nextSibling);
      'z-index:9999;pointer-events:none;transition:left 2s linear;';
  document.getElementById('mw-8ball').addEventListener('click', function() {
    document.body.appendChild(nyan);
     document.getElementById('mw-8ball-ans').textContent = answers[Math.floor(Math.random() * answers.length)];
    setTimeout(function() { nyan.style.left = '110vw'; }, 50);
     setTimeout(function() { nyan.remove(); }, 2200);
   });
   });
})();
})();