Updated Quizlet Micromatch bot

Win micromatch in less than a second! This is based off of the original script by Danielv123, but basically all of the code has been replaced by my own

目前为 2019-09-21 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Updated Quizlet Micromatch bot
  3. // @namespace BenjaminHinchliff
  4. // @version 0.2
  5. // @description Win micromatch in less than a second! This is based off of the original script by Danielv123, but basically all of the code has been replaced by my own
  6. // @author You
  7. // @match https://quizlet.com/*/match*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. // a little function to allow the program to click on elements
  12. function clickEvent(element) {
  13. let eve = new CustomEvent("pointerdown", { bubbles: true });
  14. element.dispatchEvent(eve);
  15. }
  16.  
  17. let rawTerms = Quizlet.matchModeData.terms;
  18. let terms = {};
  19. // get terms from Quizlet object (a global variable because I only want to retrive it once)
  20. for (let i = 0; i < rawTerms.length; i++) {
  21. terms[rawTerms[i].word] = rawTerms[i].definition;
  22. }
  23.  
  24. // wait until user presses start
  25. document.onclick = ()=>{
  26. // get all the nodes and store them in a variable to avoid re-querying nodes (I know it's live shut up)
  27. let nodes = document.querySelector(".MatchModeQuestionGridBoard-tiles").childNodes;
  28. for (let i = 0; i < nodes.length; i++) {
  29. // get term
  30. let search = nodes[i].childNodes[0].childNodes[0].childNodes[0].childNodes[0].innerHTML;
  31. // match with definition
  32. let dictionaryResult = terms[search];
  33. if(dictionaryResult) {
  34. // find term in nodes and send click events
  35. for (let j = 0; j < nodes.length; j++) {
  36. if (nodes[j].innerHTML.includes(dictionaryResult)) {
  37. setTimeout(() => {
  38. clickEvent(nodes[i].childNodes[0]);
  39. clickEvent(nodes[j].childNodes[0]);
  40. },
  41. i * 50); // this is only here because quizlet doesn't allow score below 0.5 seconds and this roughly comes out to 0.5
  42. }
  43. }
  44. }
  45. }
  46. };