Quizlet - Hotkeys to Search Flash Cards by Accuracy

Press the 1-2-3-4 number keys to navigate large decks easily

  1. // ==UserScript==
  2. // @name Quizlet - Hotkeys to Search Flash Cards by Accuracy
  3. // @namespace QZLT_flashcardSelectKBMode
  4. // @description Press the 1-2-3-4 number keys to navigate large decks easily
  5. // @author Kai Krause <kaikrause95@gmail.com>
  6. // @match http://*.quizlet.com/*
  7. // @match https://*.quizlet.com/*
  8. // @version 1.6
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. if (!location.pathname.endsWith("-flash-cards/")) return
  13.  
  14. // Helper function to inject JS code into the page, for page-level access to JS functions and variables
  15. var injectCode = function(f) {
  16. var script = document.createElement("script");
  17. script.textContent = "(" + f.toString() + "());";
  18. document.head.appendChild(script);
  19. };
  20.  
  21. var theCode = function(){
  22. var titlesCache = [];
  23.  
  24. function titleSelect(charE) {
  25. if (!titlesCache || titlesCache.length === 0) {
  26. var titles = document.getElementsByClassName("SetPageTermChunk-title");
  27. for (var i = 0; i < titles.length; i++){
  28. titles[i].innerHTML += "<a style='visibility:hidden' name='" + titles[i].textContent + "'></a>";
  29. titlesCache.push(titles[i].textContent);
  30. }
  31. }
  32.  
  33. var el = document.activeElement;
  34. if (el.tagName.toLowerCase() != 'textarea') {
  35. if (charE.keyCode == "49") {
  36. window.location.hash = titlesCache[0];
  37. } else if (charE.keyCode == "50") {
  38. window.location.hash = titlesCache[1];
  39. } else if (charE.keyCode == "51") {
  40. window.location.hash = titlesCache[2];
  41. } else if (charE.keyCode == "52") {
  42. window.location.hash = titlesCache[3];
  43. }
  44. }
  45. }
  46. window.addEventListener("keydown", titleSelect, true);
  47. }
  48.  
  49. injectCode(theCode);