TP-Link Router Interface Enhancer

Adds an extra "Client Name" column or information to several sub-pages of the TP-Link router web-interface.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        TP-Link Router Interface Enhancer
// @description Adds an extra "Client Name" column or information to several sub-pages of the TP-Link router web-interface.
// @namespace   localhost
// @include     http://192.168*/*/userRpm/*
// @require     https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js
// @version     1.0
// @grant       none
// ==/UserScript==

var MACaddr = {
  "12-34-56-78-90-AB": "(PC) Sample",
  "23-45-67-89-0A-BC": "(NAS) Sample",
  "34-56-78-90-AB-CD": "(Printer) Sample",
  "45-67-89-0A-BC-DE": "(TV) Sample",
  "56-78-90-AB-CD-EF": "(Smartphone) Sample",
  "67-89-0A-BC-DE-F1": "(Tablet) Sample"
};

function init() {
  if(location.href.includes("AssignedIpAddrListRpm.htm")) DHCP.DHCPClientsList();
  if(location.href.includes("FixMapCfgRpm.htm")) DHCP.AddressReservation();
  if(location.href.includes("WlanStationRpm")) Wireless.WirelessStatistics();
  if(location.href.includes("SystemStatisticRpm.htm")) SystemTools.Statistics();
}


var Wireless = {
  "WirelessStatistics": function() {
    $("#autoWidth").find("table").find("tr").each(function() {
      var ct = $(this).find("td").eq(1).text();
      var nt;
      if(ct==="MAC Address") {
        nt = '<td class="ListTC2" id="t_host_name">Client Name</td>';
      } else {
        nt = '<td class="ListC2">' + ((typeof MACaddr[ct]==="string") ? MACaddr[ct] : "-") + "</td>";
      }
      $(this).find("td").eq(1).after("<td>" + nt + "</td>");
    });    
  }
};

var DHCP = {
  "DHCPClientsList": function() {
    $("#autoWidth").find("table").find("tr").each(function() {
      var ct = $(this).find("td").eq(1).text();
      var cm = $(this).find("td").eq(2).text();
      var hn = ((typeof MACaddr[cm]==="string") ? '<span title="Original Name: ' + ct + '" style="font-weight: bold;">' + MACaddr[cm] + '</span>' : ct);
      if(ct!=="Client Name") $(this).find("td").eq(1).html(hn);
    });
  },
  "AddressReservation": function() {
    // code is currently identical to Wireless.WirelessStatistics();
    // keeping this separated for easy readability and distinctive method names
    Wireless.WirelessStatistics();
  }
};

var SystemTools = {
  "Statistics": function() {
    $("#autoWidth").find("table").find("tr").each(function() {
      if($(this).find("td").length===8) {
        $(this).find("td").eq(0).html('Client Name<br>IP Address');
      }
      if($(this).find("td").length===9) {
        var hi = $(this).find("td").eq(0).html().split('<br>');
        if(hi.length!==2) return;
        $(this).find("td").eq(0).html(((typeof MACaddr[hi[1]]==="string") ? MACaddr[hi[1]] : "-") + "<br>" + hi[0]);
      }
    });
  }
};

var $ = jQuery;
init();