(Google Play Points) Check Availability

Checks if the weekly Google Play reward is ready to be claimed.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            (Google Play Points) Check Availability
// @name:de         (Google Play Points) Verfügbarkeit Prüfen
// @description     Checks if the weekly Google Play reward is ready to be claimed.
// @description:de  Prüft, ob die wöchentliche Google Play Prämie zum Einlösen bereit ist.
// @version         0.0.1.3
// @author          JAS1998 (https://greasyfork.org/users/4792)
// @copyright       2024+, JAS1998
// @namespace       https://greasyfork.org/users/4792
// @license         CC BY-NC-ND 4.0; http://creativecommons.org/licenses/by-nc-nd/4.0/
// @icon            https://www.gstatic.com/android/market_images/web/favicon_v3.ico
//
// @include         *
// @noframes
// @run-at          document-idle
//
// @grant           GM_notification
// @grant           GM_xmlhttpRequest
// @grant           GM_registerMenuCommand
// @grant           GM_setValue
// @grant           GM_getValue
//
// @supportURL      https://greasyfork.org/scripts/493895/feedback
// @compatible      Chrome tested with Tampermonkey
// @contributionURL https://www.paypal.com/donate?hosted_button_id=9JEGCDFJJHWU8
// @contributionAmount €1.00
// ==/UserScript==

(function() {
    'use strict';

    const _vault = "4792";
    const _isOriginal = GM_info.script.namespace.includes(_vault);
    const _originalURL = "https://greasyfork.org/scripts/493895";
    const _authorName = GM_info.script.author.split('(')[0].trim();

    const perksUrl = "https://play.google.com/store/points/perks";

    const checkProtection = () => {
        if (!_isOriginal) {
            alert("Please install the Original Version");
            window.location.href = _originalURL;
            return false;
        }
        return true;
    };

    function runCheck() {
        if (!checkProtection()) return;

        const today = new Date().toDateString();

        if (GM_getValue("lastSuccessfulClaimCheck") === today) {
            return;
        }

        GM_xmlhttpRequest({
            method: "GET",
            url: perksUrl,
            anonymous: false, 
            onload: function(response) {
                let parser = new DOMParser();
                let doc = parser.parseFromString(response.responseText, "text/html");

                const buttons = Array.from(doc.querySelectorAll("button"));
                const claimButton = buttons.find(btn => 
                    btn.textContent.includes("Einlösen") || btn.textContent.includes("Claim")
                );

                if (claimButton) {
                    const isDisabled = claimButton.hasAttribute('disabled') || 
                                       claimButton.getAttribute('aria-disabled') === 'true' ||
                                       claimButton.classList.contains('disabled');

                    if (!isDisabled) {
                        GM_notification({
                            title: "Google Play Points",
                            text: "Your weekly reward is available! Click here to claim it.",
                            image: "https://www.gstatic.com/images/branding/product/2x/google_play_96dp.png",
                            onclick: function() {
                                window.open(perksUrl, "_blank");
                            }
                        });
                    }
                } else {
                    const html = response.responseText;
                    if (html.includes("Prämie") || html.includes("Gold") || html.includes("Reward")) {
                        GM_setValue("lastSuccessfulClaimCheck", today);
                    }
                }
            }
        });
    }

    let lastExecution = GM_getValue("lastCheckTimestamp", 0);
    let currentTime = Date.now();

    if (currentTime - lastExecution > 1000 * 60 * 60 * 24) {
        GM_setValue("lastCheckTimestamp", currentTime);
        runCheck();
    }

    GM_registerMenuCommand("⭐ Check Play Points", function() {
        runCheck();
    });

    GM_registerMenuCommand("🎁 Donate", function () {
        alert(`Hello, I'm ${_authorName}\nand I wrote this script as a hobby.\nIf you find it useful, I would appreciate a small donation! =)`);
        window.open("https://www.paypal.com/donate?hosted_button_id=9JEGCDFJJHWU8", "_blank");
    });

    if (_isOriginal) {
        console.log(`%c ${GM_info.script.name} v${GM_info.script.version} %c (Verified Original)`, 
                    "background: #f44336; color: white; font-weight: bold; padding: 2px 5px;", "color: #f44336;");
    }

})();