/* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
// IE likes to cache too much :P
$.ajaxSetup({cache: false});
// Get PHP info
var token = $("#token").html();
var listType = $("#list-type").html();
var fullName = listType === "white" ? "Whitelist" : "Blacklist";
function sub(index, entry, arg) {
var domain = $("#list #"+index);
var locallistType = listType;
if(arg === "regex")
{
locallistType = "regex";
domain = $("#list-regex #"+index);
}
domain.hide("highlight");
$.ajax({
url: "scripts/pi-hole/php/sub.php",
method: "post",
data: {"domain":entry, "list":locallistType, "token":token},
success: function(response) {
if(response.length !== 0){
return;
}
domain.remove();
},
error: function(jqXHR, exception) {
alert("Failed to remove the domain!");
domain.show({queue:true});
}
});
}
function refresh(fade) {
var listw;
var list = $("#list");
if(listType === "black")
{
listw = $("#list-regex");
}
if(fade) {
list.fadeOut(100);
if(listw)
{
listw.fadeOut(100);
}
}
$.ajax({
url: "scripts/pi-hole/php/get.php",
method: "get",
data: {"list":listType},
success: function(response) {
list.html("");
if(listw)
{
listw.html("");
}
var data = JSON.parse(response);
if(data.length === 0) {
$("h3").hide();
if(listw)
{
listw.html("
Your " + fullName + " is empty!
");
}
else
{
list.html("
Your " + fullName + " is empty!
");
}
}
else
{
$("h3").show();
data[0] = data[0].sort();
data[0].forEach(function (entry, index) {
// Whitelist entry or Blacklist (exact entry) are in the zero-th
// array returned by get.php
list.append(
"
" + entry +
"
");
// Handle button
$("#list #"+index+"").on("click", "button", function() {
sub(index, entry, "exact");
});
});
// Add regex domains if present in returned list data
if(data.length === 2)
{
data[1] = data[1].sort();
data[1].forEach(function (entry, index) {
// Whitelist entry or Blacklist (exact entry) are in the zero-th
// array returned by get.php
listw.append(
"