(Google Play Points) Check Availability

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

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

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

})();