(Google Play Points) Check Availability

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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.4
// @author          Wack.3gp (https://greasyfork.org/users/4792)
// @copyright       2024+, Wack.3gp
// @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=BYW9D395KJWZ2
// @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 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 " + GM_info.script.author + "\nand I wrote this script as a hobby.\nIf you find it useful, I would appreciate a small donation! =)");
    window.open(GM_info.script.header.match(/@contributionURL\s+(.+)/)[1], "_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;");
    }

})();