Kikora hax

Attempts to record tasks submitted to kikora and delivers the correct results to everyone else

  1. // ==UserScript==
  2. // @name Kikora hax
  3. // @namespace Danielv123
  4. // @version 1.1.1
  5. // @description Attempts to record tasks submitted to kikora and delivers the correct results to everyone else
  6. // @author You
  7. // @match *.kikora.no/*
  8. // @require http://code.jquery.com/jquery-3.1.0.js
  9. // @grant GM_xmlhttpRequest
  10. // ==/UserScript==
  11.  
  12. var haxServer = "http://81.167.2.56:8090";
  13. // expected name in JSON fields is something like C21803|C22001|C22022|188431
  14. // it is grabbed from the URL up top, but URL parsing is unreliable so this may break for some.
  15.  
  16. // Datamine for the correct answer and send it to a server for future abuse
  17. function getCorrectAnswer() {
  18. let url = document.location.href.replace("HWA|", "").replace("|", "/").replace("|", "/").split(/[/:]+/);
  19. let x = false;
  20. let name = "";
  21. try{
  22. x = document.querySelector(".answer-trophy").childNodes[1].childNodes[0].dataset.title;
  23. name = url[7]+"|"+url[8]+"|"+url[9]+"|"+url[10];
  24. } catch (e){}
  25. if(x){
  26. console.log("Found answer! " + x);
  27. GM_xmlhttpRequest({
  28. method: "POST",
  29. url: haxServer + "/api/place",
  30. data: JSON.stringify({name: name, answer: x}),
  31. headers: {
  32. "Content-Type": "application/json"
  33. },
  34. onload: function(data) {
  35. if(data /*&& typeof data == "string"*/){
  36. console.log("Sent answer! " + x);
  37. }
  38. }
  39. });
  40. }
  41. }
  42. setInterval(getCorrectAnswer,1000);
  43. function outputSolution(string){
  44. document.querySelector("#userscript").innerHTML = string;
  45. }
  46. // try checking the last hint (which doesn't show up as a hint since its the answer)
  47. url = document.location.href.replace("HWA|", "").replace("|", "/").replace("|", "/").split(/[/:]+/);
  48. console.log(url);
  49. console.log("Book: " + url[7] + " Theme: " + url[8] + " Chapter: " + url[9] + " Task: " + url[10]);
  50.  
  51. // Using this function is not recommended so I disabled it below by commenting it out. Turns out it places a lot of strain on kikoras servers so they called me and asked me to turn it off :P
  52. // I am still going to leave it in as it works nicely if called with a number liker 15 or 30
  53. function wasddas(number) {
  54. number = number - 1;
  55. (function(number){
  56. url = document.location.href.replace("HWA|", "").replace("|", "/").replace("|", "/").split(/[/:]+/);
  57. $.ajax({
  58. type: "POST",
  59. url: "/k/json",
  60. data: 'request={"solution":{"containerid":"'+url[9]+'","exerciseid":'+url[10]+',"timeusedforevent":'+666+',"calculationid":0,"solutionid":' + number + ',"newcalculation":false,"lcode":"nb"}}',
  61. dataType: "json",
  62. success: function(data) {
  63. if(data[0].solution){
  64. console.log(number);
  65. console.log("Hint found!");
  66. console.log(JSON.parse(data[0].solution.esl.replace("[[km:","").replace("]]","")).text);
  67. outputSolution(JSON.parse(data[0].solution.esl.replace("[[km:","").replace("]]","")).text);
  68. } else {
  69. console.log("Not found :'(");
  70. if (number>-10){
  71. wasddas(number);
  72. }
  73. }
  74. },
  75. error: function() {
  76. // alert('error handing here');
  77. }
  78. });
  79. })(number);
  80. }
  81. $('body').append("<div id='userscript' style='position:fixed;background-color:white;z-index:100000000;bottom:0px;right:0px;height:50px;width:150px;'></div>");
  82. // start it up
  83. setInterval(function(){
  84. //wasddas(30);
  85. let url = document.location.href.replace("HWA|", "").replace("|", "/").replace("|", "/").split(/[/:]+/);
  86. data = {
  87. name: url[7]+"|"+url[8]+"|"+url[9]+"|"+url[10],
  88. };
  89. GM_xmlhttpRequest({
  90. method: "POST",
  91. url: haxServer + "/api/get",
  92. data: JSON.stringify(data),
  93. headers: {
  94. "Content-Type": "application/json"
  95. },
  96. onload: function(data) {
  97. //console.log("Got answer from server! " + JSON.stringify(data));
  98. if(data && typeof data == "object"){
  99. //console.log("Got answer from server! " + data.responseText);
  100. outputSolution(data.responseText);
  101. }
  102. }
  103. });
  104. console.log("Asking for answer to " + JSON.stringify(data));
  105. }, 5000);