LearningApps Show Crossword Answers

Add "Show answers" button to LearningApps crossword

  1. // ==UserScript==
  2. // @name LearningApps Show Crossword Answers
  3. // @version 0.1
  4. // @description Add "Show answers" button to LearningApps crossword
  5. // @author stennen
  6. // @match *://learningapps.org/display?v=*
  7. // @grant none
  8. // @namespace http://tampermonkey.net/
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=learningapps.org
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. setTimeout(() => {
  15. function handler2() {
  16.  
  17. let appcnt = document.body.getElementsByTagName("iframe")[0].contentWindow.document.getElementsByTagName("iframe")[0].contentWindow;
  18.  
  19. if (!appcnt.eval('AppClient')) {
  20. return;
  21. }
  22.  
  23. if (!appcnt.document.body.innerHTML.includes('<script type="text/javascript" src="crossword.js"></script>')) {
  24. return;
  25. }
  26.  
  27. let dc = document.getElementById("content_container");
  28. let cntr = document.createElement("center");
  29. let el = document.createElement("button");
  30. el.setAttribute("id", "showAnswersBtn");
  31. el.innerText='Show Answers';
  32. el.style.fontFamily='Arial';
  33. el.style.fontSize='30px';
  34. el.style.textAlign='center';
  35. cntr.appendChild(el);
  36. dc.appendChild(cntr);
  37. el = document.getElementById("showAnswersBtn");
  38. el.onclick = () => {
  39. let appClient = document.body.getElementsByTagName("iframe")[0].contentWindow.document.getElementsByTagName("iframe")[0].contentWindow.eval('AppClient');
  40.  
  41. let answers='';
  42. for (let i=0;i<50;i++) {
  43. let answr = appClient.getParameter("word" + i);
  44. if (answr) {
  45. answers+='<h3>Word ' + i + ': ' + answr + '</h3>';
  46. }
  47. }
  48.  
  49. let wnd = window.open("about:blank");
  50. wnd.document.body.innerHTML = '<style>h1,h2,h3,h4,h5,h6{font-family:Arial}</style><center><h1>Answers</h1><hr>' + answers + '<hr><p>made by stennen</p></center>'
  51. };
  52. }
  53.  
  54. if (document.getElementById("showAnswersBtn")) {
  55. return;
  56. }
  57.  
  58. if (!document.body.getElementsByTagName("iframe")) {
  59. return;
  60. }
  61.  
  62.  
  63. if (!document.body.getElementsByTagName("iframe")[0].contentWindow.document.getElementsByTagName("iframe")) {
  64. return;
  65. }
  66.  
  67. handler2();
  68.  
  69. }, 1500);
  70.  
  71. /* made by Stennen */
  72. })();