-
-
Save resultakak/33028bf7e2e1a7d1a7bb51e5fbc32664 to your computer and use it in GitHub Desktop.
Revisions
-
tarikguney revised this gist
Jan 9, 2022 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,5 +72,4 @@ },interruptionInterval); } })(); -
tarikguney revised this gist
Jan 9, 2022 . 1 changed file with 13 additions and 23 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,10 +11,6 @@ (function() { 'use strict'; var interruptionInterval = 40000; // 40 seconds var pauseTime = 8000; // 8 seconds @@ -40,15 +36,14 @@ } }).observe(document, {subtree: true, childList: true}); async function onUrlChange() { console.info("Playing the next video"); clearInterval(interruptionIntervalId); await new Promise(resolve => setTimeout(resolve, pauseTime)); interruptionIntervalId = startInterruptingNetflix(); } async function startInterruptingNetflix(){ var mediaPlayer = document.getElementsByTagName("video")[0]; var maximumRetryBucket = 1000; while(mediaPlayer == null && maximumRetryBucket >= 0){ @@ -57,30 +52,25 @@ maximumRetryBucket--; } if(mediaPlayer == null){ console.error("the netflix media player could not be found!"); } console.info("the netflix media player is found"); return setInterval(function(){ if(mediaPlayer.readyState >= 2 && mediaPlayer.paused == false){ mediaPlayer.pause(); console.info("the media player is paused"); setTimeout(function(){ var actualPlayPromise = mediaPlayer.play(); actualPlayPromise.then(_ => { console.info("the media player resumes"); }); },pauseTime); } },interruptionInterval); } })(); -
tarikguney revised this gist
Jan 9, 2022 . 1 changed file with 50 additions and 32 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,52 +17,70 @@ var interruptionInterval = 40000; // 40 seconds var pauseTime = 8000; // 8 seconds var interruptionIntervalId; if(document.readyState === 'ready' || document.readyState === 'complete') { console.info("page is ready"); interruptionIntervalId = startInterruptingNetflix(); } else { document.onreadystatechange = function () { if (document.readyState == "complete") { console.info("page is ready"); interruptionIntervalId = startInterruptingNetflix(); } } } // If moving onto the next video in line, rebind the timer. let lastUrl = location.href; new MutationObserver(() => { const url = location.href; if (url !== lastUrl) { lastUrl = url; onUrlChange(); } }).observe(document, {subtree: true, childList: true}); function onUrlChange() { console.info("Playing the next video"); clearInterval(interruptionIntervalId); interruptionIntervalId = startInterruptingNetflix(); } async function startInterruptingNetflix(){ var interruptionIntervalId; var mediaPlayer = document.getElementsByTagName("video")[0]; var maximumRetryBucket = 1000; while(mediaPlayer == null && maximumRetryBucket >= 0){ await new Promise(resolve => setTimeout(resolve, 1000)); mediaPlayer = document.getElementsByTagName("video")[0]; maximumRetryBucket--; } var mediaPlayerFound = mediaPlayer != null; if(!mediaPlayerFound){ console.error("the netflix media player could not be found!"); } console.info("the netflix media player is found"); interruptionIntervalId = setInterval(function(){ // Don't delete this, otherwise: https://developers.google.com/web/updates/2017/06/play-request-was-interrupted var playPromise = mediaPlayer.play(); if (playPromise !== undefined) { playPromise.then(_ => { mediaPlayer.pause(); console.info("the media player is paused"); setTimeout(function(){ mediaPlayer.play(); console.info("the media player resumes"); },pauseTime); }); } },interruptionInterval); return interruptionIntervalId; } })(); -
tarikguney revised this gist
Jan 9, 2022 . 1 changed file with 15 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,11 +9,6 @@ // @grant none // ==/UserScript== (function() { 'use strict'; // Waits for this many seconds to try to find Netflix media player. Waiting for document ready is not enough. @@ -34,6 +29,21 @@ Known problems: } } } // If moving onto the next video in line, rebind the timer. let lastUrl = location.href; new MutationObserver(() => { const url = location.href; if (url !== lastUrl) { lastUrl = url; onUrlChange(); } }).observe(document, {subtree: true, childList: true}); function onUrlChange() { console.info("Playing the next video"); startInterruptingNetflix(); } })(); function startInterruptingNetflix(){ -
tarikguney revised this gist
Jan 6, 2022 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,12 +24,12 @@ Known problems: 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(); } } @@ -42,13 +42,13 @@ function startInterruptingNetflix(){ 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 { -
tarikguney revised this gist
Jan 6, 2022 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,11 @@ // @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. -
tarikguney revised this gist
Jan 6, 2022 . 1 changed file with 16 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,6 +11,13 @@ (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.log("page is ready"); startInterruptingNetflix(); @@ -27,17 +34,20 @@ function startInterruptingNetflix(){ setTimeout(function(){ var mediaPlayer = document.getElementsByTagName("video")[0]; var mediaPlayerFound = mediaPlayer != null; if(mediaPlayerFound){ console.log("the netflix media player is found"); setInterval(function(){ mediaPlayer.pause(); console.log("the media player is paused"); setTimeout(function(){ mediaPlayer.play(); console.log("teh media player resumes"); },pauseTime); },interruptionInterval); } else { console.error("the netflix media player could not be found. increase the intializationDelay perhaps."); } },initializationDelay); } -
tarikguney renamed this gist
Jan 6, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
tarikguney created this gist
Jan 6, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ // ==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== (function() { 'use strict'; if(document.readyState === 'ready' || document.readyState === 'complete') { console.log("page is ready"); startInterruptingNetflix(); } else { document.onreadystatechange = function () { if (document.readyState == "complete") { console.log("page is ready"); startInterruptingNetflix(); } } } })(); function startInterruptingNetflix(){ setTimeout(function(){ var mediaPlayer = document.getElementsByTagName("video")[0]; console.log(mediaPlayer); if(mediaPlayer != null){ console.log("the media player is found"); setInterval(function(){ mediaPlayer.pause(); console.log("the media player is paused"); setTimeout(function(){ mediaPlayer.play(); console.log("teh media player resumes"); },4000); },50000); } },2000); }