"use strict"; (function () { const API_TARGET = "https://netutils.hayoweb.info"; const RPC = { GET_REQUEST_IP: getRequestIp, LIST_REQUEST_ATTRIBUTES: listRequestAttributes, } const IP_DIV = document.getElementById("ip-div"); const IP_SPAN = document.getElementById("ip-span"); const REQ_ATTRS_PRE = document.getElementById("req-attrs-pre") const REQ_ATTRS_DIV = document.getElementById("req-attrs-div") function getRequestIp() { return fetch(API_TARGET + "/v1/request-attributes?filter=name=ip") .then(resp => resp.json(), console.error) .then(data => { let attrs = data.requestAttributes || []; for (let i = 0; i < attrs.length; i += 1) { if (attrs[i].name === "ip") { return attrs[i].stringValue; } } return "unknown"; }); } function listRequestAttributes() { return fetch(API_TARGET + "/v1/request-attributes") .then(resp => resp.json(), console.error) .then(data => JSON.stringify(data, null, 2)); } window.addEventListener("DOMContentLoaded", function (){ RPC.GET_REQUEST_IP().then(ip => { IP_SPAN.innerText = ip; IP_DIV.hidden = false; }); RPC.LIST_REQUEST_ATTRIBUTES().then(ip => { REQ_ATTRS_PRE.innerText = ip; REQ_ATTRS_DIV.hidden = false; }); }); }());