| 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], |
| }); |
|
|