From b5c034a84c0801035de82fad1cdfb437bba47add Mon Sep 17 00:00:00 2001 From: andrewstech Date: Thu, 25 Jan 2024 12:31:43 +0000 Subject: [PATCH 1/2] Add graphs to data Co-authored-by: William Harrison --- .gitignore | 1 + index.html | 47 ++++++++++-- script.js | 207 ++++++++++++++++++++++++++++++++--------------------- 3 files changed, 171 insertions(+), 84 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..11cdf6d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +index copy.html diff --git a/index.html b/index.html index 9254842..c40592b 100644 --- a/index.html +++ b/index.html @@ -6,16 +6,34 @@ - Domains | is-a.dev + Domain Data | is-a.dev + + + +
+
+ +
+
+ +
+
+
@@ -27,8 +45,29 @@
- - - + + + + diff --git a/script.js b/script.js index ea60298..3bed1a5 100644 --- a/script.js +++ b/script.js @@ -1,106 +1,154 @@ const tableBody = document.getElementById("data-body"); +const types = { + Cloudflare: ".pages.dev", + DBH: "69.30.249.53", + GitHub: ".github.io" +} + const hiddenDomains = [ "_psl", "@", "www" ] -function loadData() { - fetch("https://raw-api.is-a.dev", { - method: "GET" - }).then(res => res.json()).then(data => { - data.sort((a, b) => a.subdomain.localeCompare(b.subdomain)); - - data.forEach(i => { - if(hiddenDomains.includes(i.subdomain)) return; - - let row = tableBody.insertRow(-1); - - let c1 = row.insertCell(0); - let c2 = row.insertCell(1); - let c3 = row.insertCell(2); +// Function to create a pie chart +function createPieChart(labels, data, chartTitle) { + const ctx = document.getElementById("pieChart").getContext("2d"); + + new Chart(ctx, { + type: "pie", + data: { + labels: labels, + datasets: [{ + data: data, + backgroundColor: generateRandomColors(labels.length), + borderWidth: 0 + }] + }, + options: { + responsive: true, + maintainAspectRatio: false, + plugins: { + title: { + display: true, + text: chartTitle, + font: { + size: 16, + weight: "bold" + }, + color: "rgb(66, 133, 244)" // Use a different color for the title + }, + tooltip: { + enabled: true, + backgroundColor: "rgba(0, 0, 0, 0.7)", + borderColor: "rgba(0, 0, 0, 0.9)", + borderWidth: 1 + } + } + } + }); +} - c1.classList = "px-4 py-2 outline outline-1 outline-gray-700"; - c2.classList = "px-4 py-2 outline outline-1 outline-gray-700"; - c3.classList = "px-4 py-2 outline outline-1 outline-gray-700"; +// Function to generate random colors for the pie chart +function generateRandomColors(numColors) { + const colors = []; + for (let i = 0; i < numColors; i++) { + const randomColor = `rgba(${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)}, 0.7)`; + colors.push(randomColor); + } + return colors; +} - const records = []; +// Function to extract data for the pie chart +function extractChartData(data) { + const recordCounts = {}; + data.forEach(i => { + if (!hiddenDomains.includes(i.subdomain)) { Object.keys(i.record).forEach(record => { - if(record === "A" || record === "AAAA" || record === "MX" || record === "TXT") { - if(Array.isArray(i.record[record])) { - i.record[record].forEach(r => { - records.push(`${record} ${r}`); - }); - } else { - records.push(`${record} ${i.record[record]}`); - } - } else if(record === "URL") { - records.push(`${record} ${i.record[record]}`); + if (recordCounts[record]) { + recordCounts[record]++; } else { - records.push(`${record} ${i.record[record]}`); + recordCounts[record] = 1; } - }) + }); + } + }); - c1.innerHTML = `${i.subdomain}`; - c2.innerHTML = `Username: ${i.owner.username ? `${i.owner.username}` : `None`}
Email: ${i.owner.email ? `${i.owner.email.replace(" (at) ", "@")}` : `None`}`; - c3.innerHTML = records.join("
"); - }) - }) -} + const labels = Object.keys(recordCounts); + const dataValues = Object.values(recordCounts); -const types = { - discord: "_discord", - ghPages: "_github-pages-challenge" + return { labels, dataValues }; } -function loadDiscordData() { - fetch("https://raw-api.is-a.dev", { - method: "GET" - }).then(res => res.json()).then(data => { - data.sort((a, b) => a.subdomain.localeCompare(b.subdomain)); - - data.forEach(i => { - if(hiddenDomains.includes(i.subdomain)) return; - if(!i.subdomain.startsWith(types.discord)) return; - - let row = tableBody.insertRow(-1); - - let c1 = row.insertCell(0); - let c2 = row.insertCell(1); - let c3 = row.insertCell(2); - - c1.classList = "px-4 py-2 outline outline-1 outline-gray-700"; - c2.classList = "px-4 py-2 outline outline-1 outline-gray-700"; - c3.classList = "px-4 py-2 outline outline-1 outline-gray-700"; - - const records = []; +// Function to create a bar chart +function createBarChart(labels, data, chartTitle) { + const ctx = document.getElementById("barChart").getContext("2d"); + + new Chart(ctx, { + type: "bar", + data: { + labels: labels, + datasets: [{ + label: chartTitle, + data: data, + backgroundColor: generateRandomColors(labels.length), + borderWidth: 0 + }] + }, + options: { + responsive: true, + maintainAspectRatio: false, + plugins: { + legend: { + display: true, + position: "bottom" // Change legend position to bottom + }, + tooltip: { + enabled: true, + backgroundColor: "rgba(0, 0, 0, 0.7)", + borderColor: "rgba(0, 0, 0, 0.9)", + borderWidth: 0 + } + } + } + }); +} - Object.keys(i.record).forEach(record => { - if(record === "A" || record === "AAAA" || record === "MX" || record === "TXT") { - if(Array.isArray(i.record[record])) { - i.record[record].forEach(r => { - records.push(`${record} ${r}`); - }); - } else { - records.push(`${record} ${i.record[record]}`); - } - } else if(record === "URL") { - records.push(`${record} ${i.record[record]}`); +// Function to extract data for the bar chart +function extractBarChartData(data, serviceTypes) { + const serviceCounts = {}; + + data.forEach(i => { + if (!hiddenDomains.includes(i.subdomain)) { + // Check if the subdomain type matches any of the specified service types + const matchedServiceType = serviceTypes.find(type => { + if (type === "Cloudflare" && i.record.CNAME?.endsWith(types[type])) return true; + if (type === "DBH" && i.record.A?.includes(types[type])) return true; + if (type === "Email" && i.record.MX?.length) return true; + if (type === "GitHub" && i.record.CNAME?.endsWith(types[type])) return true; + + return false; + }); + + if (matchedServiceType) { + if (serviceCounts[matchedServiceType]) { + serviceCounts[matchedServiceType]++; } else { - records.push(`${record} ${i.record[record]}`); + serviceCounts[matchedServiceType] = 1; } - }) + } + } + }); - c1.innerHTML = `${i.subdomain}`; - c2.innerHTML = `Username: ${i.owner.username ? `${i.owner.username}` : `None`}
Email: ${i.owner.email ? `${i.owner.email.replace(" (at) ", "@")}` : `None`}`; - c3.innerHTML = records.join("
"); - }) - }) + const labels = Object.keys(serviceCounts); + const dataValues = Object.values(serviceCounts); + + return { labels, dataValues }; } -function loadGHPagesData() { +function loadData() { fetch("https://raw-api.is-a.dev", { method: "GET" }).then(res => res.json()).then(data => { @@ -108,7 +156,6 @@ function loadGHPagesData() { data.forEach(i => { if(hiddenDomains.includes(i.subdomain)) return; - if(!i.subdomain.startsWith(types.ghPages)) return; let row = tableBody.insertRow(-1); From f40537a0467e6a72e0d8334c593f44c62c49adb4 Mon Sep 17 00:00:00 2001 From: William Harrison Date: Thu, 25 Jan 2024 20:33:06 +0800 Subject: [PATCH 2/2] Discard changes to .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 11cdf6d..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -index copy.html