File size: 2,456 Bytes
939831a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const fs = require('fs');
const path = 'C:/Users/user/Documents/מעקף פרוקסי 2.0/worker.js';
let w = fs.readFileSync(path, 'utf8').replace(/^\uFEFF/, '');
const cookieLine = fs
  .readFileSync('C:/Users/user/Documents/מעקף פרוקסי 2.0/builtin_yt_cookies.inc.js', 'utf8')
  .trim();

w = w.replace(/const SW_VERSION = \d+;/, 'const SW_VERSION = 86;');

if (!w.includes('BUILTIN_YOUTUBE_COOKIE')) {
  w = w.replace(
    /const GATE_PEPPER = 'etrog-gate-v1-antigravity';[^\n]*/,
    (m) =>
      m +
      '\n\n// Built-in YouTube cookies (from user cookies.txt) — always available\n' +
      cookieLine
  );
}

const newFn = `async function getYoutubeCookieHeader(request) {
  const parts = [];
  const pushHdr = (hdr) => {
    if (!hdr) return;
    for (const piece of String(hdr).split(';')) {
      const t = piece.trim();
      if (t && t.includes('=')) parts.push(t);
    }
  };
  // 1) Built-in cookies first (always on — no manual import needed)
  if (typeof BUILTIN_YOUTUBE_COOKIE === 'string' && BUILTIN_YOUTUBE_COOKIE.length > 20) {
    pushHdr(BUILTIN_YOUTUBE_COOKIE);
  }
  // 2) Cache imports (optional override)
  for (const d of ['www.youtube.com', 'youtube.com', '.youtube.com']) {
    try {
      const c = await getCookiesFromCache(d);
      const hdr = normalizeCookieTextToHeader(c);
      if (hdr && hdr.length > 20) pushHdr(hdr);
    } catch {}
  }
  // 3) Request virtualized cookies (optional override)
  try {
    const raw = (request && request.headers.get('cookie')) || '';
    if (raw) {
      const built = buildTargetCookies(raw, new URL('https://www.youtube.com/'), true);
      pushHdr(built.join('; '));
    }
  } catch {}
  // Dedupe by cookie name (later overrides earlier)
  const map = new Map();
  for (const p of parts) {
    const eq = p.indexOf('=');
    if (eq === -1) continue;
    map.set(p.slice(0, eq).trim(), p.slice(eq + 1).trim());
  }
  if (!map.has('CONSENT')) map.set('CONSENT', 'YES+cb.20210328-17-p0.en+FX+667');
  if (!map.has('SOCS')) map.set('SOCS', 'CAE=');
  return [...map.entries()].map(([k, v]) => k + '=' + v).join('; ');
}`;

const re = /async function getYoutubeCookieHeader\(request\) \{[\s\S]*?\n\}/;
if (!re.test(w)) {
  console.error('getYoutubeCookieHeader not found');
  process.exit(1);
}
w = w.replace(re, newFn);
fs.writeFileSync(path, w);
console.log('OK', {
  hasCookie: w.includes('BUILTIN_YOUTUBE_COOKIE'),
  sw: /const SW_VERSION = (\d+)/.exec(w)?.[1],
});