From 98ae7d6e9c040884d0bec3e30aeeab6399763ec5 Mon Sep 17 00:00:00 2001
From: fynks <75840152+fynks@users.noreply.github.com>
Date: Sun, 19 Jan 2025 20:02:05 +0500
Subject: [PATCH] refactor: streamline dark mode functionality and improve
script loading
---
docs/app-min.js | 2 +-
docs/app.js | 17 -----------------
docs/index.html | 6 +++++-
3 files changed, 6 insertions(+), 19 deletions(-)
diff --git a/docs/app-min.js b/docs/app-min.js
index 4969367..b7c4e44 100644
--- a/docs/app-min.js
+++ b/docs/app-min.js
@@ -1 +1 @@
-const debounce=(e,t=300)=>{let n;return(...a)=>{clearTimeout(n),n=setTimeout((()=>e(...a)),t)}};class TableManager{constructor(e,t,n){this.container=document.querySelector(`#${e}`),this.searchInput=document.querySelector(`#${t}`),this.clearIcon=document.querySelector(`#${n}`),this._setupSearchFunctionality()}generateTable(e={}){if(!Object.keys(e).length)return void(this.container.innerHTML="
No data available.
");const t=Object.keys(e[Object.keys(e)[0]]);this.container.innerHTML=`\n \n \n \n Service Name \n ${t.map((e=>`${e} `)).join("")}\n \n \n \n ${Object.entries(e).map((([e,n])=>`\n \n ${e} \n ${t.map((e=>`\n \n ${"yes"===n[e]?"✅":"❌"}\n \n `)).join("")}\n \n `)).join("")}\n \n
\n `}_setupSearchFunctionality(){const e=debounce((()=>{const e=this.searchInput.value.toLowerCase(),t=this.container.querySelectorAll("table tbody tr");this.clearIcon.style.display=e?"block":"none",t.forEach((t=>{const n=t.querySelector("td:first-child")?.textContent.toLowerCase();t.style.display=n?.includes(e)?"":"none"}))}));this.searchInput?.addEventListener("input",e),this.clearIcon?.addEventListener("click",(()=>{this.searchInput.value="",this.clearIcon.style.display="none",e()}))}}class ComparisonManager{constructor(e,t,n,a){this.container=document.querySelector(`#${e}`),this.select1=document.querySelector(`#${t}`),this.select2=document.querySelector(`#${n}`),this.data=a,this._populateDropdowns(),this._setupEventListeners()}_populateDropdowns(){const e=Object.keys(this.data[Object.keys(this.data)[0]]);[this.select1,this.select2].forEach((t=>{e.forEach((e=>{const n=document.createElement("option");n.value=e,n.textContent=e,t.appendChild(n)}))}))}_generateCompareTable(){const e=this.select1.value,t=this.select2.value;e&&t&&(this.container.innerHTML=`\n \n Close \n \n \n \n \n \n \n \n Service Name \n ${e} \n ${t} \n \n \n \n ${Object.entries(this.data).map((([n,a])=>`\n \n ${n} \n ${"yes"===a[e]?"✅":"❌"} \n ${"yes"===a[t]?"✅":"❌"} \n \n `)).join("")}\n \n
\n `,this.container.style.display="block",this._setupCloseButton())}_setupEventListeners(){[this.select1,this.select2].forEach((e=>{e?.addEventListener("change",(()=>this._generateCompareTable()))}))}_setupCloseButton(){this.container.querySelector("#close-compare")?.addEventListener("click",(()=>{this.container.style.display="none"}))}}class PricingManager{constructor(e){this.container=document.querySelector(`#${e}-table-container`)}generatePricingTable(e={}){if(!e.plans?.length)return void(this.container.innerHTML="Error: Invalid pricing data structure.
");const t=Object.keys(e.plans[0]).filter((e=>"name"!==e));this.container.innerHTML=`\n \n \n \n Plans \n ${t.map((e=>`${e} `)).join("")}\n \n \n \n ${e.plans.map((e=>`\n \n ${e.name} \n ${t.map((t=>`\n ${e[t]} \n `)).join("")}\n \n `)).join("")}\n \n
\n `}}document.addEventListener("DOMContentLoaded",(async()=>{const e=new TableManager("file-hosts-table-container","host-search-input","clear-host-search"),t=new TableManager("adult-hosts-table-container","adult-host-search-input","clear-adult-host-search"),n=new PricingManager("pricing");try{const[a,r,o]=await Promise.all([fetch("./json/file-hosts.json").then((e=>e.json())),fetch("./json/adult-hosts.json").then((e=>e.json())),fetch("./json/pricing.json").then((e=>e.json()))]);e.generateTable(a),t.generateTable(r),n.generatePricingTable(o),new ComparisonManager("compare-table-container","provider1","provider2",a)}catch(a){const r="Error loading data. Please try again later.
";e.container.innerHTML=r,t.container.innerHTML=r,n.container.innerHTML=r}})),document.addEventListener("DOMContentLoaded",(()=>{const e=document.getElementById("darkModeToggle"),t=localStorage.getItem("theme");t&&document.documentElement.setAttribute("data-theme",t),e.addEventListener("click",(()=>{const e="dark"===document.documentElement.getAttribute("data-theme")?"light":"dark";document.documentElement.setAttribute("data-theme",e),localStorage.setItem("theme",e)}))}));
\ No newline at end of file
+const debounce=(e,t=300)=>{let n;return(...a)=>{clearTimeout(n),n=setTimeout((()=>e(...a)),t)}};class TableManager{constructor(e,t,n){this.container=document.querySelector(`#${e}`),this.searchInput=document.querySelector(`#${t}`),this.clearIcon=document.querySelector(`#${n}`),this._setupSearchFunctionality()}generateTable(e={}){if(!Object.keys(e).length)return void(this.container.innerHTML="No data available.
");const t=Object.keys(e[Object.keys(e)[0]]);this.container.innerHTML=`\n \n \n \n Service Name \n ${t.map((e=>`${e} `)).join("")}\n \n \n \n ${Object.entries(e).map((([e,n])=>`\n \n ${e} \n ${t.map((e=>`\n \n ${"yes"===n[e]?"✅":"❌"}\n \n `)).join("")}\n \n `)).join("")}\n \n
\n `}_setupSearchFunctionality(){const e=debounce((()=>{const e=this.searchInput.value.toLowerCase(),t=this.container.querySelectorAll("table tbody tr");this.clearIcon.style.display=e?"block":"none",t.forEach((t=>{const n=t.querySelector("td:first-child")?.textContent.toLowerCase();t.style.display=n?.includes(e)?"":"none"}))}));this.searchInput?.addEventListener("input",e),this.clearIcon?.addEventListener("click",(()=>{this.searchInput.value="",this.clearIcon.style.display="none",e()}))}}class ComparisonManager{constructor(e,t,n,a){this.container=document.querySelector(`#${e}`),this.select1=document.querySelector(`#${t}`),this.select2=document.querySelector(`#${n}`),this.data=a,this._populateDropdowns(),this._setupEventListeners()}_populateDropdowns(){const e=Object.keys(this.data[Object.keys(this.data)[0]]);[this.select1,this.select2].forEach((t=>{e.forEach((e=>{const n=document.createElement("option");n.value=e,n.textContent=e,t.appendChild(n)}))}))}_generateCompareTable(){const e=this.select1.value,t=this.select2.value;e&&t&&(this.container.innerHTML=`\n \n Close \n \n \n \n \n \n \n \n Service Name \n ${e} \n ${t} \n \n \n \n ${Object.entries(this.data).map((([n,a])=>`\n \n ${n} \n ${"yes"===a[e]?"✅":"❌"} \n ${"yes"===a[t]?"✅":"❌"} \n \n `)).join("")}\n \n
\n `,this.container.style.display="block",this._setupCloseButton())}_setupEventListeners(){[this.select1,this.select2].forEach((e=>{e?.addEventListener("change",(()=>this._generateCompareTable()))}))}_setupCloseButton(){this.container.querySelector("#close-compare")?.addEventListener("click",(()=>{this.container.style.display="none"}))}}class PricingManager{constructor(e){this.container=document.querySelector(`#${e}-table-container`)}generatePricingTable(e={}){if(!e.plans?.length)return void(this.container.innerHTML="Error: Invalid pricing data structure.
");const t=Object.keys(e.plans[0]).filter((e=>"name"!==e));this.container.innerHTML=`\n \n \n \n Plans \n ${t.map((e=>`${e} `)).join("")}\n \n \n \n ${e.plans.map((e=>`\n \n ${e.name} \n ${t.map((t=>`\n ${e[t]} \n `)).join("")}\n \n `)).join("")}\n \n
\n `}}document.addEventListener("DOMContentLoaded",(async()=>{const e=new TableManager("file-hosts-table-container","host-search-input","clear-host-search"),t=new TableManager("adult-hosts-table-container","adult-host-search-input","clear-adult-host-search"),n=new PricingManager("pricing");try{const[a,r,o]=await Promise.all([fetch("./json/file-hosts.json").then((e=>e.json())),fetch("./json/adult-hosts.json").then((e=>e.json())),fetch("./json/pricing.json").then((e=>e.json()))]);e.generateTable(a),t.generateTable(r),n.generatePricingTable(o),new ComparisonManager("compare-table-container","provider1","provider2",a)}catch(a){const r="Error loading data. Please try again later.
";e.container.innerHTML=r,t.container.innerHTML=r,n.container.innerHTML=r}}));
\ No newline at end of file
diff --git a/docs/app.js b/docs/app.js
index 282d536..842d11b 100644
--- a/docs/app.js
+++ b/docs/app.js
@@ -208,20 +208,3 @@ document.addEventListener('DOMContentLoaded', async () => {
pricingManager.container.innerHTML = errorMessage;
}
});
-document.addEventListener('DOMContentLoaded', () => {
- const darkModeToggle = document.getElementById('darkModeToggle');
-
- // Check for saved theme preference
- const savedTheme = localStorage.getItem('theme');
- if (savedTheme) {
- document.documentElement.setAttribute('data-theme', savedTheme);
- }
-
- darkModeToggle.addEventListener('click', () => {
- const currentTheme = document.documentElement.getAttribute('data-theme');
- const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
-
- document.documentElement.setAttribute('data-theme', newTheme);
- localStorage.setItem('theme', newTheme);
- });
-});
\ No newline at end of file
diff --git a/docs/index.html b/docs/index.html
index abebc70..302781f 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -9,6 +9,7 @@
Debrid Services Comparison
+
Source | Made with ❤️ by Fynks
-
+
+