OpEx Countdown Skip

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

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

  1. // ==UserScript==
  2. // @name OpEx Countdown Skip
  3. // @name:pt-BR OpEx Pula Tempo de Espera
  4. // @autor SecretX
  5. // @namespace namespace_secretx
  6. // @description A small script to skip the silly countdown of One Piece Ex website
  7. // @description:pt-br Um pequeno script para pular o contador irritante do site OpEx
  8. // @version 2022.03.12
  9. // @match *://onepieceex.net/download/?*
  10. // @grant none
  11. // @icon https://onepieceex.net/favicon/favicon-32x32.png
  12. // @license GNU LGPLv3
  13. // ==/UserScript==
  14.  
  15. Object.defineProperty(Array.prototype, "firstNotNull", {
  16. value: function firstNotNull() {
  17. for (const element of this) if (element != null) return element;
  18. throw new Error("Array contains no non null element.");
  19. },
  20. writable: true,
  21. configurable: true
  22. });
  23.  
  24. function fallback() {
  25. // if everything else fails, at least set the countdown to 1
  26. countElem().innerHTML = 1;
  27. }
  28.  
  29. const countElem = () => document.getElementById('contador');
  30.  
  31. const countdownScript = () => document.querySelector("body > script:nth-child(4)").innerText;
  32.  
  33. function firstScriptLineThatMatches(regex) {
  34. return countdownScript().split("\n")
  35. .map(line => line.trim().match(regex))
  36. .firstNotNull();
  37. }
  38.  
  39. function haltCountdown() {
  40. try {
  41. countElem().remove();
  42. } catch (e) {}
  43. }
  44.  
  45. window.addEventListener("DOMContentLoaded", function() {
  46. 'use strict';
  47.  
  48. const magnetLinkRegex = /^.+?href="(magnet[^"]+)".*$/i;
  49.  
  50. try {
  51. const magnetLink = firstScriptLineThatMatches(magnetLinkRegex)[1];
  52. console.info(`Automatically redirecting you to the extracted magnet link from this page: ${magnetLink}`);
  53. haltCountdown();
  54. window.location.replace(magnetLink);
  55. } catch (e) {
  56. 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}`);
  57. fallback();
  58. }
  59. }, false);