File size: 3,789 Bytes
3d7d9b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/// json-prune.js
(function() {
    'use strict';
    const args = Array.from(arguments);
    const prunePaths = (args[0] || '').split(/\s+/).filter(Boolean);
    if (prunePaths.length === 0) return;
    function prune(obj, path) {
        if (!obj || typeof obj !== 'object') return;
        const parts = path.split('.');
        let target = obj;
        for (let i = 0; i < parts.length - 1; i++) {
            const part = parts[i];
            if (part.endsWith('[]')) {
                const key = part.slice(0, -2);
                if (Array.isArray(target[key])) {
                    target[key].forEach(item => prune(item, parts.slice(i + 1).join('.')));
                }
                return;
            }
            if (!target[part]) return;
            target = target[part];
        }
        delete target[parts[parts.length - 1]];
    }
    function pruneAll(obj) { for (const p of prunePaths) prune(obj, p); return obj; }
    const jp = JSON.parse;
    JSON.parse = function() { return pruneAll(jp.apply(this, arguments)); };
    const rj = Response.prototype.json;
    Response.prototype.json = function() { return rj.apply(this, arguments).then(pruneAll); };
})();

/// set-constant.js
(function() {
    'use strict';
    const prop = arguments[0];
    const raw = arguments[1];
    if (!prop) return;
    let value;
    if (raw === 'undefined') value = undefined;
    else if (raw === 'false') value = false;
    else if (raw === 'true') value = true;
    else if (raw === 'null') value = null;
    else value = raw;
    const parts = prop.split('.');
    let obj = window;
    for (let i = 0; i < parts.length - 1; i++) {
        obj = obj[parts[i]] = obj[parts[i]] || {};
    }
    try {
        Object.defineProperty(obj, parts[parts.length - 1], { get: () => value, set: () => {}, configurable: true });
    } catch {}
})();

/// abort-current-script.js
(function() {
    'use strict';
    const needle = arguments[0] || '';
    const prop = arguments[1] || '';
    if (!needle && !prop) return;
    const re = new RegExp(needle);
    const oe = document.createElement.bind(document);
    document.createElement = function(tag) {
        const el = oe(tag);
        if (String(tag).toLowerCase() === 'script') {
            const set = el.setAttribute.bind(el);
            el.setAttribute = function(name, value) {
                if (name === 'src' && re.test(String(value))) return;
                return set(name, value);
            };
        }
        return el;
    };
})();

/// prevent-fetch.js
(function() {
    'use strict';
    const needle = arguments[0] || '';
    if (!needle) return;
    const re = new RegExp(needle);
    const of = window.fetch;
    window.fetch = function(input, init) {
        const url = typeof input === 'string' ? input : input && input.url || '';
        if (re.test(url)) return Promise.resolve(new Response('', { status: 204 }));
        return of.apply(this, arguments);
    };
})();

/// m3u8-prune.js
(function() {
    'use strict';
    const needle = arguments[0] || 'stitched-ad|advertisement|DATERANGE';
    const re = new RegExp(needle);
    const of = window.fetch;
    window.fetch = function(input, init) {
        const url = typeof input === 'string' ? input : input && input.url || '';
        return of.apply(this, arguments).then(resp => {
            if (!String(url).includes('.m3u8')) return resp;
            return resp.clone().text().then(text => {
                const out = text.split('\n').filter(line => !re.test(line)).join('\n');
                return new Response(out, { status: resp.status, headers: resp.headers });
            }).catch(() => resp);
        });
    };
})();