summaryrefslogtreecommitdiff
path: root/src/scripts
diff options
context:
space:
mode:
authoraltaf-creator <64111012+altaf-creator@users.noreply.github.com>2023-05-03 22:12:11 +0700
committeraltaf-creator <64111012+altaf-creator@users.noreply.github.com>2023-05-03 22:12:11 +0700
commit568debd74070ecb23433a8fb413b48dcc56141eb (patch)
tree1916a58c3a5ec60827da2ea6e38baf2116b266d2 /src/scripts
Initial commit
Diffstat (limited to 'src/scripts')
-rw-r--r--src/scripts/quran.js196
-rw-r--r--src/scripts/sura-list.js67
-rw-r--r--src/scripts/window-buttons.js9
3 files changed, 272 insertions, 0 deletions
diff --git a/src/scripts/quran.js b/src/scripts/quran.js
new file mode 100644
index 0000000..76c18bf
--- /dev/null
+++ b/src/scripts/quran.js
@@ -0,0 +1,196 @@
+var metadata;
+var translations = ["en.sahih.xml", "id.indonesian.xml"];
+var tIndex = 0;
+var currentSura = 1;
+
+function changeLang(i) {
+ tIndex = i;
+ loadSuraButtons();
+ load(currentSura, tIndex)
+}
+
+// https://stackoverflow.com/a/46247496/21407402
+function getUrlVars() {
+ var vars = [], hash;
+ var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
+ for (var i = 0; i < hashes.length; i++) {
+ hash = hashes[i].split('=');
+ vars.push(hash[0]);
+ vars[hash[0]] = hash[1];
+ }
+ return vars;
+}
+
+function quranOnLoad() {
+ var a = getUrlVars()["sura"];
+ load(a, tIndex);
+ loadSuraButtons();
+
+ 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-link').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 load(suraIndex, translationIndex) {
+ currentSura = suraIndex;
+ loadMetadata(suraIndex - 1);
+
+ var xhttp = new XMLHttpRequest();
+
+ xhttp.onreadystatechange = function () {
+ if (this.readyState == 4 && this.status == 200) {
+ loadSura(this, translationIndex, suraIndex);
+ }
+ };
+
+ xhttp.open("GET", "./data/quran-uthmani.xml", true);
+ xhttp.send();
+}
+
+function loadSura(xml, translationIndex, index) {
+ var suraIndex = index - 1
+ var sura, i, xmlDoc, txt;
+
+ xmlDoc = xml.responseXML;
+ txt = "";
+ sura = xmlDoc.getElementsByTagName('sura');
+
+ var children = sura[suraIndex].children;
+
+ txt += "<ol>"
+ for (var i = 0; i < children.length; i++) {
+ txt += `<li class="sura-li">${children[i].getAttribute('text')}</li>
+ <p id="t-${i}"></p>
+ <hr>`;
+ }
+ txt += "</ol>"
+
+ loadTranslation(index, translationIndex);
+
+ document.getElementById("header").innerHTML = metadata[3] +
+ " - <b>" + sura[suraIndex].getAttribute('name') + "</b>";
+ document.getElementById("navbar-text").innerHTML = metadata[3] +
+ " - <b>" + sura[suraIndex].getAttribute('name') + "</b>";
+ document.getElementById("subheader").innerHTML = metadata[1] + " Aya <br>" + metadata[4];
+ document.getElementById("main").innerHTML = txt;
+}
+
+function loadAllAya(xml) {
+ var x, i, xmlDoc, txt;
+
+ xmlDoc = xml.responseXML;
+ txt = "";
+ x = xmlDoc.getElementsByTagName('aya');
+
+ txt += "<ol>"
+ for (i = 0; i < x.length; i++) {
+ txt += "<li>" + x[i].getAttribute('text') + "</li>";
+ }
+ txt += "</ol>"
+
+ document.getElementById("main").innerHTML = txt;
+}
+
+function loadMetadata(suraIndex) {
+ var xhttp = new XMLHttpRequest();
+
+ xhttp.onreadystatechange = function () {
+ if (this.readyState == 4 && this.status == 200) {
+ metadata = getMetadata(this, suraIndex);
+ }
+ };
+
+ xhttp.open("GET", "./data/quran-data.xml", true);
+ xhttp.send();
+}
+
+function getMetadata(xml, suraIndex) {
+ var sura, i, xmlDoc, txt;
+
+ xmlDoc = xml.responseXML;
+ txt = "";
+ sura = xmlDoc.getElementsByTagName('sura');
+
+ var index = sura[suraIndex].getAttribute('index');
+ var ayas = sura[suraIndex].getAttribute('ayas');
+ var name = sura[suraIndex].getAttribute('name');
+ var tname = sura[suraIndex].getAttribute('tname');
+ var type = sura[suraIndex].getAttribute('type');
+
+ var metadata = new Array(5);
+ metadata = [index, ayas, name, tname, type];
+
+ return metadata;
+}
+
+function loadSuraButtons() {
+ 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();
+}
+
+function loadMetadataButtons(xml) {
+ var sura, i, xmlDoc, txt;
+
+ xmlDoc = xml.responseXML;
+ txt = "";
+ sura = xmlDoc.getElementsByTagName('sura');
+
+ document.getElementById("sidebar-sura").innerHTML = "";
+ for (var i = 0; i < sura.length; i++) {
+ var index = sura[i].getAttribute('index');
+ var tname = sura[i].getAttribute('tname');
+
+ document.getElementById("sidebar-sura").innerHTML += `<a class="side-buttons" href="#" onclick="load(${index}, ${tIndex})"><i class="fa-solid fa-book-quran"></i> ${tname}</a>`;
+ }
+}
+
+function loadTranslation(suraIndex, translationIndex, aya) {
+ var xhttp = new XMLHttpRequest();
+
+ xhttp.onreadystatechange = function () {
+ if (this.readyState == 4 && this.status == 200) {
+ loadTranslationAya(this, suraIndex, aya);
+ }
+ };
+
+ xhttp.open("GET", `./data/${translations[translationIndex]}`, true);
+ xhttp.send();
+}
+
+function loadTranslationAya(xml, index, aya) {
+ var suraIndex = index - 1
+ var sura, i, xmlDoc, txt;
+
+ xmlDoc = xml.responseXML;
+ txt = "";
+ sura = xmlDoc.getElementsByTagName('sura');
+
+ var children = sura[suraIndex].children;
+
+ for (var i = 0; i < children.length; i++) {
+ txt = children[i].getAttribute("text");
+ document.getElementById(`t-${i}`).innerHTML = txt;
+ }
+}
diff --git a/src/scripts/sura-list.js b/src/scripts/sura-list.js
new file mode 100644
index 0000000..a799b02
--- /dev/null
+++ b/src/scripts/sura-list.js
@@ -0,0 +1,67 @@
+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';
+ }
+ } 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>`;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/scripts/window-buttons.js b/src/scripts/window-buttons.js
new file mode 100644
index 0000000..5c4f0da
--- /dev/null
+++ b/src/scripts/window-buttons.js
@@ -0,0 +1,9 @@
+const { ipcRenderer } = require('electron');
+
+document.getElementById('minimize').addEventListener('click', () => {
+ ipcRenderer.send('min');
+})
+
+document.getElementById('maximize').addEventListener('click', () => {
+ ipcRenderer.send('max');
+}) \ No newline at end of file