· 6 years ago · Dec 24, 2019, 05:40 PM
1// ==UserScript==
2// @name New Userscript
3// @namespace http://tampermonkey.net/
4// @version 0.1
5// @description try to take over the world!
6// @author You
7// @match http://certifications.ru/tests/new/id/18/
8// @grant none
9// ==/UserScript==
10function sleep (time) {
11 return new Promise((resolve) => setTimeout(resolve, time));
12}
13sleep(300).then(f)
14function f(){
15var ip_id;
16var key;
17let = isStarted = false;
18if(isStarted == false) {
19
20 isStarted = true;
21 tn_id = $("#testId").attr("value");
22 soap_key = $("#soapKey").attr("value") || 'undefined';
23
24 if (typeof timer != 'undefined') {
25 window.clearInterval(timer);
26 }
27
28 $.ajax({
29 url: '/tests/get-current-question/tn_id/' + tn_id + '/soapkey/' + soap_key,
30 dataType : "json",
31 success: function (data, textStatus) {
32
33 ip_id = data['ip_id'];
34 key = data['secret_key'];
35 html = data['body'];
36 $("#DOMWindow").find(".d-content").html(html);
37
38 doTimerPosition();
39 }
40 });
41 }
42
43sleep(500).then(() => {
44 for(let i = 0; i < 40; i ++){//process started
45 inprocess = true;
46
47 //clear interval
48 if (typeof timer != 'undefined') {
49 window.clearInterval(timer);
50 }
51
52 answers = Math.floor( Math.random() * (5) ) + 1;
53 breaked = $('input[name=breaked]').is(':checked');
54 comment = $('.betacomment').val();
55
56 if (answers === undefined) {
57
58 array = [];
59 $('input:checkbox[name="answers[]"]:checked').each(function(index) {
60 array.push($(this).val());
61 });
62 answers = array.sort(function(a, b){return a-b;}).toString();
63 }
64
65 var resendTimer = window.setInterval(function () {
66 xhr.abort();
67 inprocess = false;
68 window.clearInterval(resendTimer);
69 $(".send-answer").trigger('click');
70 }, 8000);
71
72 var xhr = $.ajax({
73 type: "POST",
74 url: "/tests/get-current-question/ip_id/" + ip_id + "/secret_key/" + key,
75 data: "answers=" + answers + '&breaked=' + breaked + '&comment=' + comment,
76 dataType : "json",
77 success: function(data){
78 html = data['body'];
79 $("#DOMWindow").find(".d-content").html(html);
80 inprocess = false;
81 window.clearInterval(resendTimer);
82 $('#DOMWindow').scrollTop(0);
83 }
84 });}
85sleep(1000).then(() => {
86 if(document.getElementsByClassName("success")[0] != undefined){
87 document.location.reload(true);
88 f()
89 }
90 else{
91 try{
92 if(Number.parseFloat(document.getElementsByClassName("success")[0].style.width) < 350)
93 {
94 document.location.reload(true);
95 f()
96 }}
97 catch(er){ document.location.reload(true);}
98}})
99});}