-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiqiyi_init.js
More file actions
50 lines (46 loc) · 1.41 KB
/
Copy pathiqiyi_init.js
File metadata and controls
50 lines (46 loc) · 1.41 KB
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
// 修改script element行为
(function() {
var func = function() {
var setter = HTMLScriptElement.prototype.__lookupSetter__('src');
Object.defineProperty(HTMLScriptElement.prototype, 'src', {
set: function(url) {
if (url.indexOf('http://cache.m.iqiyi.com/jp/tmts/') === 0) {
var match = /callback=([^&]+)/.exec(url);
if (match) {
var callback = match[1];
if (!window['_' + callback] && window[callback]) {
window['_' + callback] = window[callback];
window[callback] = function(data) {
if (data.data) {
data.status = 'A00015';
data.data.ds = 'A00015';
}
return window['_' + callback](data);
};
}
}
}
setter.apply(this, Array.prototype.slice.call(arguments));
}
});
};
var observer = new MutationObserver(function(mutations, observer) {
mutations.forEach(function(mutation) {
for (var index = 0; index < mutation.addedNodes.length; ++index) {
var node = mutation.addedNodes.item(index);
if (node.tagName == 'HEAD') {
var script = document.createElement('script');
script.innerHTML = '(' + func.toString() + ')()';
if (node.firstChild) {
node.insertBefore(script, node.firstChild);
} else {
node.appendChild(script);
}
observer.disconnect();
break;
}
}
});
});
observer.observe(document.documentElement, {childList: true, subtree: true});
})();