From 568debd74070ecb23433a8fb413b48dcc56141eb Mon Sep 17 00:00:00 2001
From: altaf-creator <64111012+altaf-creator@users.noreply.github.com>
Date: Wed, 3 May 2023 22:12:11 +0700
Subject: Initial commit
---
src/scripts/quran.js | 196 ++++++++++++++++++++++++++++++++++++++++++
src/scripts/sura-list.js | 67 +++++++++++++++
src/scripts/window-buttons.js | 9 ++
3 files changed, 272 insertions(+)
create mode 100644 src/scripts/quran.js
create mode 100644 src/scripts/sura-list.js
create mode 100644 src/scripts/window-buttons.js
(limited to 'src/scripts')
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 += "
"
+ for (var i = 0; i < children.length; i++) {
+ txt += `- ${children[i].getAttribute('text')}
+
+
`;
+ }
+ txt += "
"
+
+ loadTranslation(index, translationIndex);
+
+ document.getElementById("header").innerHTML = metadata[3] +
+ " - " + sura[suraIndex].getAttribute('name') + "";
+ document.getElementById("navbar-text").innerHTML = metadata[3] +
+ " - " + sura[suraIndex].getAttribute('name') + "";
+ document.getElementById("subheader").innerHTML = metadata[1] + " Aya
" + metadata[4];
+ document.getElementById("main").innerHTML = txt;
+}
+
+function loadAllAya(xml) {
+ var x, i, xmlDoc, txt;
+
+ xmlDoc = xml.responseXML;
+ txt = "";
+ x = xmlDoc.getElementsByTagName('aya');
+
+ txt += ""
+ for (i = 0; i < x.length; i++) {
+ txt += "- " + x[i].getAttribute('text') + "
";
+ }
+ txt += "
"
+
+ 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 += ` ${tname}`;
+ }
+}
+
+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 += `
+
+
+ `;
+ } catch {
+ document.getElementById("sura-ul").innerHTML += `
+
+
+ `;
+ }
+ }
+}
\ 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
--
cgit v1.2.3