Extract Google Business Data (v4)

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

当前为 2024-07-23 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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");
        }
    });
})();