From cc7ebd2d8a67c57983af31495d14236845f3602d Mon Sep 17 00:00:00 2001 From: Alexandre Iooss <erdnaxe@crans.org> Date: Thu, 3 Sep 2020 00:35:25 +0200 Subject: [PATCH] Sometimes the nk20 is too laggy --- note_kfet/static/js/konami.js | 38 +++++++++++++++++++++++++++++++++++ note_kfet/templates/base.html | 1 + 2 files changed, 39 insertions(+) create mode 100644 note_kfet/static/js/konami.js diff --git a/note_kfet/static/js/konami.js b/note_kfet/static/js/konami.js new file mode 100644 index 00000000..e9f6c17d --- /dev/null +++ b/note_kfet/static/js/konami.js @@ -0,0 +1,38 @@ +/* + * Konami code support + */ + +// Cursor denote the position in konami code +let cursor = 0 +const KONAMI_CODE = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65] + +function afterKonami() { + // Load Rythm.js + var rythmScript = document.createElement('script') + rythmScript.setAttribute('src','https://unpkg.com/rythm.js@2.2.5/rythm.min.js') + document.head.appendChild(rythmScript) + + rythmScript.addEventListener('load', function() { + // This media source need to be accessible with a cross-origin header + const audioElement = new Audio('https://okazari.github.io/Rythm.js/samples/rythmC.mp3') + audioElement.crossOrigin = 'anonymous' + audioElement.play(); + + const rythm = new Rythm() + rythm.connectExternalAudioElement(audioElement) + rythm.addRythm('card', 'pulse', 0, 10) + rythm.addRythm('nav-link', 'color', 0, 10, { + from: [0,0,255], + to:[255,0,255] + }) + rythm.start() + }); +} + +// Register custom event +document.addEventListener('keydown', (e) => { + cursor = (e.keyCode == KONAMI_CODE[cursor]) ? cursor + 1 : 0; + if (cursor == KONAMI_CODE.length) { + afterKonami() + } +}); diff --git a/note_kfet/templates/base.html b/note_kfet/templates/base.html index 3381c78e..fcee608a 100644 --- a/note_kfet/templates/base.html +++ b/note_kfet/templates/base.html @@ -35,6 +35,7 @@ SPDX-License-Identifier: GPL-3.0-or-later <script src="https://cdnjs.cloudflare.com/ajax/libs/turbolinks/5.2.0/turbolinks.js" crossorigin="anonymous"></script> <script src="{% static "js/base.js" %}"></script> + <script src="{% static "js/konami.js" %}"></script> {# Si un formulaire requiert des données supplémentaires (notamment JS), les données sont chargées #} {% if form.media %} -- GitLab