Autoskip Prime Trailers

3/5/2021, 11:13:26 PM

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Autoskip Prime Trailers
// @namespace   Violentmonkey Scripts
// @match       https://addons.mozilla.org/en-US/firefox/addon/violentmonkey/
// @grant       none
// @version     1.3
// @author      -
// @description 3/5/2021, 11:13:26 PM
// @match       https://www.amazon.com/gp/product/*
// @match       https://www.amazon.com/gp/video/*
// ==/UserScript==

const INTERVAL_MAX_ATTEMPTS = 120; // When triggered, the seekSkipButton method will run a maximum of 120 times before stopping 
const INTERVAL_WAIT_DURATION = 500; // when triggered, the seekSkipButton method will wait half a second in between each execution

let skipButtonInterval;
let intervalCurrentAttempts = 0;

let seekSkipButton = function() {
  intervalCurrentAttempts++;
  let xpath = "//div[text()='Skip']";
  let skipButton = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE, null).singleNodeValue;
  if (skipButton != null) {
    console.log("Skipping the ad lol.");
    skipButton.click();
    clearInterval(skipButtonInterval);
  }
  if (intervalCurrentAttempts >= INTERVAL_MAX_ATTEMPTS) {
    clearInterval(skipButtonInterval);
  }
}

const observer = new MutationObserver(function(mutationList) {
  console.log("mutations have been observed");
  for (let mutation of mutationList) {
    if (mutation.addedNodes.length == 0) {
      return;
    }
    for (let elem in mutation.addedNodes) {
      if (elem instanceof HTMLElement && elem.classList.contains("webPlayerUIContainer")) {
        intervalCurrentAttempts = 0;
        skipButtonInterval = setInterval(seekSkipButton, 500);
        return;
      }
    }
  }
});

console.log("We are listening");
observer.observe(document, {childList: true, subtree: true});