mirror of
https://github.com/pi-hole/web.git
synced 2025-12-24 12:48:29 +00:00
Ensure blocking mode timer is started even when set via a third-party API call
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -39,10 +39,16 @@ function secondsTimeSpanToHMS(s) {
|
||||
return h + ":" + (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s); //zero padding on minutes and seconds
|
||||
}
|
||||
|
||||
function piholeChanged(blocking) {
|
||||
var status = $("#status");
|
||||
var ena = $("#pihole-enable");
|
||||
var dis = $("#pihole-disable");
|
||||
function piholeChanged(blocking, timer = null) {
|
||||
const status = $("#status");
|
||||
const ena = $("#pihole-enable");
|
||||
const dis = $("#pihole-disable");
|
||||
const enaT = $("#enableTimer");
|
||||
|
||||
if (timer !== null && parseFloat(timer) > 0) {
|
||||
enaT.html(Date.now() + parseFloat(timer) * 1000);
|
||||
setTimeout(countDown, 100);
|
||||
}
|
||||
|
||||
switch (blocking) {
|
||||
case "enabled": {
|
||||
@@ -83,7 +89,7 @@ function piholeChanged(blocking) {
|
||||
function countDown() {
|
||||
var ena = $("#enableLabel");
|
||||
var enaT = $("#enableTimer");
|
||||
var target = new Date(parseInt(enaT.html(), 10));
|
||||
var target = new Date(parseInt(enaT.text(), 10));
|
||||
var seconds = Math.round((target.getTime() - Date.now()) / 1000);
|
||||
|
||||
//Stop and remove timer when user enabled early
|
||||
@@ -97,7 +103,7 @@ function countDown() {
|
||||
ena.text("Enable Blocking (" + secondsTimeSpanToHMS(seconds) + ")");
|
||||
} else {
|
||||
ena.text("Enable Blocking");
|
||||
piholeChanged("enabled");
|
||||
piholeChanged("enabled", null);
|
||||
if (localStorage) {
|
||||
localStorage.removeItem("countDownTarget");
|
||||
}
|
||||
@@ -116,7 +122,7 @@ function checkBlocking() {
|
||||
method: "GET",
|
||||
})
|
||||
.done(function (data) {
|
||||
piholeChanged(data.blocking);
|
||||
piholeChanged(data.blocking, data.timer);
|
||||
utils.setTimer(checkBlocking, REFRESH_INTERVAL.blocking);
|
||||
})
|
||||
.fail(function (data) {
|
||||
@@ -126,8 +132,7 @@ function checkBlocking() {
|
||||
}
|
||||
|
||||
function piholeChange(action, duration) {
|
||||
var enaT = $("#enableTimer");
|
||||
var btnStatus;
|
||||
let btnStatus = null;
|
||||
|
||||
switch (action) {
|
||||
case "enable":
|
||||
@@ -155,11 +160,7 @@ function piholeChange(action, duration) {
|
||||
.done(function (data) {
|
||||
if (data.blocking === action + "d") {
|
||||
btnStatus.html("");
|
||||
piholeChanged(data.blocking);
|
||||
if (duration > 0) {
|
||||
enaT.html(Date.now() + duration * 1000);
|
||||
setTimeout(countDown, 100);
|
||||
}
|
||||
piholeChanged(data.blocking, data.timer);
|
||||
}
|
||||
})
|
||||
.fail(function (data) {
|
||||
|
||||
Reference in New Issue
Block a user