-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSearchConsoleMonitor.html
More file actions
79 lines (73 loc) · 2.51 KB
/
SearchConsoleMonitor.html
File metadata and controls
79 lines (73 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
layout: default
permalink: /scm
---
<!DOCTYPE html>
<html>
<head>
<title>Indexed Pages Monitor</title>
<!-- Load Google APIs base client (needed for gapi.client.setToken if you want) -->
<script src="https://apis.google.com/js/api.js"></script>
<!-- Load Google Identity Services -->
<script src="https://accounts.google.com/gsi/client" async defer onload="gisLoaded()"></script>
</head>
<body>
<h1>Indexed Pages Count</h1>
<button id="authBtn" onclick="authorizeAndFetch()">Authorize & Fetch</button>
<pre id="output"></pre>
<script>
let tokenClient;
// Initialize GIS client
function gisLoaded() {
tokenClient = google.accounts.oauth2.initTokenClient({
client_id: '830015351192-38tmspassocrp65dok2mo83d54g9gtav.apps.googleusercontent.com',
scope: 'https://www.googleapis.com/auth/webmasters.readonly',
callback: (tokenResponse) => {
if (tokenResponse && tokenResponse.access_token) {
fetchSitemaps(tokenResponse.access_token);
} else {
showError('Token error', tokenResponse);
}
},
});
}
// Trigger authorization
function authorizeAndFetch() {
tokenClient.requestAccessToken();
}
// Fetch sitemap data directly via REST API
async function fetchSitemaps(accessToken) {
try {
const siteUrl = encodeURIComponent('https://www.pwindows.qzz.io/');
const resp = await fetch(
`https://www.googleapis.com/webmasters/v3/sites/${siteUrl}/sitemaps`,
{
headers: { Authorization: `Bearer ${accessToken}` },
}
);
const data = await resp.json();
if (data.sitemap && data.sitemap.length > 0) {
let output = '';
data.sitemap.forEach((smap) => {
const contents = smap.contents?.[0];
const submitted = contents?.submitted ?? 'n/a';
const indexed = contents?.indexed ?? 'n/a';
output += `Sitemap: ${smap.path}\nSubmitted: ${submitted}, Indexed: ${indexed}\n\n`;
});
document.getElementById('output').innerText = output.trim();
} else {
document.getElementById('output').innerText = 'No sitemap data found.';
}
} catch (err) {
showError('Fetch error', err);
}
}
// Error handler
function showError(label, err) {
console.error(label, err);
document.getElementById('output').innerText =
`${label}: ${JSON.stringify(err, null, 2)}`;
}
</script>
</body>
</html>