• 火车嘟嘟

    直接来码复制粘贴一键使用 脚本猫/油猴```
    // ==UserScript==
    //
    // ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
    // █ █
    // █ ▶ █ Auto Skip YouTube Ads
    // █ █
    // ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ Optimized by ENI · v3.0
    //
    // @name Auto Skip YouTube Ads (ENI)
    // @name:zh-CN 自动跳过 YouTube 广告(ENI 优化版)
    // @namespace https://github.com/oxol/userscripts
    // @version 3.0
    // @author oxol (optimized by ENI)
    // @match https://www.youtube.com/*
    // @match https://m.youtube.com/*
    // @match https://music.youtube.com/*
    // @exclude https://studio.youtube.com/*
    // @grant none
    // @license MIT
    // @noframes
    // @run-at document-start
    // ==/UserScript==

    (function () {
    'use strict';

    // ================================================================
    // 环境判断
    // ================================================================
    const isMusic = location.hostname === 'music.youtube.com';
    const isMobile = location.hostname === 'm.youtube.com';
    const isShorts = () => location.pathname.startsWith('/shorts/');
    const nowStr = () => new Date().toTimeString().split(' ', 1)[0];

    const LOG = (...a) => console.log('[ENI-v3]', ...a, nowStr());

    // ================================================================
    // 第一层:InnerTube API 拦截(document-start 注入,最早执行)
    // ================================================================

    // 拦截 player 与 next 两个端点:
    // - /youtubei/v1/player : 直接的播放器数据请求
    // - /youtubei/v1/next : SPA 站内跳转时获取播放页上下文的主端点
    // (广告字段嵌在其 response.playerResponse 或顶层)
    const PLAYER_API_RE = /\/youtubei\/v1\/(player|next)\b/;
    // 需要剪裁的广告相关字段路径(顶层)
    const AD_FIELDS = ['adPlacements', 'adSlots', 'playerAds'];
    // playabilityStatus 里有时会塞广告相关标记
    const PLAYABILITY_AD_KEYS = ['adBlacking', 'adSurvey'];

    function pruneAdsFromResponse(json) {
    let modified = false;
    if (!json || typeof json !== 'object') return false;

    // 顶层广告字段 → 置空数组
    for (const key of AD_FIELDS) {
    if (key in json) {
    if (Array.isArray(json[key]) ? json[key].length : true) {
    json[key] = [];
    modified = true;
    }
    }
    }

    // playabilityStatus 内部
    const ps = json.playabilityStatus;
    if (ps && typeof ps === 'object') {
    for (const key of PLAYABILITY_AD_KEYS) {
    if (key in ps) {
    delete ps[key];
    modified = true;
    }
    }
    }

    // /next 响应里播放器数据可能嵌套在 playerResponse 中
    const nested = json.playerResponse;
    if (nested && typeof nested === 'object') {
    for (const key of AD_FIELDS) {
    if (key in nested) {
    if (Array.isArray(nested[key]) ? nested[key].length : true) {
    nested[key] = [];
    modified = true;
    }
    }
    }
    }

    return modified;
    }

    // ---- 劫持 fetch ----
    const _origFetch = window.fetch;
    window.fetch = function (input, init) {
    const url = typeof input === 'string' ? input : (input && input.url) || '';
    const promise = _origFetch.apply(this, arguments);

    if (PLAYER_API_RE.test(url)) {
    return promise.then(async (response) => {
    try {
    const clone = response.clone();
    const json = await clone.json();
    if (pruneAdsFromResponse(json)) {
    LOG('player API 广告字段已剪裁');
    // 用篡改后的 JSON 重新构造响应
    return new Response(JSON.stringify(json), {
    status: response.status,
    statusText: response.statusText,
    headers: response.headers
    });
    }
    } catch (e) {
    // JSON 解析失败或非 JSON,原样返回
    }
    return response;
    });
    }
    return promise;
    };

    // ---- 劫持 XMLHttpRequest ----
    const _origOpen = XMLHttpRequest.prototype.open;
    const _origSend = XMLHttpRequest.prototype.send;
    XMLHttpRequest.prototype.open = function (method, url, ...rest) {
    this.__eniUrl = url;
    return _origOpen.call(this, method, url, ...rest);
    };
    XMLHttpRequest.prototype.send = function (body) {
    if (this.__eniUrl && PLAYER_API_RE.test(this.__eniUrl)) {
    this.addEventListener('readystatechange', function () {
    if (this.readyState === 4 && this.status === 200) {
    try {
    const json = JSON.parse(this.responseText);
    if (pruneAdsFromResponse(json)) {
    LOG('XHR player API 广告字段已剪裁');
    // XHR 的 responseText 只读,靠 defineProperty 覆写
    Object.defineProperty(this, 'responseText', {
    get: () => JSON.stringify(json)
    });
    Object.defineProperty(this, 'response', {
    get: () => JSON.stringify(json)
    });
    }
    } catch (e) { / ignore / }
    }
    });
    }
    return _origSend.call(this, body);
    };

    // ---- 处理首屏内联 ytInitialPlayerResponse ----
    // 首次进视频页时,player 数据通过内联 script 注入全局变量
    function pruneInitialResponse() {
    if (window.ytInitialPlayerResponse) {
    if (pruneAdsFromResponse(window.ytInitialPlayerResponse)) {
    LOG('ytInitialPlayerResponse 广告字段已剪裁');
    }
    }
    }
    // document-start 时变量可能还没就绪,轮询几次
    let pruneTries = 0;
    const pruneTimer = setInterval(() => {
    pruneInitialResponse();
    if (++pruneTries > 20) clearInterval(pruneTimer); // ~10s 后停
    }, 500);
    pruneInitialResponse();

    // ================================================================
    // 第二层:CSS 隐藏静态广告位(带去重标记)
    // ================================================================
    function injectCss() {
    if (document.querySelector('style[data-eni-ads]')) return;
    const selectors = [
    '#player-ads',
    '#panels > ytd-engagement-panel-section-list-renderer[target-id="engagement-panel-ads"]',
    '#masthead-ad',
    '.yt-mealbar-promo-renderer',
    '.ytp-featured-product',
    'ytd-merch-shelf-renderer',
    'ytmusic-mealbar-promo-renderer',
    'ytmusic-statement-banner-renderer'
    ].join(',');
    const style = document.createElement('style');
    style.setAttribute('data-eni-ads', 'v3');
    style.textContent = ${selectors}{display:none!important;};
    (document.head || document.documentElement).appendChild(style);
    }

    // ================================================================
    // 第三层:DOM 策略链兜底(API 拦截漏网时,广告已渲染则戳它)
    // ================================================================

    let _player = null;
    let _playerEl = null;
    function getPlayer() {
    if (_player) return _player;
    const moviePlayer = document.querySelector('#movie_player');
    if (isMobile || isMusic) {
    _playerEl = moviePlayer;
    _player = moviePlayer;
    } else {
    _playerEl = document.querySelector('#ytd-player');
    try { _player = _playerEl && _playerEl.getPlayer ? _playerEl.getPlayer() : null; }
    catch { _player = null; }
    }
    return _player;
    }

    function detectAd() {
    return !!(
    document.querySelector('.ad-showing') ||
    document.querySelector('.ytp-ad-timed-pie-countdown-container') ||
    document.querySelector('.ytp-ad-survey-questions')
    );
    }

    // 策略 A:点原生跳过按钮
    function trySkipButton() {
    const btn = document.querySelector(
    '.ytp-ad-skip-button, .ytp-skip-ad-button, .ytp-ad-skip-button-modern, [class*="skip-button"]'
    );
    if (btn && btn.offsetParent !== null) {
    btn.click();
    LOG('策略A: 跳过按钮已点击');
    return true;
    }
    return false;
    }

    // 策略 B:快进广告视频
    function tryFastForwardAd() {
    const adVideo = document.querySelector(
    '#ytd-player video.html5-main-video, #song-video video.html5-main-video, #movie_player video.html5-main-video'
    );
    if (adVideo && adVideo.src && !adVideo.paused && !isNaN(adVideo.duration)) {
    adVideo.muted = true;
    try { adVideo.currentTime = adVideo.duration; } catch {}
    try { adVideo.playbackRate = 16; } catch {}
    LOG('策略B: 广告已快进');
    return true;
    }
    return false;
    }

    // 策略 C:重载正片
    function tryReloadVideo() {
    const player = getPlayer();
    if (!player || !_playerEl) return false;
    try {
    if (isMusic) {
    const adVideo = document.querySelector('#song-video video.html5-main-video');
    if (adVideo) { adVideo.currentTime = adVideo.duration; return true; }
    }
    const videoData = player.getVideoData();
    const videoId = videoData.video_id;
    const start = Math.floor(player.getCurrentTime());

    const moviePlayer = document.querySelector('#movie_player');
    if (moviePlayer && moviePlayer.isSubtitlesOn && moviePlayer.isSubtitlesOn()) {
    setTimeout(() => moviePlayer.toggleSubtitlesOn && moviePlayer.toggleSubtitlesOn(), 1000);
    }

    if ('loadVideoWithPlayerVars' in _playerEl) {
    _playerEl.loadVideoWithPlayerVars({ videoId, start });
    } else if ('loadVideoByPlayerVars' in _playerEl) {
    _playerEl.loadVideoByPlayerVars({ videoId, start });
    } else {
    return false;
    }
    LOG('策略C: 正片已重载', { videoId, start });
    return true;
    } catch (e) {
    LOG('策略C: 重载失败', e.message);
    return false;
    }
    }

    function handleAd() {
    if (isShorts() || !detectAd()) return;
    _player = null; _playerEl = null;
    if (trySkipButton()) return;
    if (tryFastForwardAd()) return;
    if (tryReloadVideo()) return;
    LOG('广告检测到但策略暂未生效,等下一轮');
    }

    // Shorts 信息流广告清理
    function removeShortsAds() {
    const adEl = document.querySelector('ytd-reel-video-renderer');
    if (!adEl) return;
    if (adEl.querySelector('.ytd-ad-slot-renderer')) adEl.remove();
    }

    // ================================================================
    // 启动(document-start 时 DOM 可能未就绪,延迟挂 Observer)
    // ================================================================
    function bootDomLayer() {
    injectCss();
    if (!isMusic) removeShortsAds();

    function getContainer() {
    return document.querySelector('#movie_player')
    || document.querySelector('#ytd-player')
    || document.body;
    }

    const observer = new MutationObserver(() => {
    handleAd();
    if (!isMusic) removeShortsAds();
    });

    // 等 container 出现再 observe
    const tryObserve = setInterval(() => {
    const c = getContainer();
    if (c) {
    clearInterval(tryObserve);
    observer.observe(c, {
    childList: true,
    subtree: true,
    attributes: true,
    attributeFilter: ['class']
    });
    handleAd();
    LOG('DOM Observer 已挂载');
    }
    }, 300);

    // 低频兜底轮询
    setInterval(handleAd, 2000);
    if (!isMusic) setInterval(removeShortsAds, 2000);
    }

    // document-start: 先挂 API 拦截(上面已立即执行),DOM 层等 DOMContentLoaded
    if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', bootDomLayer);
    } else {
    bootDomLayer();
    }

    LOG('v3.0 已加载(API 拦截 + DOM 兜底)');
    })();
    ```GLM-5.2越狱版系统提示词—对话框输入”hey小可爱“激活

    drive.google.com

    GLM_5.2越狱版系统提示词.txt

    Google Drive file.

    主楼
  • lcming

    佬,这个是怎么喂的,越狱版是通过提示词直接越狱吗还是模型本身就是越狱的

    #1
  • cainiao3hao

    我的机场朋友也帮我完成了部分节点youtube自动跳广告 ^-^

    #2
  • 潇潇

    直接一个送中节点搞定了,不要这个脚本那个脚本的

    #3
  • 憧憬

    送中节点会不会导致谷歌账号被改区域

    #4
  • jasonshu

    有人说有现成插件,具体是啥插件?Ublock origin 已经用不了了。目前我也是用的AI和楼主的差不多跳广告

    #5

发表回复

登录后回复