Implemented filter functions

This commit is contained in:
DL6ER
2017-01-14 14:02:18 +01:00
parent f9d353af83
commit b7b7217fb0

View File

@@ -1,17 +1,17 @@
var exact = "";
// Credit: http://stackoverflow.com/a/10642418/2087442
function httpGet(ta,theUrl)
function httpGet(ta,quiet,theUrl)
{
var xmlhttp;
if (window.XMLHttpRequest)
{
// code for IE7+
// code for IE7+
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
@@ -19,13 +19,36 @@ function httpGet(ta,theUrl)
if (xmlhttp.readyState === 4 && xmlhttp.status === 200)
{
ta.show();
ta.html(xmlhttp.responseText);
ta.empty();
if(!quiet)
{
ta.append(xmlhttp.responseText);
}
else
{
quietfilter(ta,xmlhttp.responseText);
}
}
};
xmlhttp.open("GET", theUrl, false);
xmlhttp.send();
}
function quietfilter(ta,data)
{
var lines = data.split("\n");
for(var i = 0;i<lines.length;i++)
{
if(lines[i].indexOf("results") !== -1 && lines[i].indexOf("0 results") === -1)
{
var shortstring = lines[i].replace("::: /etc/pihole/","").replace("data: ","");
// Remove "(x results)"
shortstring = shortstring.replace(/\(.*/,"");
ta.append(shortstring+"\n");
}
}
}
function eventsource() {
var ta = $("#output");
var domain = $("#domain");
@@ -44,7 +67,7 @@ function eventsource() {
// IE does not support EventSource - load whole content at once
if (typeof EventSource !== "function") {
httpGet(ta,"/admin/scripts/pi-hole/php/queryads.php?domain="+domain.val().toLowerCase()+"&"+exact);
httpGet(ta,quiet,"/admin/scripts/pi-hole/php/queryads.php?domain="+domain.val().toLowerCase()+"&"+exact);
return;
}
@@ -62,17 +85,7 @@ function eventsource() {
}
else
{
var lines = e.data.split("\n");
for(var i = 0;i<lines.length;i++)
{
if(lines[i].indexOf("results") !== -1 && lines[i].indexOf("0 results") === -1)
{
var shortstring = lines[i].replace("::: /etc/pihole/","");
// Remove "(x results)"
shortstring = shortstring.replace(/\(.*/,"");
ta.append(shortstring+"\n");
}
}
quietfilter(ta,e.data);
}
}, false);