AniPlusPlus

Auto-skip the loading screen on any AniPlus episode page

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         AniPlusPlus
// @namespace    https://aniplus.co
// @version      1.0.0
// @license      MIT
// @description  Auto-skip the loading screen on any AniPlus episode page
// @match        https://aniplus.co/*
// @match        http://aniplus.co/*
// @run-at       document-idle
// @grant        none
// ==/UserScript==
 
(function () {
  'use strict';
 
  const LOG = '[AniPlus Skip]';
  const GLOBAL_KEY = '__aniplusSkip';
 
  function skipLoadingAd() {
    const el = document.querySelector('[class*="ad-window"]');
    if (!el) return false;
 
    const fiberKey = Object.keys(el).find((k) => k.startsWith('__reactFiber'));
    if (!fiberKey) return false;
 
    let fiber = el[fiberKey];
    while (fiber) {
      const onFinish = fiber.memoizedProps?.onFinish;
      if (fiber.type?.name === 'y' && typeof onFinish === 'function') {
        onFinish();
        console.log(LOG, 'Loading timer skipped on', location.pathname);
        return true;
      }
      fiber = fiber.return;
    }
 
    return false;
  }
 
  function stopWatching(state) {
    if (state.observer) state.observer.disconnect();
    if (state.interval) clearInterval(state.interval);
    if (state.timeout) clearTimeout(state.timeout);
    state.observer = null;
    state.interval = null;
    state.timeout = null;
  }
 
  function watchForLoadingAd() {
    const state = window[GLOBAL_KEY] || (window[GLOBAL_KEY] = {});
    stopWatching(state);
 
    if (skipLoadingAd()) return;
 
    state.observer = new MutationObserver(() => {
      if (skipLoadingAd()) stopWatching(state);
    });
 
    state.observer.observe(document.documentElement, {
      childList: true,
      subtree: true,
    });
 
    state.interval = setInterval(() => {
      if (skipLoadingAd()) stopWatching(state);
    }, 50);
 
    state.timeout = setTimeout(() => stopWatching(state), 30000);
  }
 
  function installHistoryHooks() {
    const state = window[GLOBAL_KEY] || (window[GLOBAL_KEY] = {});
    if (state.historyHooked) return;
    state.historyHooked = true;
 
    const rerun = () => setTimeout(watchForLoadingAd, 0);
 
    const wrap = (original) =>
      function () {
        const result = original.apply(this, arguments);
        rerun();
        return result;
      };
 
    history.pushState = wrap(history.pushState);
    history.replaceState = wrap(history.replaceState);
    window.addEventListener('popstate', rerun);
  }
 
  installHistoryHooks();
  watchForLoadingAd();
})();