summaryrefslogtreecommitdiff
path: root/src/scripts/sura-list.js
blob: abbae2e64614afc8b67a5088d42d8b7b141821a6 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var metadata;

function load() {
    var xhttp = new XMLHttpRequest();

    xhttp.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
            loadMetadataButtons(this);
        }
    };

    xhttp.open("GET", "./data/quran-data.xml", true);
    xhttp.send();

    try {
        process.versions['electron'];

        var windowBtns = document.getElementsByClassName('window-button-container');
        
        for (var i = 0; i < windowBtns.length; i++) {
            windowBtns[i].style.display = 'grid';
        }

        document.getElementById('openquran-home').href = 'index.html'
    } catch {
        var windowBtns = document.getElementsByClassName('window-button-container');

        for (var i = 0; i < windowBtns.length; i++) {
            windowBtns[i].style.display = 'none';
        }
    }
}

function loadMetadataButtons(xml) {
    var sura, i, xmlDoc, txt;

    xmlDoc = xml.responseXML;
    txt = "";
    sura = xmlDoc.getElementsByTagName('sura');

    for (var i = 0; i < sura.length; i++) {
        var index = sura[i].getAttribute('index');
        var tname = sura[i].getAttribute('tname');

        try {
            process.versions['electron'];

            document.getElementById("sura-ul").innerHTML += `
                <li>
                    <table>
                        <tr>
                            <td class="number">${index}</td>
                            <td style="padding-left: 10px;"><a href="sura.html?sura=${index}" class="link">${tname}</a></td>
                        </tr>
                    </table>
                </li>`;
        } catch {
            document.getElementById("sura-ul").innerHTML += `
                <li>
                    <table>
                        <tr>
                            <td class="number">${index}</td>
                            <td style="padding-left: 10px;"><a href="sura?sura=${index}" class="link">${tname}</a></td>
                        </tr>
                    </table>
                </li>`;
        }
    }
}