added keyboard shortcut for killing sounds via ajax

This commit is contained in:
Erhard 2017-08-03 21:08:38 +02:00
parent d4377e0f49
commit 90c0887f97
2 changed files with 12 additions and 5 deletions

View File

@ -61,6 +61,8 @@ ready(function() {
evt = evt || window.event; evt = evt || window.event;
if (evt.keyCode == 27) { if (evt.keyCode == 27) {
resetSearch(); resetSearch();
} else if (evt.keyCode == 75 && evt.ctrlKey) {
ajaxRequest("/?killvideo=yes");
} }
}; };
@ -70,8 +72,13 @@ ready(function() {
all_a_s[i].addEventListener('keypress', async function (e) { all_a_s[i].addEventListener('keypress', async function (e) {
var key = e.keyCode; var key = e.keyCode;
var source = e.target; var source = e.target;
if (key === 13) { // keylistener for enter or ctrl+enter (which is k10 on chrome)
source.classList.add("sound-pressed") if (key === 13 || (key === 10 && e.ctrlKey)) {
if(e.ctrlKey){
ajaxRequest("/?killvideo=yes");
await sleep(100);
}
source.classList.add("sound-pressed");
source.onclick(); source.onclick();
await sleep(300); await sleep(300);
source.classList.remove("sound-pressed"); source.classList.remove("sound-pressed");
@ -105,11 +112,10 @@ function hideSections() {
}); });
} }
function ajaxRequest(filename){ function ajaxRequest(url){
var ajaxRequest; var ajaxRequest;
try{ try{
ajaxRequest = new XMLHttpRequest(); ajaxRequest = new XMLHttpRequest();
var url = "play/" + filename;
ajaxRequest.open("GET", url, true); ajaxRequest.open("GET", url, true);
ajaxRequest.send(null); ajaxRequest.send(null);
}catch (e){ }catch (e){

View File

@ -38,7 +38,7 @@
<section id="sounds"> <section id="sounds">
<div><input type="text" id="search" autofocus/><span id="reset"></span></div> <div><input type="text" id="search" autofocus/><span id="reset"></span></div>
{% for sound in sounds %} {% for sound in sounds %}
<div class="sound"><a tabindex="0" class="unselectable" onclick="ajaxRequest('{{ sound | urlencode }}');">{{ sound.split('.', 1)[0] }}</a></div> <div class="sound"><a tabindex="0" class="unselectable" onclick="ajaxRequest('{{ '/play/' + sound | urlencode }}');">{{ sound.split('.', 1)[0] }}</a></div>
{% endfor %} {% endfor %}
</section> </section>
<section id="youtube"> <section id="youtube">
@ -67,3 +67,4 @@
<script src="/static/main.js"></script> <script src="/static/main.js"></script>
</body> </body>
</html> </html>