Ready! Search on Maps and click Start.
`;
const style = document.createElement('style');
style.textContent = `
#gmaps-lead-scraper-box {
position: fixed;
bottom: 20px;
right: 20px;
width: 320px;
background: #111827;
color: #f9fafb;
border-radius: 12px;
box-shadow: 0 12px 30px rgba(0,0,0,0.6);
z-index: 9999999;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
font-size: 13px;
border: 1px solid #374151;
overflow: hidden;
}
.gls-header {
background: linear-gradient(135deg, #10b981, #059669);
padding: 10px 14px;
display: flex;
justify-content: space-between;
align-items: center;
font-weight: 600;
color: #ffffff;
}
.gls-body {
padding: 12px 14px;
}
.gls-filter-group {
background: #1f2937;
padding: 8px 10px;
border-radius: 6px;
margin-bottom: 10px;
border: 1px solid #374151;
font-size: 12px;
color: #e5e7eb;
}
.gls-filter-group input {
cursor: pointer;
accent-color: #10b981;
}
.gls-status {
background: #0f172a;
padding: 8px 10px;
border-radius: 6px;
margin-bottom: 12px;
font-size: 12px;
color: #94a3b8;
border-left: 3px solid #10b981;
min-height: 40px;
line-height: 1.4;
word-break: break-word;
}
.gls-btn-group {
display: flex;
gap: 8px;
}
.gls-btn {
flex: 1;
padding: 10px;
border: none;
border-radius: 6px;
font-weight: bold;
cursor: pointer;
font-size: 13px;
transition: background 0.2s;
}
.gls-start {
background: #10b981;
color: white;
}
.gls-start:hover {
background: #059669;
}
.gls-stop {
background: #ef4444;
color: white;
}
.gls-stop:hover {
background: #dc2626;
}
`;
document.head.appendChild(style);
document.body.appendChild(box);
// Minimize toggle
let isMin = false;
document.getElementById('gls-min-btn').addEventListener('click', () => {
isMin = !isMin;
document.getElementById('gls-body-content').style.display = isMin ? 'none' : 'block';
document.getElementById('gls-min-btn').innerText = isMin ? '+' : '—';
});
// Button handlers
document.getElementById('gls-start-btn').addEventListener('click', startScraping);
document.getElementById('gls-stop-btn').addEventListener('click', () => {
shouldStop = true;
setStatus("🛑 Stopping & preparing CSV export...");
});
}
function setStatus(html) {
const el = document.getElementById('gls-status-text');
if (el) el.innerHTML = html;
}
// Phone Extractor
function getPhone() {
const phoneBtn = document.querySelector('button[data-item-id^="phone:tel:"], [data-item-id*="phone"]');
if (phoneBtn) {
const innerText = phoneBtn.querySelector('.Io6YTe')?.innerText?.trim();
if (innerText) return innerText;
const aria = phoneBtn.getAttribute('aria-label')?.replace(/^Phone:\s*/i, '').trim();
if (aria) return aria;
const itemId = phoneBtn.getAttribute('data-item-id')?.replace(/^phone:tel:/i, '').trim();
if (itemId) return itemId;
}
const telLink = document.querySelector('a[href^="tel:"]');
if (telLink) {
return telLink.getAttribute('href').replace('tel:', '').trim();
}
const infoSection = document.querySelector('div[aria-label^="Information for"], div.m6QErb');
if (infoSection) {
const text = infoSection.innerText || '';
const match = text.match(/(?:\+?880|0)?1[3-9]\d{2}[-\s]?\d{6}|\b(?:\+?\d{1,4}[-\s]?)?\(?\d{2,4}\)?[-.\s]?\d{3,4}[-.\s]?\d{3,4}/);
if (match) return match[0].trim();
}
return 'N/A';
}
// Website Extractor
function getWebsite() {
const addWebSection = document.querySelector('[data-section-id="456"], [jsaction*="suggestWebsiteEdit"]');
if (addWebSection && addWebSection.innerText.includes("Add website")) {
return '';
}
const authLink = document.querySelector('a[data-item-id="authority"], a[data-tooltip*="website" i], a[aria-label*="website" i]');
if (authLink && authLink.href && !authLink.href.includes('google.') && !authLink.href.includes('goo.gl')) {
return authLink.href;
}
const infoContainer = document.querySelector('div[aria-label^="Information for"]');
if (infoContainer) {
const extLink = infoContainer.querySelector('a[href^="http"]:not([href*="google.com"]):not([href*="business.google.com"]):not([href*="gstatic.com"])');
if (extLink) return extLink.href;
}
return '';
}
async function startScraping() {
const feed = document.querySelector('div[role="feed"]') || document.querySelector('[role="main"]');
if (!feed) {
alert("❌ No search results found! Please search on Google Maps first.");
return;
}
const noWebOnly = document.getElementById('gls-no-web-only').checked;
const delayMs = parseInt(document.getElementById('gls-speed-select').value) || 3000;
const startBtn = document.getElementById('gls-start-btn');
const stopBtn = document.getElementById('gls-stop-btn');
startBtn.style.display = 'none';
stopBtn.style.display = 'block';
isRunning = true;
shouldStop = false;
// Step 1: Auto-Scroll
setStatus("⏳ Step 1: Scrolling list (safe mode)...");
let lastHeight = 0;
let retries = 0;
while (!shouldStop && retries < 3) {
feed.scrollTop = feed.scrollHeight;
await new Promise(r => setTimeout(r, 1800)); // safe 1.8s scroll delay
const currentCount = feed.querySelectorAll('.Nv2PK, div[role="article"]').length;
setStatus(`⏳ Loading cards... Found: