ZeroAd: Poki

Instant, zero-delay Poki SDK bypass with immediate hooks

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         ZeroAd: Poki
// @namespace    https://greasyfork.org/users/zeroadv4
// @version      4.0.1
// @description  Instant, zero-delay Poki SDK bypass with immediate hooks
// @author       ZeroAd Team
// @match        *://*.poki.com/*
// @match        *://poki.com/*
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const CONFIG = {
        DEBUG: true               // set false for production silence
    };

    const METRICS = {
        hooksInstalled: 0,
        interceptedCalls: 0,
        failedHooks: 0,
        rewardsGranted: 0
    };

    const log = (...args) => CONFIG.DEBUG && console.log('[ZeroAd:Poki]', ...args);
    const warn = (...args) => CONFIG.DEBUG && console.warn('[ZeroAd:Poki]', ...args);
    const error = (...args) => console.error('[ZeroAd:Poki]', ...args);

    function safeDispatchEvent(target, eventName) {
        try {
            target.dispatchEvent(new CustomEvent(eventName, { bubbles: true }));
        } catch (e) { /* ignore */ }
    }

    function safeCallback(fn, ...args) {
        if (typeof fn === 'function') {
            try { fn(...args); } catch (e) { warn('Callback error:', e); }
        }
    }

    // ═══════ CORE HOOK (instant, no delays) ═══════
    function hookPokiSDK(sdk) {
        if (!sdk || sdk.__zaHooked) return false;

        try {
            sdk.__zaHooked = true;

            // Midroll ads → skip
            if (typeof sdk.commercialBreak === 'function') {
                sdk.commercialBreak = () => {
                    log('commercialBreak skipped');
                    METRICS.interceptedCalls++;
                    return Promise.resolve();
                };
            }

            // Rewarded ads → instant reward, no delay
            if (typeof sdk.rewardedBreak === 'function') {
                sdk.rewardedBreak = function(callbacks) {
                    log('rewardedBreak → instant reward');
                    METRICS.interceptedCalls++;

                    let onStart = null, onReward = null;
                    if (typeof callbacks === 'function') {
                        onReward = callbacks;
                    } else if (callbacks && typeof callbacks === 'object') {
                        onStart = callbacks.onStart;
                        onReward = callbacks.adFinished || callbacks.onComplete || callbacks.onReward;
                    }

                    safeCallback(onStart);
                    safeCallback(onReward);          // <── instant, no setTimeout

                    METRICS.rewardsGranted++;
                    safeDispatchEvent(window, 'rewardedComplete');
                    safeDispatchEvent(window, 'rewardGranted');
                    safeDispatchEvent(window, 'adComplete');
                    log('✅ Reward granted instantly');
                    return Promise.resolve(true);
                };
            }

            // Display ad methods
            if (typeof sdk.hoistDisplayAd === 'function') {
                sdk.hoistDisplayAd = () => { METRICS.interceptedCalls++; return false; };
            }
            if (typeof sdk.destroyDisplayAd === 'function') {
                sdk.destroyDisplayAd = () => { METRICS.interceptedCalls++; };
            }

            // Platform-specific ad breaks
            ['playgroundCommercialBreak', 'platformCommercialBreak'].forEach(m => {
                if (typeof sdk[m] === 'function') {
                    sdk[m] = () => { log(m + ' skipped'); METRICS.interceptedCalls++; return Promise.resolve(); };
                }
            });

            // Internal monetisation object (if present)
            if (sdk.__monetization) {
                if (typeof sdk.__monetization.requestAd === 'function') {
                    sdk.__monetization.requestAd = () => Promise.resolve();
                }
                if (typeof sdk.__monetization.displayAd === 'function') {
                    sdk.__monetization.displayAd = () => false;
                }
                if (typeof sdk.__monetization.init === 'function') {
                    sdk.__monetization.init = () => Promise.resolve();
                }
            }

            // Analytics (no-op)
            ['happyTime','gameLoading','gameplayStart','gameplayStop','captureError','sendEvent'].forEach(m => {
                if (typeof sdk[m] === 'function') sdk[m] = () => {};
            });

            METRICS.hooksInstalled++;
            log('✓ PokiSDK hooked instantly');
            return true;

        } catch (e) {
            error('Hook failed:', e);
            METRICS.failedHooks++;
            return false;
        }
    }

    // ═══════ IMMEDIATE TRAP (catches any late SDK assignment) ═══════
    function installTrap() {
        let _PokiSDK = window.PokiSDK;
        Object.defineProperty(window, 'PokiSDK', {
            configurable: true,
            enumerable: true,
            get() { return _PokiSDK; },
            set(newValue) {
                _PokiSDK = newValue;
                if (newValue && !newValue.__zaHooked) {
                    hookPokiSDK(newValue);
                }
            }
        });
        log('✓ PokiSDK trap installed');
    }

    // ═══════ ATTEMPT HOOK ON EXISTING SDK (rare but safe) ═══════
    function hookExistingIfPresent() {
        if (window.PokiSDK && !window.PokiSDK.__zaHooked) {
            hookPokiSDK(window.PokiSDK);
        }
    }

    // ═══════ OBSERVE DYNAMIC SCRIPT INJECTION ═══════
    function setupObserver() {
        const observer = new MutationObserver(mutations => {
            for (const mutation of mutations) {
                for (const node of mutation.addedNodes) {
                    if (node.tagName === 'SCRIPT') {
                        const src = (node.src || '').toLowerCase();
                        if (src.includes('poki') && (src.includes('sdk') || src.includes('monetization'))) {
                            log('SDK script detected:', src.substring(0, 80));
                            node.addEventListener('load', () => {
                                // small microtask just to be safe
                                setTimeout(hookExistingIfPresent, 0);
                            });
                        }
                    }
                }
            }
        });
        if (document.documentElement) {
            observer.observe(document.documentElement, { childList: true, subtree: true });
        }
        log('✓ MutationObserver active');
    }

    // ═══════ INIT ═══════
    function initialize() {
        log('ZeroAd: Poki SDK v4.0.1 – Instant reward');
        installTrap();
        hookExistingIfPresent();   // in case SDK already defined (unlikely)
        setupObserver();

        window._zaMetrics = window._zaMetrics || {};
        window._zaMetrics.poki = METRICS;

        // Status in 5s
        setTimeout(() => {
            log('Status:', { hookState: !!window.PokiSDK?.__zaHooked, metrics: METRICS });
        }, 5000);
    }

    initialize();

    // DOM ready fallback
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', hookExistingIfPresent);
    }
})();