66< html >
77< head >
88 < title > Indexed Pages Monitor</ title >
9- <!-- Load Google APIs client -->
10-
9+ <!-- Define gapiLoaded before loading api.js -->
1110 < script >
12- function gapiLoaded ( ) {
13- gapi . load ( 'client' , initializeGapiClient ) ;
14- }
15- async function initializeGapiClient ( ) {
11+ let tokenClient ;
12+ let gapiInited = false ;
13+
14+ function gapiLoaded ( ) {
15+ gapi . load ( 'client' , initializeGapiClient ) ;
16+ }
17+
18+ async function initializeGapiClient ( ) {
1619 try {
1720 await gapi . client . init ( {
1821 discoveryDocs : [ 'https://www.googleapis.com/discovery/v1/apis/searchconsole/v1/rest' ] ,
1922 } ) ;
23+ // Explicitly load the Search Console API
24+ await gapi . client . load ( 'searchconsole' , 'v1' ) ;
2025 gapiInited = true ;
21- // Enable the button once initialization is complete
2226 document . getElementById ( 'authBtn' ) . disabled = false ;
2327 } catch ( err ) {
2428 showError ( 'Init error' , err ) ;
2529 }
2630 }
27- </ script >
28-
29- < script src ="https://apis.google.com/js/api.js " onload ="gapiLoaded() "> </ script >
30- <!-- Load Google Identity Services -->
31- < script src ="https://accounts.google.com/gsi/client " async defer onload ="gisLoaded() "> </ script >
32- </ head >
33- < body >
34- < h1 > Indexed Pages Count</ h1 >
35- < button id ="authBtn " onclick ="authorizeAndFetch() " disabled > Authorize & Fetch</ button >
36- < div id ="output "> </ div >
3731
38- < script >
39- let tokenClient ;
40- let gapiInited = false ;
41-
42- // Load GAPI client
43-
44- // Load GIS client
4532 function gisLoaded ( ) {
4633 tokenClient = google . accounts . oauth2 . initTokenClient ( {
4734 client_id : '830015351192-38tmspassocrp65dok2mo83d54g9gtav.apps.googleusercontent.com' ,
@@ -56,7 +43,6 @@ <h1>Indexed Pages Count</h1>
5643 } ) ;
5744 }
5845
59- // Trigger authorization
6046 function authorizeAndFetch ( ) {
6147 if ( ! gapiInited ) {
6248 showError ( 'Init error' , { message : 'GAPI not initialized yet' } ) ;
@@ -65,16 +51,21 @@ <h1>Indexed Pages Count</h1>
6551 tokenClient . requestAccessToken ( ) ;
6652 }
6753
68- // Fetch sitemap data
6954 async function fetchSitemaps ( ) {
7055 try {
7156 const response = await gapi . client . searchconsole . sitemaps . list ( {
7257 siteUrl : 'https://www.pwindows.qzz.io/' ,
7358 } ) ;
7459 if ( response . result . sitemap && response . result . sitemap . length > 0 ) {
75- const data = response . result . sitemap [ 0 ] . contents [ 0 ] ;
76- document . getElementById ( 'output' ) . innerText =
77- `Submitted: ${ data . submitted } , Indexed: ${ data . indexed } ` ;
60+ // Loop through all sitemaps instead of just the first
61+ let output = '' ;
62+ response . result . sitemap . forEach ( ( smap ) => {
63+ if ( smap . contents && smap . contents . length > 0 ) {
64+ const data = smap . contents [ 0 ] ;
65+ output += `Sitemap: ${ smap . path } \nSubmitted: ${ data . submitted } , Indexed: ${ data . indexed } \n\n` ;
66+ }
67+ } ) ;
68+ document . getElementById ( 'output' ) . innerText = output . trim ( ) ;
7869 } else {
7970 document . getElementById ( 'output' ) . innerText = 'No sitemap data found.' ;
8071 }
@@ -83,12 +74,21 @@ <h1>Indexed Pages Count</h1>
8374 }
8475 }
8576
86- // Error handler
8777 function showError ( label , err ) {
8878 console . error ( label , err ) ;
8979 document . getElementById ( 'output' ) . innerText =
9080 `${ label } : ${ JSON . stringify ( err , null , 2 ) } ` ;
9181 }
9282 </ script >
83+
84+ <!-- Load Google APIs client -->
85+ < script src ="https://apis.google.com/js/api.js " onload ="gapiLoaded() "> </ script >
86+ <!-- Load Google Identity Services -->
87+ < script src ="https://accounts.google.com/gsi/client " async defer onload ="gisLoaded() "> </ script >
88+ </ head >
89+ < body >
90+ < h1 > Indexed Pages Count</ h1 >
91+ < button id ="authBtn " onclick ="authorizeAndFetch() " disabled > Authorize & Fetch</ button >
92+ < pre id ="output "> </ pre >
9393</ body >
9494</ html >
0 commit comments