OpEx Countdown Skip

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

当前为 2022-03-12 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

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