Prime Video Ad Blocker [ESP]

Skips ads and promos on Prime Video.

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            Prime Video Ad Blocker [ESP]
// @name:es         Prime Video Ad Blocker [ESP]
// @namespace       https://greasyfork.org/en/users/5102-jeau
// @version         0.4.1
// @description     Skips ads and promos on Prime Video.
// @description:es  Bloquea los anuncios y promociones en Prime Video.
// @author          Jeau
// @license         MIT
// @match           https://*.amazon.com/*/video/*
// @match           https://*.amazon.co.uk/*/video/*
// @match           https://*.amazon.de/*/video/*
// @match           https://*.amazon.co.jp/*/video/*
// @match           https://*.primevideo.com/*
// @icon            https://m.media-amazon.com/images/G/01/digital/video/DVUI/favicons/favicon-32x32.png
// @grant           none
// ==/UserScript==

/*
-----------------------------------------------------------------------------------
  Adapted for Amazon Prime Video Spain. It might also work in other countries.
  Based on RawMeatEater's script:
  https://greasyfork.org/es/scripts/446723-amazon-video-ad-blocker
-----------------------------------------------------------------------------------
*/

(function() {
    'use strict';

    // Track if current ad block has been skipped
    let adSkipped = false;
    const adTimeRegExp = /(\d?\d:){0,2}\d?\d/;

    setInterval(() => {
        // Target the video element inside the latest injected surface container
        const lastSurface = Array.from(document.querySelectorAll(".atvwebplayersdk-video-surface")).pop();
        const video = lastSurface ? lastSurface.querySelector('video') : null;

        const adEl = document.querySelector(".atvwebplayersdk-ad-timer-remaining-time");

        // Execute skip logic if video is playing, ad timer is found, and ad hasn't been skipped yet
        if (video && video.currentTime && adEl && !adSkipped) {
            const match = adEl.textContent.match(adTimeRegExp);
            if (match) {
                // Parse time components directly into seconds using unary operator (+)
                const secs = match[0].split(':').reduce((accumulator, time) => (accumulator * 60) + (+time), 0);
                video.currentTime += secs;
                adSkipped = true;

                // DEBUG
                console.log([
                    '==========================',
                    'PRIME VIDEO AD SKIPPED !!!',
                    `Skipped: ${secs} seconds.`,
                    '=========================='
                ].join('\n'));
            }
        } else if (!adEl) {
            // Reset state only when the ad element completely disappears from the DOM
            adSkipped = false;
        }
    }, 200);

})();