11// stats-counter.js
22
3- import servers from './servers.js' ;
4-
5- // Function to count the number of protected servers (excluding anonymous and DM)
6- function countProtectedServers ( ) {
7- let count = 0 ;
8- for ( const server in servers . serverNames ) {
9- if ( server !== 'DIRECT_MESSAGES' &&
10- ! server . startsWith ( 'ANONYMOUS_SERVER_' ) &&
11- servers . serverInvites [ server ] !== "" ) {
12- count ++ ;
3+ // Function to fetch and parse data from Inspection.md
4+ async function fetchInspectionData ( ) {
5+ try {
6+ const response = await fetch ( 'https://raw.githubusercontent.com/TheDARTProject/Database-Files/refs/heads/main/Inspection-Database/Inspection.md' ) ;
7+ if ( ! response . ok ) {
8+ throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
139 }
10+ const text = await response . text ( ) ;
11+ return parseInspectionData ( text ) ;
12+ } catch ( error ) {
13+ console . error ( 'Error fetching inspection data:' , error ) ;
14+ return null ;
1415 }
15- return count ;
1616}
1717
18- // Function to get total member count from all servers
19- async function getTotalMembers ( ) {
20- let totalMembers = 0 ;
21-
22- for ( const server in servers . serverInvites ) {
23- const inviteUrl = servers . serverInvites [ server ] ;
24- if ( inviteUrl && ! inviteUrl . startsWith ( 'http' ) ) continue ; // Skip invalid URLs
25-
26- try {
27- // Extract invite code from URL
28- const inviteCode = inviteUrl . split ( '/' ) . pop ( ) ;
29- if ( ! inviteCode ) continue ;
30-
31- const response = await fetch ( `https://corsproxy.io/?https://discord.com/api/v9/invites/${ inviteCode } ?with_counts=true` ) ;
32- if ( ! response . ok ) continue ;
33-
34- const data = await response . json ( ) ;
35- if ( data . approximate_member_count ) {
36- totalMembers += data . approximate_member_count ;
37- }
38- } catch ( error ) {
39- console . error ( `Error fetching member count for ${ server } :` , error ) ;
40- continue ;
41- }
18+ // Function to parse the Inspection.md content
19+ function parseInspectionData ( text ) {
20+ const data = {
21+ threatsDetected : 0 ,
22+ monitoredServers : 0 ,
23+ protectedMembers : 0 ,
24+ maliciousServers : 0 ,
25+ maliciousUrls : 0
26+ } ;
27+
28+ // Extract Total Cases (THREATS DETECTED)
29+ const totalCasesMatch = text . match ( / # # T o t a l C a s e s : ( \d + ) / ) ;
30+ if ( totalCasesMatch ) {
31+ data . threatsDetected = parseInt ( totalCasesMatch [ 1 ] . replace ( / , / g, '' ) ) ;
4232 }
4333
44- return totalMembers ;
45- }
34+ // Extract Protected Members (PROTECTED MEMBERS)
35+ const protectedMembersMatch = text . match ( / # # P r o t e c t e d M e m b e r s : ( [ \d , ] + ) / ) ;
36+ if ( protectedMembersMatch ) {
37+ data . protectedMembers = parseInt ( protectedMembersMatch [ 1 ] . replace ( / , / g, '' ) ) ;
38+ }
4639
47- // Function to fetch and count threats from the database
48- async function countThreats ( ) {
49- try {
50- const response = await fetch ( 'https://raw.githubusercontent.com/TheDARTProject/Database-Files/refs/heads/main/Main-Database/Compromised-Discord-Accounts.json' ) ;
51- if ( ! response . ok ) {
52- throw new Error ( 'Failed to fetch threats data' ) ;
53- }
54- const data = await response . json ( ) ;
55- return Object . keys ( data ) . length ;
56- } catch ( error ) {
57- console . error ( 'Error fetching threats:' , error ) ;
58- return 0 ;
40+ // Count Found On Server list (MONITORED SERVERS) - excluding DIRECT_MESSAGES
41+ const serverListMatch = text . match ( / # # F o u n d O n S e r v e r \n ( [ \s \S ] + ?) \n # # / ) ;
42+ if ( serverListMatch ) {
43+ const serverList = serverListMatch [ 1 ] . split ( '\n' )
44+ . filter ( line => line . trim ( ) . startsWith ( '- ' ) )
45+ . filter ( server => ! server . includes ( 'DIRECT_MESSAGES' ) ) ; // Exclude DIRECT_MESSAGES
46+ data . monitoredServers = serverList . length ;
5947 }
60- }
6148
62- // Function to count malicious URLs
63- async function countMaliciousUrls ( ) {
64- try {
65- const response = await fetch ( 'https://raw.githubusercontent.com/TheDARTProject/Database-Files/refs/heads/main/Filter-Database/Global-Domains.json' ) ;
66- if ( ! response . ok ) {
67- throw new Error ( 'Failed to fetch malicious URLs data' ) ;
68- }
69- const data = await response . json ( ) ;
70- return data . length ;
71- } catch ( error ) {
72- console . error ( 'Error fetching malicious URLs:' , error ) ;
73- return 0 ;
49+ // Extract Discord Servers (MALICIOUS SERVERS)
50+ const discordServersMatch = text . match ( / - \* \* D i s c o r d S e r v e r s \* \* : ( \d + ) e n t r i e s / ) ;
51+ if ( discordServersMatch ) {
52+ data . maliciousServers = parseInt ( discordServersMatch [ 1 ] . replace ( / , / g, '' ) ) ;
53+ }
54+
55+ // Extract Global Domains (MALICIOUS URLS)
56+ const globalDomainsMatch = text . match ( / - \* \* G l o b a l D o m a i n s \* \* : ( \d + ) e n t r i e s / ) ;
57+ if ( globalDomainsMatch ) {
58+ data . maliciousUrls = parseInt ( globalDomainsMatch [ 1 ] . replace ( / , / g, '' ) ) ;
7459 }
60+
61+ return data ;
7562}
7663
77- // Function to count malicious servers
78- async function countMaliciousServers ( ) {
79- try {
80- const response = await fetch ( 'https://raw.githubusercontent.com/TheDARTProject/Database-Files/refs/heads/main/Filter-Database/Discord-Servers.json' ) ;
81- if ( ! response . ok ) {
82- throw new Error ( 'Failed to fetch malicious servers data' ) ;
83- }
84- const data = await response . json ( ) ;
85- return Object . keys ( data ) . length ;
86- } catch ( error ) {
87- console . error ( 'Error fetching malicious servers:' , error ) ;
88- return 0 ;
64+ // Function to format numbers with appropriate units
65+ function formatNumber ( value , showDecimal = true ) {
66+ if ( value >= 1000000 ) {
67+ const millions = value / 1000000 ;
68+ return showDecimal ? `${ millions . toFixed ( millions % 1 === 0 ? 0 : 1 ) } M` : `${ Math . round ( millions ) } M` ;
69+ } else if ( value >= 1000 ) {
70+ const thousands = value / 1000 ;
71+ return showDecimal ? `${ thousands . toFixed ( thousands % 1 === 0 ? 0 : 1 ) } k` : `${ Math . round ( thousands ) } k` ;
8972 }
73+ return value . toLocaleString ( ) ;
9074}
9175
9276// Function to update the stats on the page
9377async function updateStats ( ) {
94- const threatsCount = await countThreats ( ) ;
95- const protectedServersCount = countProtectedServers ( ) ;
96- const totalMembers = await getTotalMembers ( ) ;
97- const maliciousUrlsCount = await countMaliciousUrls ( ) ;
98- const maliciousServersCount = await countMaliciousServers ( ) ;
99-
100- // Format numbers
101- const formattedThreats = threatsCount . toLocaleString ( ) ;
102- const formattedServers = protectedServersCount . toLocaleString ( ) ;
103- const formattedMembers = totalMembers >= 1000 ?
104- `${ Math . round ( totalMembers / 1000 ) } k` :
105- totalMembers . toLocaleString ( ) ;
106- const formattedUrls = maliciousUrlsCount . toLocaleString ( ) ;
107- const formattedServersMalicious = maliciousServersCount . toLocaleString ( ) ;
108-
109- // Update the DOM
78+ // Show loading state
79+ const statElements = [
80+ 'threats-detected' ,
81+ 'protected-servers' ,
82+ 'total-members' ,
83+ 'malicious-urls' ,
84+ 'malicious-servers'
85+ ] ;
86+
87+ statElements . forEach ( id => {
88+ document . getElementById ( id ) . textContent = 'Loading...' ;
89+ } ) ;
90+
91+ // Fetch and parse the data
92+ const inspectionData = await fetchInspectionData ( ) ;
93+
94+ if ( ! inspectionData ) {
95+ // Fallback if data couldn't be fetched
96+ statElements . forEach ( id => {
97+ document . getElementById ( id ) . textContent = 'Error' ;
98+ } ) ;
99+ return ;
100+ }
101+
102+ // Format numbers appropriately
103+ const formattedThreats = formatNumber ( inspectionData . threatsDetected ) ;
104+ const formattedServers = formatNumber ( inspectionData . monitoredServers ) + '+' ;
105+ const formattedMembers = formatNumber ( inspectionData . protectedMembers , false ) ; // No decimal for protected members
106+ const formattedUrls = formatNumber ( inspectionData . maliciousUrls ) ;
107+ const formattedServersMalicious = formatNumber ( inspectionData . maliciousServers ) ;
108+
109+ // Update the DOM with the new values
110110 document . getElementById ( 'threats-detected' ) . textContent = formattedThreats ;
111- document . getElementById ( 'protected-servers' ) . textContent = formattedServers + '+' ;
111+ document . getElementById ( 'protected-servers' ) . textContent = formattedServers ;
112112 document . getElementById ( 'total-members' ) . textContent = formattedMembers ;
113113 document . getElementById ( 'malicious-urls' ) . textContent = formattedUrls ;
114114 document . getElementById ( 'malicious-servers' ) . textContent = formattedServersMalicious ;
115115}
116116
117117// Initialize when DOM is loaded
118- document . addEventListener ( 'DOMContentLoaded' , updateStats ) ;
118+ document . addEventListener ( 'DOMContentLoaded' , updateStats ) ;
119+
120+ // Refresh stats every 5 minutes (300000 ms)
121+ setInterval ( updateStats , 300000 ) ;
0 commit comments