sisyshell / KYKWifi_Internet_Calculator

// ==UserScript==
// @name        KYKWifi_Internet_Calculator
// @namespace   http://wifi.kyk.gov.tr/
// @version     1.0
// @date        2019-10-29
// @author      Sisyshell
// @description KYKWifi_Internet_Calculator: calculates the amount of internet used and the amount of internet remaining
// @match           http://wifi.kyk.gov.tr/*
// @include         http://wifi.kyk.gov.tr/*
// @match           https://wifi.kyk.gov.tr/*
// @include         https://wifi.kyk.gov.tr/*
// @license MIT
// @copyright 2019, sisyshell (https://openuserjs.org/users/sisyshell)
// ==/UserScript==
PrimeFaces.ab({
  s: "servisUpdateForm:j_idt123"
});
var timer = null;

function myStopFunction() {
  clearInterval(timer);
}

timer = setInterval(function () {
  var table = document.getElementById('sorguSonuclari_data');
  if (table !== undefined && table !== null) {
    var rows = table.childNodes;
    var lastMount = 0;
    var usedInternet = 0;

    for (var i = 0; i < rows.length; i++) {
      if (lastMount === 0) {
        lastMount = rows[i].firstChild.innerText.split('.')[1];
      }
      if (lastMount == rows[i].firstChild.innerText.split('.')[1]) {
        usedInternet += Number(rows[i].childNodes[2].innerText) + Number(rows[i].childNodes[3].innerText);
      }
    }
    document.getElementsByClassName('ui-button')[0].innerText = 1024 * 16 - usedInternet + " MB internet left ( <= Main Page)";
    //alert(1024 * 16 - usedInternet + " MB internet left");
    myStopFunction();
  }
}, 3000);