@@ -14,18 +14,39 @@ <h1>Indexed Pages Count</h1>
1414 < div id ="output "> </ div >
1515
1616 < script >
17- function initClient ( ) {
18- gapi . load ( 'client:auth2' , ( ) => {
19- gapi . auth2 . init ( {
20- client_id : '830015351192-38tmspassocrp65dok2mo83d54g9gtav.apps.googleusercontent.com' ,
21- scope : 'https://www.googleapis.com/auth/webmasters.readonly'
22- } ) . then ( ( ) => {
23- gapi . auth2 . getAuthInstance ( ) . signIn ( ) . then ( ( ) => {
24- gapi . client . load ( 'searchconsole' , 'v1' ) . then ( fetchSitemaps ) ;
25- } ) ;
17+ function initClient ( ) {
18+ gapi . load ( 'client:auth2' , ( ) => {
19+ gapi . auth2 . init ( {
20+ client_id : '830015351192-38tmspassocrp65dok2mo83d54g9gtav.apps.googleusercontent.com' ,
21+ scope : 'https://www.googleapis.com/auth/webmasters.readonly'
22+ } ) . then ( ( ) => {
23+ gapi . auth2 . getAuthInstance ( ) . signIn ( ) . then ( ( ) => {
24+ gapi . client . load ( 'searchconsole' , 'v1' ) . then ( fetchSitemaps )
25+ . catch ( err => showError ( 'API load error' , err ) ) ;
26+ } ) . catch ( err => showError ( 'Sign-in error' , err ) ) ;
27+ } ) . catch ( err => showError ( 'Init error' , err ) ) ;
2628 } ) ;
27- } ) ;
28- }
29- </ script >
29+ }
30+
31+ function fetchSitemaps ( ) {
32+ gapi . client . searchconsole . sitemaps . list ( {
33+ siteUrl : 'https://pwindows.qzz.io/'
34+ } ) . then ( response => {
35+ if ( response . result . sitemap && response . result . sitemap . length > 0 ) {
36+ const data = response . result . sitemap [ 0 ] . contents [ 0 ] ;
37+ document . getElementById ( 'output' ) . innerText =
38+ `Submitted: ${ data . submitted } , Indexed: ${ data . indexed } ` ;
39+ } else {
40+ document . getElementById ( 'output' ) . innerText = 'No sitemap data found.' ;
41+ }
42+ } ) . catch ( err => showError ( 'Fetch error' , err ) ) ;
43+ }
44+
45+ function showError ( label , err ) {
46+ console . error ( label , err ) ;
47+ document . getElementById ( 'output' ) . innerText =
48+ `${ label } : ${ JSON . stringify ( err , null , 2 ) } ` ;
49+ }
50+ </ script >
3051</ body >
3152</ html >
0 commit comments