aboutsummaryrefslogtreecommitdiff
path: root/script.h
blob: abccd7e782958712c56ba3cda44ef56b94817d6c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const char script[] PROGMEM = R"=====(
function fixNoNetwork() {
    if (getParameterByName(\"l\") != null) {
        document.getElementById(\"homePageAddr\").href = \"/?l=1\";
        document.getElementById(\"settingsPageAddr\").href = \"/settings?l=1\";
        return;
    }

    try {
        var xhttp = new XMLHttpRequest();
        xhttp.onerror = function onError(e) {
            //alert(\"Error \" + e.target.status + \" occurred while receiving the document.\");
            var hrefAddr = window.location.href + \"?l=1\";
            window.location.replace(hrefAddr);
        };
        xhttp.open(\"GET\", \"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css\", true);
        xhttp.setRequestHeader(\"Content-type\", \"application/x-www-form-urlencoded\");
        xhttp.send();
    } catch (e) {
        console.log(e);
    }
}

function ajax_request(adress, callback_function) {
    /* A simple ajax request wrapper
       Doesn´t return anything else than the callback */
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            callback_function(this.responseText);
        }
    };
    xhttp.open(\"POST\", adress, true);
    xhttp.setRequestHeader(\"Content-type\", \"application/x-www-form-urlencoded\");
    xhttp.send();
}

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, \"\\$&\");
    var regex = new RegExp(\"[?&]\" + name + \"(=([^&#]*)|&|#|$)\"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, \" \"));
}
)=====";