Greasy Fork

Greasy Fork is available in English.

Youku视频去广告 by ylcs006

Youku视频去广告及其黑屏倒计时

当前为 2021-08-01 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Youku视频去广告 by ylcs006
// @namespace    ylcs006.Youku.com
// @version      0.1.1
// @description  Youku视频去广告及其黑屏倒计时
// @match        https://v.youku.com/v_show/*
// @run-at       document-start
// ==/UserScript==

'use strict';

const r1 = (regp, s) => regp.test(s) && RegExp.$1;
const runScript = (text) => {
	const e = document.createElement('script');
	e.textContent = text;
	document.head.appendChild(e);
	e.remove();
};

const rules = [{
		//去广告及其倒计时
		rule: '//acs.youku.com/h5/mtop.youku.play.ups.appinfo.get/',
		async callback(url) {
			const resp = await fetch(url, { credentials: 'include' });
			const val = await resp.text();
			const cb = r1(/callback=(mtopjsonp\d*)/, url);
			if (!cb) return;
			const i = val.indexOf(cb);
			if (i < 2) {
				const json = JSON.parse(val.slice(i + cb.length + 1, -1));
				json.data.data.ad = {BFSTREAM:[],BFVAL:[]};
				runScript(`${cb}(${JSON.stringify(json)})`);
			}
		}
	}
];

Reflect.defineProperty(
	HTMLScriptElement.prototype, '_rawSrc',
	Reflect.getOwnPropertyDescriptor(HTMLScriptElement.prototype, 'src')
);
Reflect.defineProperty(HTMLScriptElement.prototype, 'src', {
	get() {
		return this._rawSrc;
	},
	set(val) {
		const rule = rules.find(r => val.includes(r.rule));
		if (rule) rule.callback(val);
		else this._rawSrc = val;
	}
});
/*
Reflect.setPrototypeOf(HTMLScriptElement, new Proxy(HTMLScriptElement.prototype, {
	appendChild(txt) {
		const s = txt.toString();
		const isHandle = rule instanceof RegExp ? rule.test(s) : s.includes(rule);
		if (!isHandle) return rawAppend(txt);
		if (cb) {
			txt.textContent = cb(s);
			//return rawAppend(txt);
		}
	},
	set(target, key, value, receiver) {
		if (key == 'src') {
			const rule = rules.find(r => value.includes(r.rule));
			if (rule) return rule.callback(value);
		}
		Reflect.set(target, key, value, receiver);
	}
})); */