MediaWiki:Gadget-FarleyWisdom/Runtime.js

mw.loader.using(['oojs-ui-core', 'oojs-ui-windows']).done(function {   function activateFarley {        const WISE_WORDS = [            "Time spent among trees is never time wasted.",            "It is good people who make good places.",            "The most important places on a map are the places we haven't been yet."        ];        let farleyCaught = false;

function hideFarley { if (!farleyCaught) { const el = document.getElementById('nookipedia-farley'); var tick = function { el.style.opacity = +el.style.opacity - 0.05; if (+el.style.opacity > 0) { (window.requestAnimationFrame && requestAnimationFrame(tick)) || setTimeout(tick, 16) } else { el.style.cursor = 'default'; el.removeEventListener("click", farleyClicked); setTimeout(function {                           showFarley;                        }, 2000); }               };                tick; }       }

function showFarley { if (!farleyCaught) { const el = document.getElementById('nookipedia-farley'); el.addEventListener("click", farleyClicked); el.style.cursor = 'pointer'; el.style.opacity = 0; el.style.left = Math.floor(Math.random * (75 - 25) + 25) + '%'; var tick = function { el.style.opacity = +el.style.opacity + 0.01; if (+el.style.opacity < 1) { (window.requestAnimationFrame && requestAnimationFrame(tick)) || setTimeout(tick, 16) } else { setTimeout(function {                           hideFarley;                        }, 500); }               };                tick; }       }

function farleyClicked { farleyCaught = true; localStorage.setItem("nookipedia-farley-caught", "true"); const el = document.getElementById('nookipedia-farley'); el.style.display = 'none'; OO.ui.alert('You found Farley the Well Spirit! He has some wise words to share: "' + WISE_WORDS[Math.floor(Math.random * WISE_WORDS.length)] + '"').done(function {}); }

setTimeout(function {           const farley = document.createElement('img');            farley.id = 'nookipedia-farley';            farley.src = 'https://dodo.ac/np/images/thumb/a/a8/Farley_e-Reader.png/198px-Farley_e-Reader.png';            farley.width = '50';            farley.style.position = 'fixed';            farley.style.bottom = '-16px';            farley.style.zIndex = '500';            farley.style.left = Math.floor(Math.random * (75 - 25) + 25) + '%';            farley.style.opacity = 0;            farley.style.cursor = 'pointer';            document.getElementsByTagName('body')[0].appendChild(farley);            showFarley;        }, 1000); }

if (!localStorage.getItem("nookipedia-farley-caught")) { activateFarley; } });