Files
web/scripts/pi-hole/js/footer.js
Adam Warner f204b71707 [Staging] 3.1 (#514)
* Remove double click handler

* ~Today~ Over Last 24 Hours

* Rename Top Advertisers to Top Blocked Domains

* percentage should be a float instead of an integer

* Define $over_time as array. Fixes #501

* Add hover/hit radius for Forward Destinations over Time graph

* Add custom callback for tooltips and disable legend for Forward Destinations over Time graph

* Remove legend, add tooltips and increase hit/hover radius for Query Types over Time graph. Fixes #502

* Don't hide detailed graphs on small screens any longer

*  🌮 is the new :shipit: squirrel

* revise wording on main page

shorter text to fit in one line on smaller screens

* Show warning in browser when fopen() failed

* open links in new tab

* open links in new tab

* Update header.php

* select 'Login' in Navbar when showing loginpage

using the same term as it is already used to show up the loginpage (in line 565)

* set the mainbox wider on smaller screens

solves issue of overlapping text with loginbutton when using smaller screens

* also fix overlapping loginpage on footerbar

* remove border on logo

* add link feedback (on hover)

* sessiontimer in bold letters

* use AdminLTE function to toggle dropdown-menu

AdminLTE has already an implemented function to toggle the user menu.
So there is no need to use an own script in footer.js
 
Benefit: The dropdown-menu closes if you click on a blank Place

* align donate-url with url in footerbar

* remove function to open user menu

AdminLTE has already an implemented function to toggle the user menu.
So there is no need to use an own script in footer.js

Benefit: The dropdown-menu closes if you click on a blank Place

* Update LICENSE of the project to EUPL v1.2

* Major overhaul of update checker - checks only every 30 minutes to reduce number of GitHub API requests

* Add version info to dropdown menu (top right) for viewing on small screens. Addresses #333 partially

* Fix typo

* footer.php: improve and clean up

move animation-stylesheet to pi-hole.css (Have you noticed that there is even a text- and text-shadow animation set, but for webkit-browsers only)
added <!-- Version Infos -->
correct continuous hide of version info (AdminLTEs classed widths as `xs` > `sm` > `md` > `lg`)
display Donate-text alwas in one line (do not wrap in between when version info string gets very long)

* pi-hole.css: pasted animation stylesheet

and improved the text-shadow-animation to work correctly with and without -webkit-prefix
(for me this wasn't working until now)

* header.php: some corrections & improvements

pull dropdown-menu always to right side
changed <!-- Update alerts --> to <!-- Version Infos --> (just like it is in footer)
hide version infos in dropdown-menu if it gets shown in footer
repaired update-urls, they also should open up in new tab & gets underlined on hover
`background:none` is needed because AdminLTE adds dark bg on hover to links when using it on smallscreen (xs)

* Minor change to make the dashboard's javascript compatible with escaped characters (like apostrophe) in client names

* Add the same for the top domains

* ... and Top Ads

* Minor change to comments

* footer.php: edited as discussed

* header.php: edited as discussed

* Update queryads.js

* Update list.js

* queryads.js: codacy fixes

* list.js: codacy fixes

* list.js: small correction

* queryads.js: small correction

* Be able to interpret status 5

* Sort list entries (black-/whitelist) alphabetically before creating the table

* queryads.js: Update*

* removed double comment and updated code to center and separate the buttons on small screens, like in my last screenshot.

* list.js: update*

updated code to center and separate the buttons on small screens, like in my last screenshot.
2017-06-20 22:17:37 +01:00

209 lines
5.8 KiB
JavaScript

/* 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. */
//The following functions allow us to display time until pi-hole is enabled after disabling.
//Works between all pages
function secondsTimeSpanToHMS(s) {
var h = Math.floor(s/3600); //Get whole hours
s -= h*3600;
var m = Math.floor(s/60); //Get remaining minutes
s -= m*60;
return h+":"+(m < 10 ? "0"+m : m)+":"+(s < 10 ? "0"+s : s); //zero padding on minutes and seconds
}
function countDown(){
var ena = $("#enableLabel");
var enaT = $("#enableTimer");
var target = new Date(parseInt(enaT.html()));
var seconds = Math.round((target.getTime() - new Date().getTime()) / 1000);
if(seconds > 0){
setTimeout(countDown,1000);
ena.text("Enable (" + secondsTimeSpanToHMS(seconds) + ")");
}
else
{
ena.text("Enable");
piholeChanged("enabled");
localStorage.removeItem("countDownTarget");
}
}
function piholeChanged(action)
{
var status = $("#status");
var ena = $("#pihole-enable");
var dis = $("#pihole-disable");
switch(action) {
case "enabled":
status.html("<i class='fa fa-circle' style='color:#7FFF00'></i> Active");
ena.hide();
dis.show();
dis.removeClass("active");
break;
case "disabled":
status.html("<i class='fa fa-circle' style='color:#FF0000'></i> Offline");
ena.show();
dis.hide();
break;
}
}
function piholeChange(action, duration)
{
var token = encodeURIComponent($("#token").html());
var enaT = $("#enableTimer");
var btnStatus;
switch(action) {
case "enable":
btnStatus = $("#flip-status-enable");
btnStatus.html("<i class='fa fa-spinner'> </i>");
$.getJSON("api.php?enable&token=" + token, function(data) {
if(data.status === "enabled") {
btnStatus.html("");
piholeChanged("enabled");
}
});
break;
case "disable":
btnStatus = $("#flip-status-disable");
btnStatus.html("<i class='fa fa-spinner'> </i>");
$.getJSON("api.php?disable=" + duration + "&token=" + token, function(data) {
if(data.status === "disabled") {
btnStatus.html("");
piholeChanged("disabled");
if(duration > 0)
{
enaT.html(new Date().getTime() + duration * 1000);
setTimeout(countDown,100);
}
}
});
break;
}
}
$( document ).ready(function() {
var enaT = $("#enableTimer");
var target = new Date(parseInt(enaT.html()));
var seconds = Math.round((target.getTime() - new Date().getTime()) / 1000);
if (seconds > 0)
{
setTimeout(countDown,100);
}
});
// Handle Enable/Disable
$("#pihole-enable").on("click", function(e){
e.preventDefault();
localStorage.removeItem("countDownTarget");
piholeChange("enable","");
});
$("#pihole-disable-permanently").on("click", function(e){
e.preventDefault();
piholeChange("disable","0");
});
$("#pihole-disable-10s").on("click", function(e){
e.preventDefault();
piholeChange("disable","10");
});
$("#pihole-disable-30s").on("click", function(e){
e.preventDefault();
piholeChange("disable","30");
});
$("#pihole-disable-5m").on("click", function(e){
e.preventDefault();
piholeChange("disable","300");
});
$("#pihole-disable-custom").on("click", function(e){
e.preventDefault();
var custVal = $("#customTimeout").val();
custVal = $("#btnMins").hasClass("active") ? custVal * 60 : custVal;
piholeChange("disable",custVal);
});
// Session timer
var sessionvalidity = parseInt(document.getElementById("sessiontimercounter").textContent);
var start = new Date;
function updateSessionTimer()
{
start = new Date;
start.setSeconds(start.getSeconds() + sessionvalidity);
}
if(sessionvalidity > 0)
{
// setSeconds will correctly handle wrap-around cases
updateSessionTimer();
setInterval(function() {
var current = new Date;
var totalseconds = (start - current) / 1000;
// var hours = Math.floor(totalseconds / 3600);
// totalseconds = totalseconds % 3600;
var minutes = Math.floor(totalseconds / 60);
if(minutes < 10){ minutes = "0" + minutes; }
var seconds = Math.floor(totalseconds % 60);
if(seconds < 10){ seconds = "0" + seconds; }
if(totalseconds > 0)
{
document.getElementById("sessiontimercounter").textContent = minutes + ":" + seconds;
}
else
{
document.getElementById("sessiontimercounter").textContent = "-- : --";
}
}, 1000);
}
else
{
document.getElementById("sessiontimer").style.display = "none";
}
// Handle Strg + Enter button on Login page
$(document).keypress(function(e) {
if((e.keyCode === 10 || e.keyCode === 13) && e.ctrlKey && $("#loginpw").is(":focus")) {
$("#loginform").attr("action", "settings.php");
$("#loginform").submit();
}
});
function testCookies()
{
if (navigator.cookieEnabled)
{
return true;
}
// set and read cookie
document.cookie = "cookietest=1";
var ret = document.cookie.indexOf("cookietest=") !== -1;
// delete cookie
document.cookie = "cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT";
return ret;
}
$(function() {
if(!testCookies() && $("#cookieInfo").length)
{
$("#cookieInfo").show();
}
});