// ==UserScript== // @name age动漫视频播放器扩展 // @namespace http://tampermonkey.net/ // @version 0.6 // @description 替换原有播放器,新增:自上次观看位置继续播放,播放结束自动跳转下一集 // @author 林狗dan // @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 // @downloadURL none // ==/UserScript== (function() { 'use strict'; review_history() if(location.href.indexOf('acg') != -1) handle_video(); })(); function review_history(){ let history_view = document.querySelector("body > div.topall > div > ul.ls > li > div") history_view.style.width = '400px' } function handle_video(){ //获取动漫的目录列表元素 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 } } */ } if(location.href.indexOf('html') == -1) return //use JSON.parse throw erro // let HISTORY = eval("(" + Cookies.get('HISTORY') + ")"); // HISTORY.video[0].link = location.href // Cookies.set('HISTORY',JSON.stringify( HISTORY)) 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) */ };