Size
3.5 KB
Version
Created
Mar 4, 2026
Updated
about 1 month ago
1// ==UserScript==
2// @name Script for www.youtube.com
3// @description A new userscript
4// @match https://*.youtube.com/*
5// @icon https://www.youtube.com/s/desktop/f893a131/img/logos/favicon_32x32.png
6// ==/UserScript==
7(function() {
8 'use strict';
9
10 function createSpeedButton() {
11 const button = document.createElement('button');
12 button.textContent = '4x Speed';
13 button.style.backgroundColor = '#ff0000';
14 button.style.color = 'white';
15 button.style.padding = '8px 12px';
16 button.style.border = 'none';
17 button.style.borderRadius = '4px';
18 button.style.cursor = 'pointer';
19 button.style.fontSize = '12px';
20 button.style.fontWeight = 'bold';
21 button.style.position = 'fixed';
22 button.style.top = '10px';
23 button.style.right = '10px';
24 button.style.zIndex = '9999';
25 button.addEventListener('click', setVideoSpeed);
26 document.body.appendChild(button);
27 }
28
29 function createSkipAdButton() {
30 const button = document.createElement('button');
31 button.textContent = 'Skip Ads';
32 button.style.backgroundColor = '#00aa00';
33 button.style.color = 'white';
34 button.style.padding = '8px 12px';
35 button.style.border = 'none';
36 button.style.borderRadius = '4px';
37 button.style.cursor = 'pointer';
38 button.style.fontSize = '12px';
39 button.style.fontWeight = 'bold';
40 button.style.position = 'fixed';
41 button.style.top = '50px';
42 button.style.right = '10px';
43 button.style.zIndex = '9999';
44 button.addEventListener('click', skipAds);
45 document.body.appendChild(button);
46 }
47
48 function setVideoSpeed() {
49 const video = document.querySelector('video');
50 if (video) {
51 video.playbackRate = 4;
52 console.log('Video speed set to 4x');
53 } else {
54 console.log('No video element found');
55 }
56 }
57
58 function skipAds() {
59 // Try to find and click skip button using document.querySelector('.ytp-ad-skip-button, .ytp-skip-ad-button')
60 const skipButton = document.querySelector('.ytp-ad-skip-button, .ytp-skip-ad-button');
61 if (skipButton && skipButton.offsetParent !== null) {
62 skipButton.click();
63 console.log('Successfully clicked YouTube skip button');
64 return;
65 }
66
67 // Try to find video element and skip to end of ad by setting currentTime to duration
68 const video = document.querySelector('video');
69 if (video && video.duration) {
70 video.currentTime = video.duration;
71 console.log('Skipped ad by setting video time to end');
72 return;
73 }
74
75 // Try to find and click any other skip elements like '.videoAdUiSkipButton, .skip-button'
76 const otherSkipButtons = document.querySelectorAll('.videoAdUiSkipButton, .skip-button');
77 for (let button of otherSkipButtons) {
78 if (button && button.offsetParent !== null) {
79 button.click();
80 console.log('Successfully clicked alternative skip button');
81 return;
82 }
83 }
84
85 // Log result of skip attempt
86 console.log('No skip options found or available');
87 }
88
89 function init() {
90 createSpeedButton();
91 createSkipAdButton();
92 }
93
94 if (document.readyState === 'loading') {
95 document.addEventListener('DOMContentLoaded', init);
96 } else {
97 init();
98 }
99})();