PKaBoot

A configurable script that maps keyboard keys (1, 2, 3, 4 and Space by default) to the answer buttons on Kahoot

  1.  
  2. // ==UserScript==
  3. // @name PKaBoot
  4. // @namespace https://tampermonkey.net
  5. // @version 0.15
  6. // @description A configurable script that maps keyboard keys (1, 2, 3, 4 and Space by default) to the answer buttons on Kahoot
  7. // @author AshKmo
  8. // @match https://kahoot.it/*
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function(){
  15. var keybinds = GM_getValue('keys');
  16.  
  17. if (keybinds == null) {
  18. keybinds = ['1', '2', '3', '4', 'Space'];
  19. }
  20.  
  21. var tkb = keybinds.map(e => e.toUpperCase());
  22.  
  23. var menuEl = document.createElement('div');
  24.  
  25. menuEl.innerHTML = '<style>.pkbInKeys {display:inline-block;width:44px !important;color:white;}</style><p style="margin:0;">PKaBoot keys:&nbsp<input type="text" class="pkbInKeys" style="background-color:rgb(208, 25, 55);"><input type="text" class="pkbInKeys" style="background-color:rgb(18, 96, 190);"><input type="text" class="pkbInKeys" style="background-color:rgb(199, 146, 0);"><input type="text" class="pkbInKeys" style="background-color:rgb(35, 126, 11);"><input type="text" class="pkbInKeys" style="background-color:black;"><button id="pkbSubmit" style="width: auto !important;">Apply</button></p>';
  26.  
  27. menuEl.setAttribute('style', 'position:absolute;z-index:5;top:0px;left:15%;background-color:white;');
  28.  
  29. var pkbInKeys = menuEl.querySelectorAll('.pkbInKeys');
  30.  
  31. pkbInKeys.forEach((k,i) => (k.value = keybinds[i]));
  32.  
  33. menuEl.querySelector('#pkbSubmit').onclick = () => {
  34. pkbInKeys.forEach((k,i) => (keybinds[i] = k.value));
  35.  
  36. tkb = keybinds.map(e => e.toUpperCase());
  37.  
  38. GM_setValue('keys', keybinds);
  39. };
  40.  
  41. document.body.appendChild(menuEl);
  42.  
  43. keybinds.map(k => k.toUpperCase());
  44.  
  45. document.addEventListener('keydown', e => {
  46. var index = tkb.indexOf(e.key.toUpperCase());
  47.  
  48. index = index == -1 ? tkb.indexOf(e.code.toUpperCase()) : index;
  49.  
  50. try {
  51. document.querySelector(`[data-functional-selector="${index == 4 ? 'multi-select-submit-button' : 'answer-' + index}"]`).click();
  52. } catch {}
  53. });
  54. })();
  55.