Enhanced 2025 YouTube Ad Blocker

Blocks YouTube ads, with advanced protections against detection.

当前为 2025-01-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Enhanced 2025 YouTube Ad Blocker
  3. // @namespace https://example.com/
  4. // @version 2.0
  5. // @description Blocks YouTube ads, with advanced protections against detection.
  6. // @author hunter
  7. // @match *://*.youtube.com/*
  8. // @grant GM_addStyle
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Encoded ad selectors and request patterns
  16. const obfuscatedSelectors = atob("eXRkLWJhbm5lci1wcm9tby1yZW5kZXJlcix5dGQtZGlzcGxheS1hZC1yZW5kZXJlcix5dGQtcHJvbW90ZWQtdmlkZW8tcmVuZGVyZXIsI21hc3RoZWFkLWFkLC55dHAtYWQtbW9kdWxlLC55dHAtYWQtb3ZlcmxheS1jb250YWluZXI=");
  17. const adPatterns = atob("Ki8vKi5nb29nbGV2aWRlby5jb20vdmlkZW9wbGF5YmFjaz8qYWQqLCovLyoueW91dHViZS5jb20vYXBpL3N0YXRzL2Fkcz8qLCovLyoueW91dHViZS5jb20vcGFnZWFkLyoi");
  18.  
  19. const selectors = obfuscatedSelectors.split(",");
  20. const patterns = adPatterns.split(",");
  21.  
  22. // Randomized delay generator
  23. const randomDelay = () => Math.floor(Math.random() * 50 + 50);
  24.  
  25. // Enhanced DOM observer for ad removal
  26. const startObserver = () => {
  27. const observer = new MutationObserver((mutations) => {
  28. setTimeout(() => removeAds(), randomDelay());
  29. });
  30. observer.observe(document.body, { childList: true, subtree: true });
  31. };
  32.  
  33. // Function to remove ads from DOM
  34. const removeAds = () => {
  35. selectors.forEach((sel) => {
  36. document.querySelectorAll(sel).forEach((el) => el.remove());
  37. });
  38. };
  39.  
  40. // Block ad-related network requests
  41. const blockNetworkAds = () => {
  42. const fetchOriginal = window.fetch;
  43. window.fetch = function(url, options) {
  44. if (typeof url === 'string' && patterns.some((pat) => url.includes(pat))) {
  45. console.log('Blocked fetch request: ', url);
  46. return new Promise(() => {});
  47. }
  48. return fetchOriginal.apply(this, arguments);
  49. };
  50.  
  51. const xhrOriginal = XMLHttpRequest.prototype.open;
  52. XMLHttpRequest.prototype.open = function(method, url) {
  53. if (patterns.some((pat) => url.includes(pat))) {
  54. console.log('Blocked XMLHttpRequest: ', url);
  55. return;
  56. }
  57. return xhrOriginal.apply(this, arguments);
  58. };
  59. };
  60.  
  61. // Inject advanced hidden styles to hide ads
  62. GM_addStyle(`
  63. ${selectors.join(",")} {
  64. display: none !important;
  65. visibility: hidden !important;
  66. }
  67. `);
  68.  
  69. // Integrity check to prevent script tampering
  70. const integrityCheck = () => {
  71. if (document.currentScript && !document.currentScript.src.includes('@name')) {
  72. console.warn("Tampering detected. Halting script execution.");
  73. return;
  74. }
  75. console.log("Script integrity verified.");
  76. };
  77.  
  78. // Main entry point
  79. const main = () => {
  80. integrityCheck();
  81. startObserver();
  82. blockNetworkAds();
  83. removeAds();
  84. };
  85.  
  86. // Randomized execution delay to evade detections
  87. setTimeout(() => main(), randomDelay());
  88. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址