diff --git a/Modern Development/Service Portal Widgets/Konami Code Easter Egg/KonamiCodeEasterEggV2.js b/Modern Development/Service Portal Widgets/Konami Code Easter Egg/KonamiCodeEasterEggV2.js new file mode 100644 index 0000000000..423bc492d6 --- /dev/null +++ b/Modern Development/Service Portal Widgets/Konami Code Easter Egg/KonamiCodeEasterEggV2.js @@ -0,0 +1,50 @@ +function(spModal) { + var c = this; + console.log('Lol what are you doing here?'); + + const KONAMI_CODE = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', + 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a']; + let inputSequence = []; + let timeoutId; + + const handleKeyPress = (e) => { + // Clear timeout to reset sequence if user pauses too long + clearTimeout(timeoutId); + + // Add key to sequence + inputSequence.push(e.key); + + // Keep only the last N keys (length of Konami code) + if (inputSequence.length > KONAMI_CODE.length) { + inputSequence.shift(); + } + + // Check if current sequence matches Konami code + if (inputSequence.join(',') === KONAMI_CODE.join(',')) { + activateCheats(); + inputSequence = []; // Reset after activation + } + + // Reset sequence after 2 seconds of inactivity + timeoutId = setTimeout(() => { + inputSequence = []; + }, 2000); + }; + + const activateCheats = () => { + spModal.open({ + size: 'sm', + title: 'Cheats activated', + message: 'Konami code entered', + buttons: [{ label: '${Close}', cancel: true }] + }); + }; + + document.addEventListener('keydown', handleKeyPress); + + // Cleanup listener when widget is destroyed + c.$onDestroy = function() { + document.removeEventListener('keydown', handleKeyPress); + clearTimeout(timeoutId); + }; +} diff --git a/Modern Development/Service Portal Widgets/Konami Code Easter Egg/README.md b/Modern Development/Service Portal Widgets/Konami Code Easter Egg/README.md index 244cde1c18..b7be3f1f38 100644 --- a/Modern Development/Service Portal Widgets/Konami Code Easter Egg/README.md +++ b/Modern Development/Service Portal Widgets/Konami Code Easter Egg/README.md @@ -1,3 +1,16 @@ # Konami Code Easter Egg Put this code in the client controller of a widget to listen for the Konami Code. By default it just opens a modal notifying the user that the konami code as activated. Modify to do whatever fun things you want. + +## Version 2 + +[KonamiCodeEasterEggV2.js]("Modern Development\Service Portal Widgets\Konami Code Easter Egg\KonamiCodeEasterEggV2.js") is the same code but improved with: + +1. Uses e.key instead of e.keyCode (which is deprecated) with modern arrow key names +2. Automatically tracks only the last N keypresses instead of manual position tracking +3. Resets the sequence if the user pauses too long (more forgiving UX) +4. Removes event listener when widget is destroyed to prevent memory leaks +5. Uses array join comparison instead of position tracking +6. Modern variable declarations for better scoping + +image