(Google Play Points) Check Availability

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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.2
// @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
//
// @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;");
    }

})();