動畫瘋 避免跳集觀看

如果點擊的集數比最後觀看的集數還要高,會自動跳轉到最後觀看的下一集。若當前集數在最後觀看集數之前,則不跳轉,若無法找到最後觀看的集數,則跳轉到第一集。

目前为 2024-08-27 提交的版本。查看 最新版本

// ==UserScript==
// @name         動畫瘋 避免跳集觀看
// @namespace    https://ani.gamer.com.tw/
// @version      1.0
// @description  如果點擊的集數比最後觀看的集數還要高,會自動跳轉到最後觀看的下一集。若當前集數在最後觀看集數之前,則不跳轉,若無法找到最後觀看的集數,則跳轉到第一集。
// @license      MIT
// @author       movwei
// @match        https://ani.gamer.com.tw/animeVideo.php?sn=*
// ==/UserScript==

(function() {
    'use strict';

    // 取得當前影片的集數編號
    let currentEpisode = window.location.search;

    // 取得所有集數列表
    let episodeList = Array.from(document.querySelectorAll('.season li a'));

    // 找到播放中的集數和已觀看的集數
    let playingElement = document.querySelector('.season .playing');
    let sawElement = document.querySelector('.season .saw');

    if (sawElement) {
        // 找到已觀看的下一集
        let nextEpisode = sawElement.nextElementSibling;

        // 取得當前集數的索引
        let currentEpisodeIndex = episodeList.findIndex(ep => ep.href.endsWith(currentEpisode));

        // 取得已觀看集數的索引
        let sawEpisodeIndex = episodeList.findIndex(ep => ep.href.endsWith(sawElement.querySelector('a').search));

        // 如果當前集數在已觀看集數之前,不跳轉
        if (currentEpisodeIndex <= sawEpisodeIndex) {
            return;
        }

        // 如果下一集存在且不是目前播放中的集數
        if (nextEpisode && !nextEpisode.classList.contains('playing')) {
            let nextEpisodeLink = nextEpisode.querySelector('a').href;
            window.location.href = nextEpisodeLink;
        }
    } else {
        // 若無最後觀看的集數,跳轉至第一集
        if (!sessionStorage.getItem('redirectedFor' + currentEpisode)) {
            let firstEpisode = document.querySelector('.season li:first-child a').href;
            sessionStorage.setItem('redirectedFor' + currentEpisode, 'true');
            window.location.href = firstEpisode;
        }
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址