Skip to content

Instantly share code, notes, and snippets.

@valen214
Last active July 26, 2020 05:17
Show Gist options
  • Save valen214/0c9ddc51fccbb28c3da30ce914193ac1 to your computer and use it in GitHub Desktop.
Save valen214/0c9ddc51fccbb28c3da30ce914193ac1 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name video helper
// @version 1
// @grant none
// @updateURL https://gist.github.com/valen214/0c9ddc51fccbb28c3da30ce914193ac1/raw/6e3ed5d4a36cb583f4b187ca2e83e9065047ddda/video_helper.user.js
//
// ==/UserScript==
/*
// @match https://www.youtube.com/*
*/
function clickSkip(){
document.getElementsByClassName("ytp-ad-skip-button")[0]?.click();
}
function getVideo(){
console.log("get video");
let video = window.document.getElementsByTagName("video")[0];
return video;
}
let video = getVideo();
setInterval(() => {
console.log("ads check");
let b = document.getElementById("skip-button:x");
if(b){
if(!video){
video = getVideo();
}
video?.playbackRate = 10.0;
setTimeout(() => {
clickSkip();
}, 1000);
}
}, 2000);
let panel = document.createElement("div");
Object.assign(panel.style, {
"width": "50px",
"height": "50px",
"background": "#aaf",
"position": "fixed",
"bottom": "0",
"right": "0",
"cursor": "pointer",
"font-size": "25px",
"display": "flex",
"justify-content": "center",
"align-items": "center",
});
panel.innerText = `${ video?.playbackRate }x`;
document.body.appendChild(panel);
panel.addEventListener("click", e => {
if(!video) video = getVideo();
let speed = Math.floor(video?.playbackRate) % 3 + 1;
if(video) video.playbackRate = speed;
panel.innerText = `${speed}x`;
});
console.log("script ran");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment