netacad script

skript na vyplnovani netacad linux testu

Από την 28/04/2020. Δείτε την τελευταία έκδοση.

  1. // ==UserScript==
  2. // @name netacad script
  3. // @namespace http://lkov.tk/
  4. // @version 1.1
  5. // @description skript na vyplnovani netacad linux testu
  6. // @author @sirluky
  7. // @include https://content.netdevgroup.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Your code here...
  15. function r(){
  16.  
  17. fetch(`https://api.jsonbin.io/b/5ca52dba34241f2ab5e1ba79`).then(e => e.json()).then(unparseddata => {
  18. const parsedData = unparseddata;
  19. //parsedData.push(prompt("zadejte ziskany kod"))
  20. /**
  21. * @param {*} n question number
  22. * return string with answer
  23. */
  24.  
  25. function start(){
  26. document.querySelectorAll("#tour2 > .ndg-menu-btn").forEach( async function (e) {await setTimeout(()=>{},1000);e.click();})
  27. let phase = 0;
  28. runForAll()
  29. function runForAll(){
  30. setTimeout(e => {
  31. let question = getQuestion(phase)
  32. let answers = findAnswer(question, parsedData);
  33. answers.forEach(answer => {
  34. checkAnswer(phase, answer)
  35. })
  36. if (question) {
  37. phase++;
  38. setTimeout(e => {
  39. runForAll()
  40. }, 300);
  41. }
  42. }, 300)
  43. }
  44.  
  45. }
  46. function getQuestion(n) {
  47. return document.querySelectorAll(".panel-body")[n].querySelector("div").innerText
  48. }
  49. function checkAnswer(n,text){
  50. let list = []
  51. document.querySelectorAll(".panel-body")[n].querySelectorAll(".answer_container div").forEach((e,index) => list.push([e.innerText,index]))
  52. list = list.filter(e => e[0] === text);
  53. // list = list.length > 0 ? true :false;
  54. console.log(list)
  55. if(list.length > 0){
  56. console.log(list[0][1])
  57. document.querySelectorAll(".panel-body")[n].querySelectorAll(".answer_container div")[list[0][1]].parentElement.parentElement.childNodes[1].checked = true
  58. } else {
  59. document.querySelectorAll(".panel-body")[n].style.background = "mistyrose"
  60. }
  61. return list;
  62. }
  63.  
  64. //question to select
  65. function findAnswer(toFind, myData) {
  66. let ans = myData.filter(e => e.question === toFind.slice(0, e.question.length));
  67. if(ans.length > 0){
  68. return ans[0].answers;
  69. } else{
  70. return []
  71. }
  72. }
  73. start()
  74. // document.querySelectorAll(".panel-body")[n].querySelector("answer_container div")
  75.  
  76. /*
  77.  
  78. parsing from https://www.ccna7.com/linux-essentials/linux-essentials-chapter-2-exam/
  79. */
  80.  
  81.  
  82.  
  83. //quesetion
  84. // document.querySelectorAll("ol>li")[0 /* question number */ ].querySelectorAll("h3")[1].innerText
  85. //answers
  86. // document.querySelectorAll("ol>li")[0 /* question number */ ].querySelectorAll("span")[0].innerText
  87. })
  88. } r()
  89. })();