MediaWiki:Gadget-FarleyWisdom/Runtime.js

mw.loader.using(['oojs-ui-core', 'oojs-ui-windows']).done(function {	// Instantiate message dialog	// From https://www.mediawiki.org/wiki/OOUI/Windows/Message_Dialogs	var messageDialog = new OO.ui.MessageDialog;	var windowManager = new OO.ui.WindowManager;	$('body').append( windowManager.$element );	windowManager.addWindows( [ messageDialog ] );

const WISE_WORDS = [ "A kind heart is a fountain of gladness, making everything in its vicinity freshen into smiles.", "A little axe can cut down a big tree.", "A mind that is stretched by a new experience can never go back to its old dimensions.", "A seed hidden in the heart of an apple is an orchard invisible.", "Do the best you can. No one can do more than that.", "Fear leads to anger. Anger leads to hate. Hate leads to lack of a golden axe.", "Flip a coin. When it's in the air, you'll know which side you're hoping for.", "For in the true nature of things, if we rightly consider, every green tree is far more glorious than if it were made of gold and silver.", "Good things come to gnomes who wait.", "Inanimate objects sometimes appear endowed with a strange power of sight. A statue notices, a tower watches, the face of an edifice contemplates.", "It is good people who make good places.", "Nearly or Farley, wherever you arely.", "No amount of Bells can buy you a golden axe, but what you use them for can.", "Some say that I'm shrouded in mystery, but I would say that I'm shrouded in hair!", "The most important places on a map are the places we haven't been yet.", "The true meaning of life is to plant trees, under whose shade you do not expect to sit.", "Time spent among trees is never time wasted.", "Wishing well? What is that?", "Worry never robs tomorrow of its sorrow; it only saps today of its strength.", "There are no accidents...only a golden axe.", "It's a good feeling to know where to get your golden axe.", "Love yourself. You're better than what you think.", "The sharing of golden axes has become all too common in the Animal Crossing world. More alarmingly, some people have traded golden axes for cheap goods that devalue the golden axes that I give, and this is extremely dangerous in my woods.", "You'll know if you are a luck if you see a certain robot villager celebrating their birthday." ];   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;                    }, 250); }           };            tick; }   }

function farleyClicked { farleyCaught = true; const el = document.getElementById('nookipedia-farley'); el.style.display = 'none'; if (!localStorage.getItem("nookipedia-farley-caught")) { windowManager.openWindow(messageDialog, {			   title: 'You found Farley the Well Spirit!',			    message: 'He has wise words to share: "' + WISE_WORDS[Math.floor(Math.random * WISE_WORDS.length)] + '" Now that you\'ve caught him, maybe he\'ll stick around.',			    actions: [				    {				        action: 'accept',				        label: 'Thanks, Farley',				        flags: 'primary'				    }				]			}); } else { windowManager.openWindow(messageDialog, {			   title: 'Farley has more wisdom to share...',			    message: '"' + WISE_WORDS[Math.floor(Math.random * WISE_WORDS.length)] + '"',			    actions: [				    {				        action: 'accept',				        label: 'Thanks, Farley',				        flags: 'primary'				    }				]			}); }       localStorage.setItem("nookipedia-farley-caught", "true"); }

if (!localStorage.getItem("nookipedia-farley-caught")) { // If Farley hasn't been caught, activate the mysterious moving Farley 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 = '-10px';            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); } else { console.log('hmm'); // If Farley has been caught, show him static at the bottom corner 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 = '5px'; farley.style.left = '5px'; farley.style.zIndex = '500'; farley.style.cursor = 'pointer'; document.getElementsByTagName('body')[0].appendChild(farley); farley.addEventListener("click", farleyClicked); } });