Skip to content

Instantly share code, notes, and snippets.

@tyhallcsu
Created September 11, 2023 21:31
Show Gist options
  • Save tyhallcsu/847460c0e3f2b40ad3413aaf8b6370c1 to your computer and use it in GitHub Desktop.
Save tyhallcsu/847460c0e3f2b40ad3413aaf8b6370c1 to your computer and use it in GitHub Desktop.
Extract Google Business data-pid (v2)
// ==UserScript==
// @name Extract Google Business data-pid (v2)
// @namespace https://example.com/
// @version 0.1
// @description Extracts the data-pid value from a Google Business profile page
// @author Tyler Hall
// @icon https://www.google.com/s2/favicons?sz=64&domain=tylerhalltech.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);
let dataPidElement = document.createElement('div');
dataPidElement.innerText = `PID: ${dataPid}`;
dataPidElement.style.fontSize = "14px";
dataPidElement.style.color = "red";
businessNameElement.append(dataPidElement);
} 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);
let dataCidElement = document.createElement('div');
dataCidElement.innerText = `CID: ${dataCid}`;
dataCidElement.style.fontSize = "14px";
dataCidElement.style.color = "blue";
businessNameElement.append(dataCidElement);
} else {
console.error("Could not find the data-cid search result link on the page");
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment