@@ -9,20 +9,22 @@ const container = document.querySelector('.container');
99getConfigBtn . addEventListener ( 'click' , async ( ) => {
1010 getConfigBtn . disabled = true ;
1111 getConfigBtn . textContent = 'Generating...' ;
12+ console . log ( 'Button clicked!' ) ;
1213 try {
1314 showSpinner ( ) ;
1415 const { publicKey, privateKey } = await fetchKeys ( ) ;
1516 const installId = generateRandomString ( 22 ) ;
1617 const fcmToken = `${ installId } :APA91b${ generateRandomString ( 134 ) } ` ;
1718 const accountData = await fetchAccount ( publicKey , installId , fcmToken ) ;
18- if ( accountData ) await generateConfig ( accountData , privateKey ) ;
19+ if ( accountData ) generateConfig ( accountData , privateKey ) ;
1920 } catch ( error ) {
2021 console . error ( 'Error processing configuration:' , error ) ;
2122 showPopup ( 'Failed to generate config. Please try again.' , 'error' ) ;
2223 } finally {
2324 hideSpinner ( ) ;
2425 getConfigBtn . disabled = false ;
2526 getConfigBtn . textContent = 'Get Free Config' ;
27+ // Scroll to the config section after generating
2628 setTimeout ( ( ) => {
2729 if ( wireGuardConfig . firstChild ) {
2830 wireGuardConfig . scrollIntoView ( { behavior : 'smooth' , block : 'start' } ) ;
@@ -80,48 +82,29 @@ const fetchAccount = async (publicKey, installId, fcmToken) => {
8082 }
8183} ;
8284
83- // Fetch random endpoint from remote API
84- const fetchRandomEndpoint = async ( ) => {
85- const fallback = 'engage.cloudflareclient.com:2408' ;
86- try {
87- const res = await fetch ( 'https://raw.githubusercontent.com/ircfspace/endpoint/refs/heads/main/ip.json' ) ;
88- if ( ! res . ok ) throw new Error ( `HTTP ${ res . status } ` ) ;
89- const data = await res . json ( ) ;
90- if ( ! Array . isArray ( data . ipv4 ) || data . ipv4 . length === 0 ) throw new Error ( "No IPv4 available" ) ;
91- const random = data . ipv4 [ Math . floor ( Math . random ( ) * data . ipv4 . length ) ] ;
92- return random ;
93- } catch ( e ) {
94- console . warn ( "Falling back to default endpoint:" , e ) ;
95- return fallback ;
96- }
97- } ;
98-
9985// Generate and Display Configurations
100- const generateConfig = async ( data , privateKey ) => {
86+ const generateConfig = ( data , privateKey ) => {
10187 const reserved = generateReserved ( data . config . client_id ) ;
102- const endpoint = await fetchRandomEndpoint ( ) ;
103-
104- const wireGuardText = generateWireGuardConfig ( data , privateKey , endpoint ) ;
88+ const wireGuardText = generateWireGuardConfig ( data , privateKey ) ;
10589 const v2rayText = generateV2RayURL (
10690 privateKey ,
10791 data . config . peers [ 0 ] . public_key ,
10892 data . config . interface . addresses . v4 ,
10993 data . config . interface . addresses . v6 ,
110- reserved ,
111- endpoint
94+ reserved
11295 ) ;
113-
11496 updateDOM ( wireGuardConfig , 'WireGuard Format' , 'wireguardBox' , wireGuardText , 'message1' ) ;
11597 updateDOM ( v2rayConfig , 'V2Ray Format' , 'v2rayBox' , v2rayText , 'message2' ) ;
11698 downloadBtn . style . display = 'block' ;
117-
99+
100+ // Add event listeners to newly created copy buttons
118101 document . querySelectorAll ( '.copy-button' ) . forEach ( btn => {
119102 btn . addEventListener ( 'click' , handleCopyButtonClick ) ;
120103 } ) ;
121104} ;
122105
123106// Generate WireGuard Configuration Text
124- const generateWireGuardConfig = ( data , privateKey , endpoint ) => `
107+ const generateWireGuardConfig = ( data , privateKey ) => `
125108[Interface]
126109PrivateKey = ${ privateKey }
127110Address = ${ data . config . interface . addresses . v4 } /32, ${ data . config . interface . addresses . v6 } /128
@@ -131,7 +114,7 @@ MTU = 1280
131114[Peer]
132115PublicKey = ${ data . config . peers [ 0 ] . public_key }
133116AllowedIPs = 0.0.0.0/0, ::/0
134- Endpoint = ${ endpoint }
117+ Endpoint = engage.cloudflareclient.com:2408
135118` ;
136119
137120// Generate Reserved Parameter Dynamically
@@ -142,10 +125,12 @@ const generateReserved = (clientId) =>
142125 . join ( '%2C' ) ;
143126
144127// Generate V2Ray URL
145- const generateV2RayURL = ( privateKey , publicKey , ipv4 , ipv6 , reserved , endpoint ) =>
146- `wireguard://${ encodeURIComponent ( privateKey ) } @${ endpoint } ?address=${ encodeURIComponent (
128+ const generateV2RayURL = ( privateKey , publicKey , ipv4 , ipv6 , reserved ) =>
129+ `wireguard://${ encodeURIComponent ( privateKey ) } @engage.cloudflareclient.com:2408 ?address=${ encodeURIComponent (
147130 ipv4 + '/32'
148- ) } ,${ encodeURIComponent ( ipv6 + '/128' ) } &reserved=${ reserved } &publickey=${ encodeURIComponent ( publicKey ) } &mtu=1420#V2ray-Config`;
131+ ) } ,${ encodeURIComponent ( ipv6 + '/128' ) } &reserved=${ reserved } &publickey=${ encodeURIComponent (
132+ publicKey
133+ ) } &mtu=1420#V2ray-Config`;
149134
150135// Update DOM with Configurations
151136const updateDOM = ( container , title , textareaId , content , messageId ) => {
@@ -169,7 +154,7 @@ const hideSpinner = () => {
169154} ;
170155
171156// Handle Copy Button Click
172- const handleCopyButtonClick = async function ( ) {
157+ const handleCopyButtonClick = async function ( e ) {
173158 const targetId = this . getAttribute ( 'data-target' ) ;
174159 const messageId = this . getAttribute ( 'data-message' ) ;
175160 try {
@@ -202,11 +187,11 @@ const showPopup = (message, type = 'success') => {
202187 const popup = document . createElement ( 'div' ) ;
203188 popup . className = 'popup-message' ;
204189 popup . textContent = message ;
205-
190+
206191 if ( type === 'error' ) {
207192 popup . style . backgroundColor = '#d32f2f' ;
208193 }
209-
194+
210195 document . body . appendChild ( popup ) ;
211196 setTimeout ( ( ) => {
212197 if ( popup . parentNode ) {
@@ -247,13 +232,17 @@ const downloadConfig = (fileName, content) => {
247232// Check for viewport size changes
248233function checkViewportSize ( ) {
249234 if ( window . innerWidth <= 480 ) {
235+ // For very small screens
250236 container . style . padding = '15px' ;
251237 } else if ( window . innerWidth <= 768 ) {
238+ // For small screens
252239 container . style . padding = '20px' ;
253240 } else {
241+ // For larger screens
254242 container . style . padding = '32px' ;
255243 }
256244}
257245
246+ // Run on page load and when window is resized
258247window . addEventListener ( 'load' , checkViewportSize ) ;
259- window . addEventListener ( 'resize' , checkViewportSize ) ;
248+ window . addEventListener ( 'resize' , checkViewportSize ) ;
0 commit comments