netfix

skip presser, mute/hide ads. (red green logo shows script is active)

目前為 2023-10-30 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           netfix
// @version        2.3.2
// @namespace      https:\\derben.ca
// @author         DerBen
/// @license        Public Domain
// @description    skip presser, mute/hide ads. (red green logo shows script is active)
// @run-at         document-end
// @include        https://www.netflix.com/*
// @include        https://www.crave.ca/en/tv-shows/*
// @include        https://www.youtube.com/watch*
// @grant          none
// ==/UserScript==
'use strict';

//console.log('netfix startup');

// ** Sometimes these sites unload this script, just press reload **
// ** no longer have crave access, cannot test.

// edit these if needed
var admut=1; // mute ads
var adblk=0; // hide ads, experimental
setInterval(looper, 2000); //check interval
var nfb=["skip-recap","skip-intro","continue"]; // netflix buttons
var nf=['ltr-yo6l9w','ad-count']; // netflix data
var yt=['ytp-ad-preview-image','ytp-ad-skip-button',"[aria-label^='No thanks']"]; // youtube ad data
var cr=['bm-view-skipbreaks1',"div[class='skipbreaks-click-area']"]; // crave ads data

// Don't edit below!
var host=location.hostname;
var vt=1,at=1; // video audio toggles
var sk=0,skip=0; //skip timing variables
var texb = document.createElement('div');
 texb.id='cgwin';
 texb.style.top='0px';
 texb.style.left='0px';
 texb.style.position='fixed';
 texb.style.background='black';
 texb.style.border='green 2px solid';
 texb.style.borderRadius='25px';
 texb.style.font='12px arial';
 texb.style.zIndex='99999';
 texb.innerHTML='netfix';


function looper(){
 //console.log('loop');
 var nflogo=document.getElementById('cgwin');
 if (typeof(nflogo) === 'undefined' || nflogo==null) {
  try { document.body.appendChild(texb); }
  catch(error){ console.log('netfix no append');}
 } else {
  nflogo.style.border= Math.floor(Math.random() * 2) ? 'green 2px solid' :  'red 2px solid';
 }
 
 if (skip>0) {
  skip--; sk=1;
  //console.log('skip');
  return;
 }
  
 if (host=='www.crave.ca') { crave(); }
 if (host=='www.youtube.com') { youtube(); }
 if (host=='www.netflix.com') { netflix(); }
}

function clkd(clkhere,typ=0){
 event = document.createEvent('HTMLEvents');
 event.initEvent('click', true, false);
 if (typ==0){
  document.querySelector(clkhere).dispatchEvent(event);
 } else {
  clkhere.dispatchEvent(event);
 }
 return;
}


function netflix(){
 //console.log('netflix funct');
 var mute=0;
 var pin=document.getElementsByClassName(nf[0]);
 if (pin.length){ mute=1; }
 var pin=document.getElementsByClassName(nf[1]);
 if (pin.length){ mute=1; }
 
 if (location.pathname.includes("watch")){
  if (mute==1){
    if (admut && !at){
     document.getElementsByTagName("video")[0].muted=true;
     at=1;
    }
    if (adblk && !vt){
     document.getElementsByTagName("video")[0].hidden=true
     vt=1;
    }
  } else {
   if (admut && at){
    document.getElementsByTagName("video")[0].muted=false;
    at=0;
   }
   if (adblk && vt){
    document.getElementsByTagName("video")[0].hidden=false
    vt=0;
   }
  }
 }

 var butt=document.getElementsByTagName('button');
 for(var i=0;i<butt.length;i++) {
  //console.log(i, butt[i].dataset);
  for(var ii=0;ii<nfb.length;ii++) {
   var regex = new RegExp(nfb[ii], "g");
   //console.log(nf[ii])
   if (regex.test(butt[i].dataset.uia)){
    skip=5;
   }
  }
  if (skip>=4) {
   //console.log('skipping');
   clkd(butt[i],2);
   break;
  }
 }
}


function crave(){
 //console.log('crave funct');
 var crsk=document.getElementById(cr[0]);
 if (typeof(crsk) === 'undefined' || crsk==null) {
  //console.log('no vid');
 } else {
  //console.log('vid'+crsk.style.display);
  if (crsk.style.display=='block'){
   console.log('CR skip');
   clkd(cr[1]);
  }
 }
}

function youtube(){
 //console.log('YT check!');
 const pop=document.querySelectorAll(yt[2]); // popup
 if (typeof(pop[0]) !== 'undefined') {
  //console.log('YT popped!');
  pop[0].click();
 }
 //console.log('youtube funct');
 const vid=document.getElementsByTagName("video");

 var crsk=document.getElementsByClassName(yt[0]); // non skip ad playing
 if (typeof(crsk[0]) === 'undefined' || crsk==null) {
  //console.log('YT unmuted');
  if (admut && vid[0].muted!=false) { vid[0].muted=false; }
 } else {
  console.log('YT muted!');
  if (admut && vid[0].muted==false) { vid[0].muted=true; }
 }
 
 var crsk=document.getElementsByClassName(yt[1]); //skip button shown
 //console.log('c',crsk[0]);
 if (typeof(crsk[0]) === 'undefined' || crsk==null) {
  //console.log('no skip');
 } else {
  //console.log('YT skip');
  clkd(crsk[0],1);
 }
}