YouTube Ad Skipper

Simple ad skip button for YouTube

目前为 2025-01-24 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Ad Skipper
  3. // @version 1.4
  4. // @description Simple ad skip button for YouTube
  5. // @match *://*.youtube.com/*
  6. // @grant GM_addStyle
  7. // @run-at document-end
  8. // @license MIT
  9. // @author anassk
  10. // @namespace https://greasyfork.org/users/1422975
  11. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14.  
  15. const skipButton = document.createElement('button');
  16. skipButton.innerHTML = '>';
  17. skipButton.style.cssText = `
  18. position: absolute;
  19. bottom: 70px;
  20. right: 5px;
  21. z-index: 9999;
  22. background: rgba(0, 0, 0, 0.7);
  23. color: white;
  24. border: none;
  25. padding: 5px 10px;
  26. border-radius: 4px;
  27. cursor: pointer;
  28. font-size: 14px;
  29. `;
  30.  
  31. const reloadVideo = () => {
  32. const player = document.querySelector('video');
  33. const videoId = new URLSearchParams(window.location.search).get('v');
  34. if (player && videoId) {
  35. const videoTime = player.currentTime;
  36. const moviePlayer = document.getElementById('movie_player');
  37. if (moviePlayer) {
  38. moviePlayer.loadVideoById(videoId, videoTime);
  39. }
  40. }
  41. };
  42.  
  43. skipButton.addEventListener('click', reloadVideo);
  44.  
  45. const initializeButton = () => {
  46. const player = document.querySelector('video');
  47. if (player) {
  48. const playerContainer = player.closest('.html5-video-player');
  49. if (playerContainer && !playerContainer.querySelector('.skip-button')) {
  50. skipButton.classList.add('skip-button');
  51. playerContainer.appendChild(skipButton);
  52. }
  53. } else {
  54. setTimeout(initializeButton, 1000);
  55. }
  56. };
  57.  
  58. GM_addStyle(`
  59. .skip-button:hover {
  60. background: rgba(0, 0, 0, 0.9) !important;
  61. }
  62. `);
  63.  
  64. initializeButton();
  65. })();