Greasy Fork

Greasy Fork is available in English.

Youku 视频去广告

Youku 视频去广

当前为 2020-08-14 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Youku 视频去广告
// @namespace    Youku.com
// @version      0.1
// @description  Youku 视频去广
// @match        https://v.youku.com/v_show/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(() => {
  'use strict';

  const rules = [
    {
      //去倒计时
      url: /^(https:)?\/\/acs\.youku\.com\/h5\/mtop\.youku\.play\.ups\.appinfo\.get.+callback=mtopjsonp.+/,
      async callback (url) {
        const val = await (await fetch(url, { credentials: 'include' })).text();
        const cb = url.match(/mtopjsonp\d*/);
        if(!cb) return;
        const index = val.indexOf(cb[0]);
        if(index < 2){
          const json = JSON.parse(val.slice(index + cb[0].length + 1, -1));
          delete json.data.data.ad;
          createScript(`${cb[0]}(${JSON.stringify(json)})`);
        }
      }
    }
  ];

  const createScript = (text) => {
    const script = document.createElement('script');
    script.textContent = text;
    document.head.appendChild(script);
    script.remove();
  }
  Object.defineProperty(
    HTMLScriptElement.prototype, '_original',
    Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype, 'src')
  );
  Object.defineProperty(HTMLScriptElement.prototype, 'src', {
    get () {
      return this._original;
    },
    set (val) {
      const rule = rules.find(r => r.url.test(val));
      if (rule) {
        rule.callback(val);
      }else{
        this._original = val;
      }
    }
  });
})();