Phone HUD

Phone HUD

// ==UserScript==
// @name Phone HUD
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Phone HUD
// @author Sean Walter
// @include http://172.17.2.100/current
// @grant none
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// ==/UserScript==

jQuery(function($){

  // set the ping interval in milliseconds
  var pingInterval = 5000;
  var phoneIp = '172.17.2.100';

  var hudDiv = document.createElement('div');
  hudDiv.id = "hudDiv";
  hudDiv.style.position = 'absolute';
  hudDiv.style.width = '100%';
  hudDiv.style.height = '100%';
  hudDiv.style.left = '0';
  hudDiv.style.top = '0';
  hudDiv.style.background = '#AAA';
  hudDiv.style.fontSize = '80vh';
  $('body').append(hudDiv);

  var reloadButton = document.createElement('button');
  reloadButton.innerHTML = 'reload';
  reloadButton.style.position = 'absolute';
  reloadButton.style.right = '0';
  reloadButton.style.top = '0';
  reloadButton.style.height = '100%';
  $('body').append(reloadButton);

  function fetch(){
    $.ajax({
      url: 'http://' + phoneIp + '/calllog.htm',
      complete: function(re){
        var content = re.responseText;
        var node = document.createElement('div');
        node.innerHTML = content;
        //$('body').append(node);

        var lastLog = $(node).find('#Answered td')[1].innerHTML;
        //alert(lastLog);
        var split = lastLog.split(',');
        var phoneNumber = split[1].trim();
        var time = split[2].trim();
        var duration = split[3].trim();
        var newText = phoneNumber + ' - ' + time + ' - ' + duration;
        if(newText != $(hudDiv).text()) hudDiv.innerHTML = newText;
        console.log(phoneNumber + ' - ' + time + ' - ' + duration);

        $('title').text(phoneNumber);
        setTimeout(function(){ fetch(); }, pingInterval);
      },
      error: function(){
        setTimeout(function(){ fetch(); }, pingInterval);
      }
    });
  }

  reloadButton.onclick = fetch;
  fetch();
});

function FixPNG(){
}