OpEx Countdown Skip

A small script to skip the silly countdown of One Piece Ex website

Fra og med 12.03.2022. Se den nyeste version.

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        OpEx Countdown Skip
// @name:pt-BR  OpEx Pula Tempo de Espera
// @autor       SecretX
// @namespace   secretx_scripts
// @description A small script to skip the silly countdown of One Piece Ex website
// @description:pt-br Um pequeno script para pular o contador irritante do site OpEx
// @version     2022.03.12
// @match       *://onepieceex.net/download/?*
// @grant       none
// @icon        https://onepieceex.net/favicon/favicon-32x32.png
// @license     GNU LGPLv3
// ==/UserScript==

Object.defineProperty(Array.prototype, "firstNotNull", {
    value: function firstNotNull() {
        for (const element of this) if (element != null) return element;
        throw new Error("Array contains no non null element.");
    },
    writable: true,
    configurable: true
});

function fallback() {
    // if everything else fails, at least set the countdown to 1
    countElem().innerHTML = 1;
}

const countElem = () => document.getElementById('contador');

const countdownScript = () => document.querySelector("body > script:nth-child(4)").innerText;

function firstScriptLineThatMatches(regex) {
    return countdownScript().split("\n")
        .map(line => line.trim().match(regex))
        .firstNotNull();
}

function haltCountdown() {
    try {
        countElem().remove();
    } catch (e) {}
}

window.addEventListener("DOMContentLoaded", function() {
    'use strict';

    const magnetLinkRegex = /^.+?href="(magnet[^"]+)".*$/i;

    try {
        const magnetLink = firstScriptLineThatMatches(magnetLinkRegex)[1];
        console.info(`Automatically redirecting you to the extracted magnet link from this page: ${magnetLink}`);
        haltCountdown();
        window.location.replace(magnetLink);
    } catch (e) {
        console.error(`Oops, this script was not able to automatically grab the magnet link from this page because of an error. Using fallback that set the countdown to 1. ${e}`);
        fallback();
    }
}, false);