// ==UserScript==
// @name 奈菲影视小猪手
// @namespace
// @version 2.7.0
// @description 功能较多并增加中,使用方法详见 https://greasyforks.org/zh-CN/scripts/403365-奈菲影视小猪手
// @author ok!
// @match https://www.nfmovies.com/*
// @grant unsafeWindow
// @run-at document-body
// @namespace
// ==/UserScript==
setTimeout(function(){if(document.querySelector("body > .hidden-xs")){document.querySelector("body > .hidden-xs").remove();}},50);
/*右上图标css
var style_type1 = document.createElement("link");
style_type1.href="/templets/default/images/css/mytheme-font.css";
style_type1.rel="stylesheet";style_type1.type="text/css";document.head.appendChild(style_type1);
*/
function getCookie(name){
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg)){return unescape(arr[2]);}
else{return null;}
}
var sec_sub;
var sec_fwd;
var wheel_sec;
var buffer_time;
var dark_mode;
var pig_hand = {
//暗夜模式
dark_eye:function (e){
if(getCookie('dark_mode')==1||e==1){
var style_type = document.createElement("style");style_type.id = "style_type";
style_type.innerHTML = `body {color:#aaa !important;background-color:#333 !important;} #header-top{background-color:#222 !important;} body div.col-md-wide-3.col-xs-1.myui-sidebar.hidden-sm.hidden-xs > div{background-color:#222 !important;}
div.myui-foot.clearfix {background-color:#222 !important;}div.myui-panel.myui-panel-bg.clearfix {background-color:#222 !important;} div.myui-panel.myui-panel-bg2.clearfix {background-color:#222 !important;}
.tab-pane.fade.clearfix .myui-content__list.sort-list.clearfix li a{box-shadow:0 5px 10px rgba(246,246,246,.25) !important;border-radius: 5px;} #playlist li a{box-shadow:0 5px 10px rgba(246,246,246,.25);border-radius: 5px;} #video {background:black !important;} #player-sidebar > div > div > div > div.text-muted > ul > li > a {background:#5bb7fe !important;color:#eee !important;border-radius: 5px !important;} .btn-gray {box-shadow:0 5px 10px rgba(246,246,246,.25) !important;}.btn-default {background-color:#222 !important;background:#222 !important;} .dropdown-box .item {background-color:#222 !important;} a {color:#aaa !important;}a:hover { font-size: 105%;color:#eee !important;} #talk div{background-color:#888 !important;} h3 {color:#aaa !important;} .myui-topbg{background-image:none !important;background-color:#333 !important;} #header-top > div.container div.item.clearfix{background-color:#333 !important;}`;
document.head.appendChild(style_type);var abcd = document.createElement("SCRIPT");var qwer1 = document.createTextNode("var adTime=0;var adsTime=0;var adsPage='';var adCount = 150;var adsPausePage='';var _ck1 = true;var inited = true;var timerAdCountdown = null");abcd.appendChild(qwer1); document.body.appendChild(abcd);if(document.querySelector('#aaaDiv'))document.querySelector('#aaaDiv').remove();
}
},
play_menu:function () {
//右上角图标明亮化
//if (!window.location.href.startsWith("https://www.nfmovies.com/detail/")){Myui.Other.Topbg($("#type-hot").outerHeight()+110);}else{Myui.Other.Topbg($(".topline").offset().top);}
//点亮正在播放那集
if(document.querySelector("#player-left > div > div.tips.close-box > ul > li:nth-child(1)")){var abc=document.querySelector("#player-left > div > div.tips.close-box > ul > li:nth-child(1)").innerText.split("-")[1];document.querySelector(`.tab-pane.fade.in.active.clearfix > ul li > a[title="${abc}"]`).style.outline="auto";}
if(document.querySelectorAll("#header-top > div.container > div > ul.myui-header__user > li:nth-child(1) > div > div > div > p")){
//播放设置菜单
var li_new = document.createElement("li");
li_new.innerHTML=`<a title="设置"><i class="fa fa-gear"></i></a><div class="dropdown-box fadeInDown"><div class="item clearfix"><p class="text-muted">播放设置</p><div class="history-list clearfix"></div><span>当前速度:</span><span id="speed_display"></span><p>选择播放速度: <button id="speed_button" style="background-color: #5bb7fe;border-radius:5px;color:white;"> 默认 1x </button></p><input type="range" min="1" max="100" value="25" class="slider" id="speed_slider"><br /><br /><p>跳过片头秒数:<input type="text" id="sec_fwd" style="width:62px;height:22px;vertical-align: middle;padding: 5px;background-color:#fff;border: 2px solid #ddd;" placeholder="空则不跳"></p><p>跳过片尾秒数:<input type="text" id="sec_sub" style="width:62px;height:22px;vertical-align: middle;padding: 5px;background-color: #fff;border: 2px solid #ddd;" placeholder="空则不播"></p><p>鼠标滚动秒数:<input type="text" id="wheel_sec" style="width:62px;height:22px;vertical-align: middle;padding: 5px;background-color: #fff;border: 2px solid #ddd;" placeholder="空则不动"></p><p>暂停缓存秒数:<input type="text" id="buffer_time" style="width:62px;height:22px;vertical-align: middle;padding: 5px;background-color: #fff;border: 2px solid #ddd;" placeholder="空则不缓"></p><br /><p>暗夜模式 : <input id="dark_mode" class="switch switch-anim" type="checkbox" checked></p></div></div>
<style>.switch { width: 42px; height: 20px; position: relative; border: 1px solid #dfdfdf; background-color: #fdfdfd; box-shadow: #dfdfdf 0 0 0 0 inset; border-radius: 20px; background-clip: content-box; display: inline-block; -webkit-appearance: none; user-select: none; outline: none; } .switch:before { content: ''; width: 20px; height: 20px; position: absolute; top: 0; left: 0; border-radius: 14px; background-color: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); } .switch:checked { border-color: #5bb7fe; box-shadow: #5bb7fe 0 0 0 16px inset; background-color: #5bb7fe; } .switch:checked:before { left: 20px; } .switch.switch-anim { transition: border cubic-bezier(0, 0, 0, 1) 0.4s, box-shadow cubic-bezier(0, 0, 0, 1) 0.4s; } .switch.switch-anim:before { transition: left 0.3s; } .switch.switch-anim:checked { box-shadow: #5bb7fe 0 0 0 16px inset; background-color: #5bb7fe; transition: border ease 0.4s, box-shadow ease 0.4s, background-color ease 1.2s; } .switch.switch-anim:checked:before { transition: left 0.3s; }
.text-red {color: #aaa;}
</style>`;//开关动画有借鉴:原文链接:https://blog.csdn.net/qq_35909852/java/article/details/79079815
li_new.classList.add('dropdown-hover');
document.querySelector("#header-top > div.container > div > ul.myui-header__user").appendChild(li_new);
//显示历史记录
/* (function(){
var history_get = MyTheme.Cookie.Get("history"),html='';
if (history_get) {
var json = eval("(" + history_get + ")");
for (i = 0; i < json.length; i++) {
html+="<p><a class='text-333' href='" + json[i].link + "' title='" + json[i].name +"'><span class='pull-right text-red'>" + json[i].part + "</span>" + json[i].name + "</a></p>";
}
} else {
html="<p style='padding: 80px 0; text-align: center'>您还没有看过影片哦</p>";
}
document.querySelector('.history-list').innerHTML=html})();
*/
//删除选定历史播放记录
var p_add = document.querySelectorAll("#header-top > div.container > div > ul.myui-header__user > li:nth-child(1) > div > div > div > p");
for(var i = 0;i<p_add.length;i++){
var a_elem = document.createElement("a");
a_elem.innerHTML= ' <span style="color:#ccc !important;background-color: #5bb7fe;border-radius:5px;font-size:70%;"> -删 除-   </span>';
p_add[i].appendChild(a_elem);
p_add[i].lastChild.addEventListener('click',change_cookie)};
function change_cookie(e){
var str_del = e.target.parentElement.parentElement.firstElementChild.title;
console.log(str_del);
var reg_exp =new RegExp(`{\"name\":\"${str_del}[^}]*},?`);
var xyza= encodeURIComponent(decodeURIComponent(document.cookie.replace(/(?:(?:^|.*;\s*)history\s*\=\s*([^;]*).*$)|^.*$/, "$1")).replace(reg_exp,''));
var exp = new Date();
exp.setTime(exp.getTime() + 365 * 24 * 60 * 60 * 1000);
document.cookie=`history=${xyza}; path=/; expires=${exp.toUTCString()}`;
e.target.parentElement.parentElement.remove();
}
//播放设置
var speed_display=document.getElementById("speed_display"),speed_slider=document.getElementById("speed_slider"),speed_button=document.getElementById("speed_button"),
y=document.getElementById("sec_sub"),z=document.getElementById("wheel_sec"),x=document.getElementById("buffer_time"),w=document.getElementById("dark_mode"),v=document.getElementById("sec_fwd");
var video_speed;dark_mode = getCookie('dark_mode');
video_speed = MyTheme.Cookie.Get('speed');sec_fwd = MyTheme.Cookie.Get('sec_fwd');sec_sub = MyTheme.Cookie.Get('sec_sub');wheel_sec = MyTheme.Cookie.Get('wheel_sec');buffer_time = MyTheme.Cookie.Get('buffer_time');
video_speed?speed_display.innerHTML=video_speed+"x":speed_display.innerHTML="1x";
setTimeout(function (){if(video_speed&&document.querySelector('#cciframe'))
document.querySelector('iframe').contentDocument.body.querySelector("#video > div.dplayer-video-wrap > video").playbackRate = video_speed;},4000);
speed_slider.oninput=function(){MyTheme.Cookie.Set('speed',this.value/25);video_speed = MyTheme.Cookie.Get('speed');video_speed?speed_display.innerHTML=video_speed+"x":speed_display.innerHTML="1x";
document.querySelector('iframe').contentDocument.body.querySelector("#video > div.dplayer-video-wrap > video").playbackRate = video_speed;
}
speed_button.onclick=function(){MyTheme.Cookie.Set('speed',1);video_speed = MyTheme.Cookie.Get('speed');video_speed?speed_display.innerHTML=video_speed+"x":speed_display.innerHTML="1x";
document.querySelector('iframe').contentDocument.body.querySelector("#video > div.dplayer-video-wrap > video").playbackRate = video_speed;}
sec_fwd?v.value=sec_fwd:v.value="";
v.onchange=function(){MyTheme.Cookie.Set('sec_fwd',this.value);sec_fwd = MyTheme.Cookie.Get('sec_fwd');sec_fwd?v.value=sec_fwd:v.value="";
}
sec_sub?y.value=sec_sub:y.value="";
y.onchange=function(){MyTheme.Cookie.Set('sec_sub',this.value);sec_sub = MyTheme.Cookie.Get('sec_sub');sec_sub?y.value=sec_sub:y.value="";
}
wheel_sec?z.value=wheel_sec:z.value="";
z.onchange=function(){MyTheme.Cookie.Set('wheel_sec',this.value);wheel_sec = MyTheme.Cookie.Get('wheel_sec');wheel_sec?z.value=wheel_sec:z.value="";
}
buffer_time?x.value=buffer_time:x.value="";
x.onchange=function(){MyTheme.Cookie.Set('buffer_time',this.value);buffer_time = MyTheme.Cookie.Get('buffer_time');buffer_time?x.value=buffer_time:x.value="";
}
w.checded=dark_mode; if(dark_mode!=1){document.getElementById("dark_mode").removeAttribute('checked');}
w.onchange=function(){if(w.checked){MyTheme.Cookie.Set('dark_mode',1);dark_eye();}else{MyTheme.Cookie.Set('dark_mode',0);document.querySelector('#style_type').remove();}
dark_mode = MyTheme.Cookie.Get('dark_mode');
}
}
},
iframe_video:function(){
//视频自动全屏
if(document.querySelector('#cciframe')){
var v_elem1;
function toggleFullscreen() {
if (!document.fullscreenElement) {
if(v_elem1.requestFullscreen){
return v_elem1.requestFullscreen();
}else if(v_elem1.webkitRequestFullScreen){
return v_elem1.webkitRequestFullScreen();
}else if(v_elem1.mozRequestFullScreen){
return v_elem1.mozRequestFullScreen();
}else{
return v_elem1.msRequestFullscreen();
}
// v_elem.requestFullscreen().catch(err => { console.log(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`);});
}
}
var fullscreen_req = setInterval(function () {
v_elem1 =document.querySelector('#cciframe').contentDocument.body.querySelector('#video');
if (document.querySelector('#cciframe').contentDocument.body.querySelector("#video > div.dplayer-video-wrap > video")) {
toggleFullscreen();clearInterval(fullscreen_req);
}
},4000);
}
//3秒后主程序
setTimeout(function(){
if(!document.querySelector('#cciframe')){location.reload();}
else{
play_main();
function play_main(){
sec_fwd = MyTheme.Cookie.Get('sec_fwd');
sec_sub = MyTheme.Cookie.Get('sec_sub');
wheel_sec = MyTheme.Cookie.Get('wheel_sec');
buffer_time = MyTheme.Cookie.Get('buffer_time');
var video_speed = MyTheme.Cookie.Get('speed');
var video_elem,v_elem;
//每3秒试执行主应用操作
var main_timer = setInterval(function () {
video_elem = document.querySelector('#cciframe').contentDocument.body.querySelector("#video > div.dplayer-video-wrap > video");
v_elem =document.querySelector('#cciframe').contentDocument.body.querySelector('#video');
if (video_elem){
main_opr();clearInterval(main_timer);}
},3000)
//主应用操作
function main_opr() {
if(video_speed&&video_elem){video_elem.playbackRate = video_speed;}
//前跳过秒数
video_elem.oncanplay = function(){
if(video_elem.currentTime < 20){
video_elem.currentTime += sec_fwd/1;
video_elem.oncanplay = "";
}
}
video_elem.currentTime += 1;
var current_time,current_timeM;
video_elem.onpause = function(){
buffer_time=MyTheme.Cookie.Get('buffer_time');
current_time = video_elem.currentTime;
current_timeM=current_time>=3600?(Math.floor(current_time/3600)+" : "+Math.floor(current_time/60-60)+" : "+Math.floor(current_time%60)):(Math.floor(current_time/60)+" : "+Math.floor(current_time%60));
document.querySelector('#cciframe').contentDocument.body.querySelector("#video > div.dplayer-info-panel.dplayer-info-panel-hide").className='dplayer-info-panel dplayer-info-panel-show';
document.querySelector('#cciframe').contentDocument.body.querySelector("#video > div.dplayer-info-panel div.dplayer-info-panel-item.dplayer-info-panel-item-resolution > span.dplayer-info-panel-item-data").innerHTML = video_elem.videoWidth+'x'+video_elem.videoHeight;
document.querySelector('#cciframe').contentDocument.body.querySelector("#video > div.dplayer-info-panel div.dplayer-info-panel-item.dplayer-info-panel-item-version > span.dplayer-info-panel-item-data").innerHTML = "DPlayer v1.25.0 fdcf45b";
document.querySelector('#cciframe').contentDocument.body.querySelector("#video > div.dplayer-info-panel div.dplayer-info-panel-item.dplayer-info-panel-item-duration > span.dplayer-info-panel-item-title").innerHTML = '当前暂停时间';
document.querySelector('#cciframe').contentDocument.body.querySelector("#video > div.dplayer-info-panel div.dplayer-info-panel-item.dplayer-info-panel-item-duration > span.dplayer-info-panel-item-data").innerHTML = current_timeM;
video_elem.oncanplaythrough = function(){
video_elem.currentTime += 1;
if(video_elem.currentTime-current_time>=(buffer_time?buffer_time:0)||(video_elem.duration<(video_elem.currentTime+30))){video_elem.currentTime = current_time;
video_elem.oncanplaythrough='';}
}
video_elem.currentTime += 1;
}
video_elem.onplay = function(){
video_elem.currentTime = current_time;
document.querySelector('#cciframe').contentDocument.body.querySelector("#video > div.dplayer-info-panel.dplayer-info-panel-show").className='dplayer-info-panel dplayer-info-panel-hide';
document.querySelector('#cciframe').contentDocument.body.querySelector("#video > div.dplayer-info-panel div.dplayer-info-panel-item.dplayer-info-panel-item-resolution > span.dplayer-info-panel-item-data").innerHTML="";
document.querySelector('#cciframe').contentDocument.body.querySelector("#video > div.dplayer-video-wrap > video").oncanplaythrough = "";
}
// 在视频框内按键ctrl或鼠标右键,直接跳到下一集
document.querySelector('#cciframe').contentDocument.body.addEventListener("keydown", function(e) {
if (e.keyCode == 17) {
e.preventDefault();
next_exec();
}
}, false);
document.querySelector('#cciframe').contentDocument.body.querySelector('#video').addEventListener("contextmenu", function(e) {
e.preventDefault();
next_exec();
}, false);
// 滚轮前进后退
video_elem.onwheel = function(e){e.preventDefault()};
v_elem.onwheel = wheel_e;
function wheel_e (event) {
event.preventDefault();
//console.log(event.deltaY);
// event.deltaY = Math.min(Math.max(.125,event.deltaY), 4);
//console.log(wheel_sec);
video_elem.currentTime += (event.deltaY>0?wheel_sec/1:-wheel_sec) ;
v_elem.onwheel="";
setTimeout(function(){v_elem.onwheel= wheel_e;},300);
}
// 去右上角logo
let logo;
if(logo = document.querySelector('#cciframe').contentDocument.body.querySelector("#video > div.dplayer-video-wrap > div.dplayer-logo"))
{logo.innerHTML="";
}
}
//每隔25秒获取播放剩余时间,如在25秒内则执行主程序
if(sec_sub !== ""){
const sec_sub2=sec_sub/1+12;
setInterval(function(){
let duration = get_dura(),sel_part = document.querySelector("#player-left > ul > li:nth-child(7) > a");
if((duration < sec_sub2) && (duration !== 0) && sel_part)
{
const sec = (duration-sec_sub)*1000;
if (sec !== 0) {
setTimeout(next_exec, sec);
}
// clearInterval(auto_play);
}
}, 12000);
}
//next part 执行
function next_exec(){
const sel_part2 = document.querySelector("#player-left > ul > li:nth-child(7) > a");
if (sel_part2 != null)
{sel_part2.click();}
}
/* function next_exec(){
if(next === now){
const sel_part2 = document.querySelector("#player-left > ul > li:nth-child(7) > a");
if (sel_part2 != null)
{sel_part2.click();}
}
else if(next !== ""){now = next;
const iframe_fresh2 = document.querySelector('iframe');
iframe_fresh2.src = iframe_fresh2.src;
}
}
*/
//获取播放剩余时间
function get_dura() {
const sel_start = document.querySelector('#cciframe').contentDocument.body.querySelector("#video > div.dplayer-video-wrap > video").currentTime;
const sel_fin = document.querySelector('#cciframe').contentDocument.body.querySelector("#video > div.dplayer-video-wrap > video").duration;
if (sel_fin !== null) {
return sel_fin-sel_start;
}
return 0;
}
}
}
},3000)
},
anti_win:function(){
var main_script = document.createElement("script");
main_script.innerHTML = "var $myui = function(e){console.log(e)};";document.body.appendChild(main_script);
}
}
pig_hand.dark_eye();
pig_hand.anti_win();
if (!window.location.href.startsWith("https://www.nfmovies.com/js/player/")){
window.onload = pig_hand.play_menu;}
if (window.location.href.startsWith("https://www.nfmovies.com/video/")){
pig_hand.iframe_video();
}