Skip to content

Instantly share code, notes, and snippets.

@gdvalle
Last active March 29, 2019 03:38
Show Gist options
  • Save gdvalle/0277739ba66c6a31d8a1bd240eb1b709 to your computer and use it in GitHub Desktop.
Save gdvalle/0277739ba66c6a31d8a1bd240eb1b709 to your computer and use it in GitHub Desktop.
Skip intros in Netflix videos.
// ==UserScript==
// @name Netflix Skip Intro
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Automatically skip intros with Netflix.
// @author goobyndolan
// @match https://www.netflix.com/*
// @grant none
// ==/UserScript==
(function() {
"use strict";
const mouseEventOpts = {
bubbles: true,
cancelable: true,
view: window
};
const mouseclick = new MouseEvent("click", mouseEventOpts);
const addObserver = target => {
const observer = new MutationObserver(function(mutations) {
mutations.forEach(mutation => {
if (mutation.addedNodes) {
const div = Array.from(mutation.addedNodes).find(
node => node.innerText === "SKIP INTRO"
);
if (div) {
const link = Array.from(div.children).find(
child => child.text === "Skip Intro"
);
if (link) {
link.dispatchEvent(mouseclick);
}
// Often the video will be paused after clicking.
// Force the video to play again.
const video = document.querySelector("video");
if (video) {
// If we only call play() the first pause can be ignored by the player.
video.pause();
video.play();
}
}
}
});
});
const config = { attributes: false, childList: true, characterData: false };
observer.observe(target, config);
return observer;
};
let lastTarget;
let lastObserver;
// Add observer, and watch to re-add it if necessary.
setInterval(() => {
const target = document.querySelector(".PlayerControlsNeo__layout");
if (target && target !== lastTarget) {
lastTarget = target;
const observer = addObserver(target);
if (lastObserver) {
lastObserver.disconnect();
}
lastObserver = observer;
}
}, 3000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment