Extracts and displays the data-pid and data-cid values from a Google Business profile page
目前為
// ==UserScript==
// @name Extract Google Business Data (v4)
// @namespace https://example.com/
// @version 4.0
// @description Extracts and displays the data-pid and data-cid values from a Google Business profile page
// @author sharmanhall
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
// @match https://www.google.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
window.addEventListener("load", function() {
let businessNameElement = document.querySelector('h2[data-attrid="title"]');
if (businessNameElement) {
let businessName = businessNameElement.textContent.trim();
console.log('%cBusiness name:','font-size: 16px; font-weight: bold; color:green', businessName);
} else {
console.error("Could not find the business name element on the page");
}
let reviewButton = document.querySelector("#wrkpb");
if (reviewButton) {
let dataPid = reviewButton.getAttribute("data-pid");
console.log('%cdata-pid:','font-size: 16px; font-weight: bold; color:green', dataPid);
console.log('%cdata-pid-link:', 'font-size: 16px; font-weight: bold; color:green', 'https://www.google.com/maps/place/?q=place_id:' + dataPid);
let dataPidElement = document.createElement('div');
dataPidElement.innerText = `PID: ${dataPid}`;
dataPidElement.style.fontSize = "14px";
dataPidElement.style.color = "red";
businessNameElement.append(dataPidElement);
let pidButton = document.createElement('div');
pidButton.className = "QqG1Sd";
pidButton.innerHTML = `<a class="ab_button" href="https://www.google.com/maps/place/?q=place_id:${dataPid}" role="button" target="_blank"><div>PlaceID</div></a>`;
businessNameElement.append(pidButton);
let writeReviewButton = document.createElement('div');
writeReviewButton.className = "QqG1Sd";
writeReviewButton.innerHTML = `<a class="ab_button" href="https://search.google.com/local/writereview?placeid=${dataPid}" role="button" target="_blank"><div>Write Review</div></a>`;
businessNameElement.append(writeReviewButton);
} else {
console.error("Could not find the 'Write a Review' button on the page");
}
let searchResultLink = document.querySelector('a[jscontroller="wuU7pb"]');
if (searchResultLink) {
let dataCid = searchResultLink.getAttribute("data-rc_ludocids");
console.log('%cdata-cid:','font-size: 16px; font-weight: bold; color:green', dataCid);
console.log('%cdata-cid-link:', 'font-size: 16px; font-weight: bold; color:green', 'https://local.google.com/place?id=' + dataCid + '&use=srp');
console.log('%cdata-cid-link:', 'font-size: 16px; font-weight: bold; color:green', 'https://maps.google.com/maps?cid=' + dataCid);
console.log('%cdata-cid-link:', 'font-size: 16px; font-weight: bold; color:green', 'https://www.google.com/maps?cid=' + dataCid);
let dataCidElement = document.createElement('div');
dataCidElement.innerText = `CID: ${dataCid}`;
dataCidElement.style.fontSize = "14px";
dataCidElement.style.color = "blue";
businessNameElement.append(dataCidElement);
let cidButton1 = document.createElement('div');
cidButton1.className = "QqG1Sd";
cidButton1.innerHTML = `<a class="ab_button" href="https://maps.google.com/maps?cid=${dataCid}" role="button" target="_blank"><div>maps.google</div></a>`;
businessNameElement.append(cidButton1);
let cidButton2 = document.createElement('div');
cidButton2.className = "QqG1Sd";
cidButton2.innerHTML = `<a class="ab_button" href="https://local.google.com/place?id=${dataCid}&use=srp" role="button" target="_blank"><div>local.google</div></a>`;
businessNameElement.append(cidButton2);
let cidButton3 = document.createElement('div');
cidButton3.className = "QqG1Sd";
cidButton3.innerHTML = `<a class="ab_button" href="https://www.google.com/maps?cid=${dataCid}" role="button" target="_blank"><div>google.com/maps</div></a>`;
businessNameElement.append(cidButton3);
} else {
console.error("Could not find the data-cid search result link on the page");
}
});
})();