TimFuckOffline / CBT REQ & Setor KJ

// ==UserScript==
// @name        CBT REQ & Setor KJ
// @description Buat minta kj
// @match       file:///C:/Users/AGUS%20SUBEKTI/Desktop/programming/web%20samples/sesudah/*/content.htm
// @match       http://sman8jkt.xyz/cbt/*
// @match       http://sample.fuckcbt.xyz/*
// @match       *://203.77.237.108/cbt/*
// @match       *://203.77.237.107/cbt/*
// @match       *://203.77.237.110/cbt/*
// @grant       GM_xmlhttpRequest
// @version     1.7.1
// @downloadURL https://openuserjs.org/install/TimFuckOffline/CBT_REQ_Setor_KJ.user.js
// @updateURL   https://openuserjs.org/meta/TimFuckOffline/CBT_REQ_Setor_KJ.meta.js
// @author      mastermind
// @require     http://code.jquery.com/jquery-latest.js
// @license     MIT
// @author      TimFuckOffline
// @copyright   2022, TimFuckOffline (https://openuserjs.org/users/TimFuckOffline)
// ==/UserScript==

// Constants(nanti diisi pas instalasi)
var NAME = "anjing";
const placeholder = "© Copyright 2020, SMAN 8 Jakarta, All Rights Reserved";
var E = $(":contains('Copyright 2020, SMAN 8 Jakarta, All Rights Reserved')")[6];
var txt = "";

// Text builder

function buildText(item, index) {
  txt = txt + item.sumber + "=" + item.jawaban + " ";
}

// Scrape in page

function cariKJ() {
  var kj = $('input[name=rdoPil][checked]')
  for(x in kj) {
    var pil = kj[0].attributes[2].textContent;
    pil = pil.split("pil=").pop();
    pil = pil.slice(0,1);
  }
  
  var pil = kj[0].attributes[2].textContent
  pil = pil.split("pil=").pop()
  pil = pil.slice(0,1);
  return(pil)
}

function cariImg() {
  var imgWalt = $("img");
  var c = imgWalt[0].currentSrc;
  return c
};

// finding NIS
function cariNIS() {
  var NIS = $(":contains(26)");
  var a = NIS[Object.keys(NIS)[26]];
  return a.textContent;
};

//finding kode soal

function cariKode() {
  var KODE = $(":contains(000)");
  var b = KODE[Object.keys(KODE)[27]];
  return b.textContent;
};

// Finding table object containing target text

function cariText(text) {
  E.innerHTML = text
  setTimeout(function () {
    E.innerHTML = placeholder
  }, 1945);
  txt = ""
}

// Re-enable context menu (right click)

$('script[type="text/javascript"][language="JavaScript"]').remove();
window.addEventListener("contextmenu", 
  function(e){
     e.stopPropagation()
}, true);

// Listening keybind for next and previous

let keysPressed = {};

var result = {};

document.addEventListener('keydown', (event) => {
  keysPressed[event.key] = true;
  
  if (keysPressed['n'] && event.key == 'm') {
    keysPressed[event.key] = false;
    console.log("N+M pressed")
    GM_xmlhttpRequest({
      method: 'POST',
      url: "https://www.fuckcbt.xyz/api/send",
      data: "kodesoal="+cariKode()+"&gambar="+cariImg()+"&jawaban="+cariKJ()+"&sumber="+NAME,
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      onload: function(response) {
        cariText(JSON.parse(response.responseText).result)
      }
    })
  }
  else if (keysPressed['m'] && event.key == 'n') {
    console.log("M+N pressed")
    GM_xmlhttpRequest({
      method: 'POST',
      url: "https://www.fuckcbt.xyz/api/send",
      data: "kodesoal="+cariKode()+"&gambar="+cariImg()+"&jawaban="+cariKJ()+"&sumber="+NAME,
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      onload: function(response) {
        console.log(response)
        cariText(JSON.parse(response.responseText).result); // GANTI ALERT JADI TULISAN DI BAWAH
      }
    })  
  }
  else if (keysPressed['z'] && event.key == 'x') {
    console.log("Z+X pressed")
    GM_xmlhttpRequest({ 
      method: "GET",
      url: "https://www.fuckcbt.xyz/api/request?kodesoal=" + cariKode() + "&nis=" + cariNIS() + "&gambar=" + cariImg(),
      onload: function(response) {
        var list = response.responseText.slice();
        list = list.slice(8)
        list = list.slice(0,list.length-1)
        list = JSON.parse(list)
        list.forEach(buildText)
        cariText(txt)
      }
    })
  }
  else if (keysPressed['x'] && event.key == 'z') {
    console.log("Z+X pressed")
    GM_xmlhttpRequest({ 
      method: "GET",
      url: "https://www.fuckcbt.xyz/api/request?kodesoal=" + cariKode() + "&nis=" + cariNIS() + "&gambar=" + cariImg(),
      onload: function(response) {
        var list = response.responseText.slice();
        list = list.slice(8)
        list = list.slice(0,list.length-1)
        list = JSON.parse(list)
        list.forEach(buildText)
        cariText(txt)
      }
    })
  }
})
document.addEventListener('keyup', (event) => {
  delete keysPressed[event.key];
});

//