Greasy Fork

Greasy Fork is available in English.

Google Play APKMirror Link

在Google Play应用页面添加APKMirror搜索按钮

// ==UserScript==
// @name         Google Play APKMirror Link
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  在Google Play应用页面添加APKMirror搜索按钮
// @author       XYZ
// @match        https://play.google.com/store/apps/details?id=*
// @icon         https://t2.gstatic.com/faviconV2?client=SOCIAL&url=http://play.google.com&size=32
// @grant        none
// @license       MIT
// ==/UserScript==

(function() {
    'use strict';

    // 获取当前应用包名
    const appId = new URLSearchParams(window.location.search).get('id');
    if (!appId) return;

    // 创建APKMirror搜索按钮
    function createAPKButton() {
        const button = document.createElement('a');
        button.href = `https://www.apkmirror.com/?post_type=app_release&searchtype=apk&s=${appId}`;
        button.target = '_blank';
        button.className = 'VfPpkd-LgbsSe VfPpkd-LgbsSe-OWXEXe-k8QpJ VfPpkd-LgbsSe-OWXEXe-dgl2Hf nCP5yc AjY5Oe DuMIQc LQeN7 MjT6xe sOCCfd brKGGd BhQfub zwjsl';
        button.setAttribute('aria-label', 'Search APKMirror');

        // 添加按钮内部结构
        const rippleDiv = document.createElement('div');
        rippleDiv.className = 'VfPpkd-Jh9lGc';
        button.appendChild(rippleDiv);

        const contentDiv = document.createElement('div');
        contentDiv.className = 'VfPpkd-RLmnJb';
        button.appendChild(contentDiv);

        const span = document.createElement('span');
        span.className = 'VfPpkd-vQzf8d';
        span.textContent = 'APKMirror';
        button.appendChild(span);

        return button;
    }

    // 在安装按钮旁插入APKMirror按钮
    function insertButton() {
        const installButton = document.querySelector('.VfPpkd-dgl2Hf-ppHlrf-sM5MNb');
        if (!installButton) return false;

        const container = document.createElement('div');
        container.style.display = 'inline-block';
        container.style.marginLeft = '12px';
        container.appendChild(createAPKButton());

        installButton.parentNode.insertBefore(container, installButton.nextSibling);
        return true;
    }

    // 尝试插入按钮,失败则监听DOM变化
    if (!insertButton()) {
        new MutationObserver((_, observer) => {
            insertButton() && observer.disconnect();
        }).observe(document.body, { childList: true, subtree: true });
    }
})();