Greasy Fork

Greasy Fork is available in English.

age动漫视频播放器扩展

替换原有播放器,新增:自上次观看位置继续播放,播放结束自动跳转下一集,播放历史跳转到具体集数。后续考虑扩展到其他视频网站:检测iframe和video标签进行替换

当前为 2021-08-27 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         age动漫视频播放器扩展
// @namespace    http://tampermonkey.net/
// @version      0.8
// @description  替换原有播放器,新增:自上次观看位置继续播放,播放结束自动跳转下一集,播放历史跳转到具体集数。后续考虑扩展到其他视频网站:检测iframe和video标签进行替换
// @author       林抱瓜
// @match        http://www.agefans.top/*
// @icon         https://www.google.com/s2/favicons?domain=agefans.top
// @grant        none
// @require https://cdn.bootcdn.net/ajax/libs/dplayer/1.25.0/DPlayer.min.js
// @require https://cdn.bootcdn.net/ajax/libs/js-cookie/latest/js.cookie.min.js

// @run-at document-end
// ==/UserScript==

(function() {
    'use strict';
    review_history()
    if(location.href.indexOf('acg') != -1){
        handle_cata();
    }
    if(location.href.indexOf('.html') != -1){
        set_history();
        handle_video();
    }

})();
function review_history(){
    let history_view = document.querySelector("body > div.topall > div > ul.ls > li > div")
    history_view.style.width = '400px'
    //历史记录更改到具体集数
    let btn = document.querySelector("body > div.topall > div > ul.ls > li > a")
    btn.onmouseover = function(){
        //每次会重新从cookie中加载,所以这里重新定义事件
        let his = document.querySelector("body > div.topall > div > ul.ls > li > div")
        his.style.display = 'block'
    }
    let video_history = document.querySelectorAll("#mh-ul > ul > li > a")
    for(let i=0; i< video_history.length; i++){
        let item = video_history[i]

        let super_url_start = item.href.lastIndexOf('acg')
        let super_url_end = item.href.lastIndexOf('/')
        let super_url = item.href.slice(super_url_start, super_url_end)

        let now_url = localStorage.getItem(super_url)
        if(now_url)
            item.href = now_url
    }

}
function set_history(){
    let super_url_start = location.href.lastIndexOf('acg')
    let super_url_end = location.href.lastIndexOf('/')
    let super_url = location.href.slice(super_url_start, super_url_end)
    localStorage.setItem(super_url,location.href)
}
function handle_cata(){
    //获取动漫的目录列表元素
    let list = document.querySelectorAll("#stab_1_71  ul > li > a");

    /*     //修改播放历史,记录当前播放集
    let cookie = document.cookie

        console.log(typeof( HISTORY));
    let super_url_index = location.href.lastIndexOf('/')
    let super_url = location.href.slice(0, super_url_index)
    let start_index = cookie.indexOf(super_url)
    console.log(start_index)
    let end_index = cookie.indexOf('\"',start_index)
    let now_cookie = cookie.slice(0,start_index) + location.href + cookie.slice(end_index)
    document.cookie = now_cookie
    console.log(document.cookie); */

    for(let i=0; i< list.length; i++){
        let text = list[i].innerText;
        let url = list[i].href;
        let now_time = localStorage.getItem(url)
        if(now_time)
            list[i].innerText = text + '(已看' + Math.round( now_time/60) + '分钟)'

        /*         //去除全部备用
        if(text.indexOf('备用')!=-1){
            list.splice(i,1);
            continue
        } */
        //点击时存储到历史记录
        /*         list[i].onclick = function(){
            let start_index = cookie.indexOf(super_url)
            console.log(start_index)
            if(start_index != -1){
                let end_index = cookie.indexOf('\"',start_index)
                let now_cookie = cookie.slice(0,start_index) + url + cookie.slice(end_index)
                document.cookie = now_cookie
            }
        } */
    }
}
function handle_video(){
    //获取动漫的目录列表元素
    let list = document.querySelectorAll("#stab_1_71  ul > li > a");

    let test = document.querySelector("#playiframe")
    console.log(test)
    let video_src = decodeURIComponent(test.src)
    let start = video_src.search('vid=') + 4
    let end = video_src.indexOf('&')
    let src = video_src.slice(start,end)
    console.log(src)
    /*     if(src.indexOf('.mp4') == -1){
        return
    } */

    //注入video标签

    //引入script及css       1.9.1的最新版有问题,不断跳出错误
    /*     let script = document.createElement('script');
    script.setAttribute('type', 'text/javascript');
    script.src = "https://cdn.bootcdn.net/ajax/libs/dplayer/1.25.0/DPlayer.min.js";
    document.documentElement.appendChild(script); */

    let link = document.createElement('link');
    link.setAttribute('rel', 'stylesheet');
    link.setAttribute('type', 'text/css');
    link.href = "https://cdn.bootcdn.net/ajax/libs/dplayer/1.25.0/DPlayer.min.css";
    document.documentElement.appendChild(link);

    let video_ele = document.createElement('div')
    video_ele.style.height = '100%'
    video_ele.style.width = 'auto'
    video_ele.id = 'lin_player'

    //视频播放器
    let player = document.querySelector("#player")
    player.appendChild(video_ele)
    test.remove()

    //注入播放器
    let dp = new DPlayer({
        container: document.getElementById('lin_player'),
        autoplay: true,
        video: {
            url: src,
        },
    });
    //跳转到历史位置
    let to_time = localStorage.getItem(location.href)
    dp.seek(to_time)

    //播放结束后自动下一个
    dp.on("ended",() => {
        console.log('video end')
        let index;
        for(let i=0; i< list.length; i++){
            //定位当前正在播放的是哪一个
            if(location.href == list[i].href){
                index = i;
                break;
            }
        }
        if(index<1){
            return;
        }

        dp.notice('即将播放下一集',3000)
        //倒计时
        let timeout = setTimeout(function(){
            clearTimeout(timeout)
            list[index--].click()
            //             location.assign(list[index-1].href)
        },3000)

        })

    //记录播放进度
    dp.on("timeupdate", () => {
        let current = dp.video.currentTime
        //         console.log(current,location.href)
        localStorage.setItem(location.href,current)
    })
    /*     setInterval(function(){
        let current = dp.video.currentTime
        console.log(current,location.href)
        localStorage.setItem(location.href,current)
    }, 5000) */

};