-
Notifications
You must be signed in to change notification settings - Fork 215
/
nbys.user.js
207 lines (201 loc) · 7.02 KB
/
nbys.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// ==UserScript==
// @name 泥巴影视去广告(nbys/nivod)
// @namespace http://tampermonkey.net/
// @version 0.1.3
// @license CC BY-NC-SA 4.0
// @description 泥巴影视去广告(nbys/nivod)视频广告/图片广告;iPhone(搜索毒奶去广告计划)/PC/Mac/iPad端均可食用;
// @author limbopro
// @match https://www.nivod4.tv/*
// @match https://m.nivod4.tv/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=nivod4.tv
// @grant none
// @run-at document-start
// ==/UserScript==
// 一些常量
const imax = {
css: {
nbys: "img[src*=gif],#adsbox,.video-ad,#ad,img[src*=download],#adltop,.nav-ads,#adDiv {display:none !important}", // 泥巴影视视频左上角水印贴片
}
}
setConstant('detailParams.is_ad_play', 'false'); // 泥巴影视PC版播放页视频广告加速
evaldataPrune(); // 泥巴影视移动版播放页视频广告加速
css_adsRemove(imax.css.nbys); // 网页图片广告
// 动态创建引用内部资源 内嵌式样式 内嵌式脚本
function css_adsRemove(newstyle, delaytime, id) {
setTimeout(() => {
var creatcss = document.createElement("style");
creatcss.id = id;
creatcss.innerHTML = newstyle;
document.getElementsByTagName('head')[0].appendChild(creatcss)
console.log("CSS样式新增完毕!");
}, delaytime);
}
// 泥巴影视手机版视频播放前20秒广告跳过
// https://github.com/AdguardTeam/AdguardFilters/issues/146359
function evaldataPrune() {
window.eval = new Proxy(eval, {
apply: (a, b, c) => {
if (c[0] && c[0].includes("commercial") && c[0].startsWith("(") && c[0].endsWith(")")) { let a = c[0].slice(1).slice(0, -1), b = JSON.parse(a); b.entity?.commercial && (b.entity.commercial = void 0), c[0] = `(${JSON.stringify(b)})` }
return Reflect.apply(a, b, c)
}
})
};
/* 广告视频加速 */
function setConstant(
chain = '',
cValue = ''
) {
if (typeof chain !== 'string') { return; }
if (chain === '') { return; }
const trappedProp = (() => {
const pos = chain.lastIndexOf('.');
if (pos === -1) { return chain; }
return chain.slice(pos + 1);
})();
if (trappedProp === '') { return; }
const thisScript = document.currentScript;
const objectDefineProperty = Object.defineProperty.bind(Object);
const cloakFunc = fn => {
objectDefineProperty(fn, 'name', { value: trappedProp });
const proxy = new Proxy(fn, {
defineProperty(target, prop) {
if (prop !== 'toString') {
return Reflect.deleteProperty(...arguments);
}
return true;
},
deleteProperty(target, prop) {
if (prop !== 'toString') {
return Reflect.deleteProperty(...arguments);
}
return true;
},
get(target, prop) {
if (prop === 'toString') {
return function () {
return `function ${trappedProp}() { [native code] }`;
}.bind(null);
}
return Reflect.get(...arguments);
},
});
return proxy;
};
if (cValue === 'undefined') {
cValue = undefined;
} else if (cValue === 'false') {
cValue = false;
} else if (cValue === 'true') {
cValue = true;
} else if (cValue === 'null') {
cValue = null;
} else if (cValue === "''") {
cValue = '';
} else if (cValue === '[]') {
cValue = [];
} else if (cValue === '{}') {
cValue = {};
} else if (cValue === 'noopFunc') {
cValue = cloakFunc(function () { });
} else if (cValue === 'trueFunc') {
cValue = cloakFunc(function () { return true; });
} else if (cValue === 'falseFunc') {
cValue = cloakFunc(function () { return false; });
} else if (/^\d+$/.test(cValue)) {
cValue = parseFloat(cValue);
if (isNaN(cValue)) { return; }
if (Math.abs(cValue) > 0x7FFF) { return; }
} else {
return;
}
let aborted = false;
const mustAbort = function (v) {
if (aborted) { return true; }
aborted =
(v !== undefined && v !== null) &&
(cValue !== undefined && cValue !== null) &&
(typeof v !== typeof cValue);
return aborted;
};
// https://github.com/uBlockOrigin/uBlock-issues/issues/156
// Support multiple trappers for the same property.
const trapProp = function (owner, prop, configurable, handler) {
if (handler.init(owner[prop]) === false) { return; }
const odesc = Object.getOwnPropertyDescriptor(owner, prop);
let prevGetter, prevSetter;
if (odesc instanceof Object) {
owner[prop] = cValue;
if (odesc.get instanceof Function) {
prevGetter = odesc.get;
}
if (odesc.set instanceof Function) {
prevSetter = odesc.set;
}
}
try {
objectDefineProperty(owner, prop, {
configurable,
get() {
if (prevGetter !== undefined) {
prevGetter();
}
return handler.getter(); // cValue
},
set(a) {
if (prevSetter !== undefined) {
prevSetter(a);
}
handler.setter(a);
}
});
} catch (ex) {
}
};
const trapChain = function (owner, chain) {
const pos = chain.indexOf('.');
if (pos === -1) {
trapProp(owner, chain, false, {
v: undefined,
init: function (v) {
if (mustAbort(v)) { return false; }
this.v = v;
return true;
},
getter: function () {
return document.currentScript === thisScript
? this.v
: cValue;
},
setter: function (a) {
if (mustAbort(a) === false) { return; }
cValue = a;
}
});
return;
}
const prop = chain.slice(0, pos);
const v = owner[prop];
chain = chain.slice(pos + 1);
if (v instanceof Object || typeof v === 'object' && v !== null) {
trapChain(v, chain);
return;
}
trapProp(owner, prop, true, {
v: undefined,
init: function (v) {
this.v = v;
return true;
},
getter: function () {
return this.v;
},
setter: function (a) {
this.v = a;
if (a instanceof Object) {
trapChain(a, chain);
}
}
});
};
trapChain(window, chain);
}