afr / get-datek-WarRoom

// ==UserScript==
// @name         get-datek-WarRoom
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  try to take over the world!
// @author       afr
// @include      /https:\/\/node-b.telkom.co.id\/*/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=co.id
// @grant        GM.setClipboard
// @grant        GM_xmlhttpRequest
// @updateURL    https://openuserjs.org/meta/afr/get-datek-WarRoom.meta.js
// @downloadURL  https://openuserjs.org/install/afr/get-datek-WarRoom.user.js
// @copyright    2022
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';

  $(document).ready(() => {

    $("iframe#myIframe").on("load", () => {

      $("div.ui-dialog-buttonset").append("<button id='fill' type='button'>Fill</button>");
      $("div.ui-dialog-buttonset").append(`<button id="qwe" type="button" style="background-color: #fc2b8d;">Copy</button>`);

      const fill = $("#fill");
      fill.on("click", () => {

        const NE = $("iframe").contents().find("table:eq(1) input[id*='Siteid']:eq(0)").val();
        const FE = $("iframe").contents().find("table:eq(1) input[id*='Siteid']:eq(1)").val();

        const prodURL = `https://autofill-2u8b.onrender.com/radio-datek?NE=${NE}&FE=${FE}`;
        const localURL = `http://localhost:3000/radio-datek?NE=${NE}&FE=${FE}`;
        const url = `https://autofill.faizruzain.site/radio-datek?NE=${NE}&FE=${FE}`;

        const details = {
          method: "GET",
          url: url,
          headers: {
            "Content-Type": "application/json",
          },
          responseType: "json",
          onerror: (err) => {
            console.log(err.responseText);
            console.log(err.statusText);
          },
          onload: (res) => {
            console.log(res.status);
            gas(res.response);
          },
        };

        GM_xmlhttpRequest(details);
      });

      const qwe = $("button#qwe");
      qwe.on("click", () => {
        let data = document.getElementById('myIframe').contentWindow.document.querySelectorAll('table')[1].querySelectorAll('th');
        let datek = ''

        for (let i = 5; i < 29; i++) {
          if (i % 2 === 1) {
            datek += data[i].innerHTML + '\n';
          }
          else {
            data[i].querySelector('input').value.length === 0 ? datek += '-\n' : datek += data[i].querySelector('input').value + '\n';
          }
        }
        //copy to clipboard
        //console.log(datek)
        GM.setClipboard(datek);
      });
    });

    function gas(data) {
      const inputs = $("iframe").contents().find("table:eq(1) input:gt(5)");
      inputs[0].value = data.NE.actNeAlamat;
      inputs[1].value = data.FE.actFeAlamat;
      inputs[2].value = data.NE.actNeLat;
      inputs[3].value = data.FE.actFeLat;
      inputs[4].value = data.NE.actNeLong;
      inputs[5].value = data.FE.actFeLong;
    };
  });

})();