Extract Google Business Data (v4)

Extracts and displays the data-pid and data-cid values from a Google Business profile page

目前為 2024-07-23 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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");
        }
    });
})();