Created
March 18, 2025 13:08
-
-
Save hclivess/85a247dcda8bfd04166422101e7256e5 to your computer and use it in GitHub Desktop.
Mass inject individual sitesmaps into Google console (sitemap is bugged and Google doesn't care)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Google Search Console Sitemap Submission Browser Script | |
* | |
* Instructions: | |
* 1. Log in to Google Search Console in your browser | |
* 2. Navigate to your property (https://zjistil.cz/) | |
* 3. Go to the Sitemaps section | |
* 4. Open browser console (F12 or Right-click > Inspect > Console) | |
* 5. Paste and run this script | |
*/ | |
(function() { | |
// Configuration | |
const baseUrl = 'https://zjistil.cz/sitemap_'; | |
const startIndex = 2151; | |
const endIndex = 1; | |
const submissionDelay = 2000; // Delay between submissions in milliseconds (2 seconds) | |
// Track progress | |
let currentIndex = startIndex; | |
let successCount = 0; | |
let failureCount = 0; | |
// Function to submit a single sitemap | |
async function submitSitemap(sitemapUrl) { | |
try { | |
console.log(`Attempting to submit: ${sitemapUrl}`); | |
// Find the sitemap input field and submit button based on the exact HTML structure | |
const inputField = document.querySelector('input.whsOnd.zHQkBf[jsname="YPqjbf"][aria-label="Enter sitemap URL"]'); | |
let submitButton = document.querySelector('div[role="button"][jsname="M2UYVd"] .RveJvd.snByac'); | |
// If the specific selector doesn't work, try a more general approach | |
if (!submitButton) { | |
const submitButtonAlt = Array.from(document.querySelectorAll('.RveJvd.snByac')).find( | |
el => el.textContent.trim().toLowerCase() === 'submit' | |
); | |
if (submitButtonAlt) { | |
submitButton = submitButtonAlt.closest('[role="button"]'); | |
} | |
} | |
if (!inputField || !submitButton) { | |
throw new Error("Couldn't find the input field or submit button. Make sure you're on the Sitemaps page."); | |
} | |
// Clear any existing value in the input field | |
inputField.value = ''; | |
// Trigger input events for React/Angular support | |
inputField.dispatchEvent(new Event('input', { bubbles: true })); | |
// Enter the sitemap URL | |
inputField.value = sitemapUrl; | |
inputField.dispatchEvent(new Event('input', { bubbles: true })); | |
inputField.dispatchEvent(new Event('change', { bubbles: true })); | |
// Click the Submit button (need to click the parent div with role="button") | |
const buttonToClick = submitButton.closest('[role="button"]') || submitButton; | |
buttonToClick.click(); | |
// If the button is disabled (has RDPZE class), we need to first enable it | |
if (buttonToClick.classList.contains('RDPZE')) { | |
console.log('Submit button appears to be disabled. Attempting to enable it...'); | |
// Remove disabled class | |
buttonToClick.classList.remove('RDPZE'); | |
buttonToClick.setAttribute('aria-disabled', 'false'); | |
// Then click | |
setTimeout(() => buttonToClick.click(), 100); | |
} | |
// Wait for the submission to complete (adjust time if needed) | |
await new Promise(resolve => setTimeout(resolve, 1500)); | |
// Check for any error messages | |
const errorElement = document.querySelector('.error-message') || | |
document.querySelector('[role="alert"]'); | |
if (errorElement && errorElement.textContent.trim() !== '') { | |
throw new Error(`Error submitting sitemap: ${errorElement.textContent.trim()}`); | |
} | |
console.log(`Successfully submitted: ${sitemapUrl}`); | |
successCount++; | |
return true; | |
} catch (error) { | |
console.error(`Failed to submit ${sitemapUrl}: ${error.message}`); | |
failureCount++; | |
return false; | |
} | |
} | |
// Main function to process all sitemaps | |
async function processAllSitemaps() { | |
console.log(`Starting submission of ${startIndex - endIndex + 1} sitemaps...`); | |
for (let i = startIndex; i >= endIndex; i--) { | |
const sitemapUrl = `${baseUrl}${i}.xml`; | |
await submitSitemap(sitemapUrl); | |
// Update progress | |
console.log(`Progress: ${startIndex - i + 1}/${startIndex - endIndex + 1} | Success: ${successCount} | Failed: ${failureCount}`); | |
// Wait before submitting the next sitemap | |
if (i > endIndex) { | |
console.log(`Waiting ${submissionDelay/1000} seconds before next submission...`); | |
await new Promise(resolve => setTimeout(resolve, submissionDelay)); | |
} | |
} | |
console.log(`Finished! Successfully submitted ${successCount} sitemaps, ${failureCount} failed.`); | |
} | |
// Execute the script | |
processAllSitemaps(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment