Skip to content

Instantly share code, notes, and snippets.

@sefacan
Forked from tarikguney/userscript.js
Created January 6, 2022 21:30
Show Gist options
  • Save sefacan/11303ee3acfbec894f936b2b9fe3f83a to your computer and use it in GitHub Desktop.
Save sefacan/11303ee3acfbec894f936b2b9fe3f83a to your computer and use it in GitHub Desktop.
Eat Your Food - Netflix Interruptor
// ==UserScript==
// @name Remember to eat your food while watching Netflix
// @namespace https://www.tarikguney.com
// @version 0.1
// @description Kids watching cartoons on Netflix often forget to eat and chew their food, which drives parents crazy. You need to sit down with them and pause the video and remind them to eat their food. This script will automate that.
// @author Tarik Guney
// @match https://www.netflix.com/watch/*
// @icon https://upload.wikimedia.org/wikipedia/commons/thumb/7/75/Netflix_icon.svg/1200px-Netflix_icon.svg.png
// @grant none
// ==/UserScript==
/*
Known problems:
1. When Netflix video jumps to the next in line, the script loses its effect. Looks like the jump happens w/o page refresh.
*/
(function() {
'use strict';
// Waits for this many seconds to try to find Netflix media player. Waiting for document ready is not enough.
// A better solution would check if the media player is ready in a loop rather than a fixed delay, but this is simpler for now.
var initializationDelay = 10000; // 10 seconds
var interruptionInterval = 40000; // 40 seconds
var pauseTime = 8000; // 8 seconds
if(document.readyState === 'ready' || document.readyState === 'complete') {
console.info("page is ready");
startInterruptingNetflix();
} else {
document.onreadystatechange = function () {
if (document.readyState == "complete") {
console.info("page is ready");
startInterruptingNetflix();
}
}
}
})();
function startInterruptingNetflix(){
setTimeout(function(){
var mediaPlayer = document.getElementsByTagName("video")[0];
var mediaPlayerFound = mediaPlayer != null;
if(mediaPlayerFound){
console.info("the netflix media player is found");
setInterval(function(){
mediaPlayer.pause();
console.info("the media player is paused");
setTimeout(function(){
mediaPlayer.play();
console.info("the media player resumes");
},pauseTime);
},interruptionInterval);
} else {
console.error("the netflix media player could not be found. increase the intializationDelay perhaps.");
}
},initializationDelay);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment