Skip to content

Instantly share code, notes, and snippets.

@deadflowers
Created February 26, 2025 17:25
Show Gist options
  • Save deadflowers/adf36bbe09c74063bbdb77bd1a8d8865 to your computer and use it in GitHub Desktop.
Save deadflowers/adf36bbe09c74063bbdb77bd1a8d8865 to your computer and use it in GitHub Desktop.
Cookie Flip Get Cookies as Netscape File

Cookie Flip Netscape

This is going to need revisiting it came up flipping through history in my devtools. I remember the project, yt-dlp complications when youtube wants to verify a user. especialy a challenge on a remove terminal or android termux. latest patch seems to have fixed that but ive not used it much. my thinking is if the file can be created in netscape format (there are libraries to incorporate on my github if all else and original code fails) and it pleases youtube, then add as a funciton into my webterminal. makes for a sick demo video of use cases. BUT another prob is that the terminal doesnt load on youtube in the newest chrome with all the security nonsense. Complications bumped this so low on my todo that it was basically hucked in the trash if not for scrolling through my history looking for a command. Here it sits until whenever and i dont know what version of whatever this is, is. Just that it spins around and spits out what looks like netscape formatted to me...

javascript:(function() {
  // Function to collect cookies in Netscape format
  function getNetscapeCookies() {
    const cookies = document.cookie.split(';');
    const netscapeCookies = [];

    for (let i = 0; i < cookies.length; i++) {
      const cookie = cookies[i].trim();
      const [name, value] = cookie.split('=');

      const domain = window.location.hostname; 
      const flag = 'FALSE';
      const path = '/'; 
      const secure = 'FALSE';
      const expiration = Math.floor(Date.now() / 1000) + 3600; 

      const netscapeCookie = `${domain}\t${flag}\t${path}\t${secure}\t${expiration}\t${name.trim()}\t${value.trim()}`;
      netscapeCookies.push(netscapeCookie);
    }

    return netscapeCookies.join('\n');
  }

  const netscapeCookies = getNetscapeCookies();

  // Create a Blob from the cookies for download
  const blob = new Blob([netscapeCookies], { type: 'text/plain' });
  const link = document.createElement('a');
  link.href = URL.createObjectURL(blob);
  link.download = 'cookies.txt';
  link.click();

  // Create the page overlay to display cookies with a 3D flip effect
  const overlay = document.createElement('div');
  overlay.style.position = 'fixed';
  overlay.style.top = '0';
  overlay.style.left = '0';
  overlay.style.width = '100vw';
  overlay.style.height = '100vh';
  overlay.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
  overlay.style.color = 'white';
  overlay.style.display = 'flex';
  overlay.style.justifyContent = 'center';
  overlay.style.alignItems = 'center';
  overlay.style.fontFamily = 'monospace';
  overlay.style.fontSize = '16px';
  overlay.style.overflow = 'auto';
  overlay.style.transformStyle = 'preserve-3d';
  overlay.style.perspective = '1000px';
  overlay.style.transition = 'transform 1s';

  const contentDiv = document.createElement('div');
  contentDiv.style.position = 'absolute';
  contentDiv.style.width = '90%';
  contentDiv.style.height = '90%';
  contentDiv.style.transformStyle = 'preserve-3d';
  contentDiv.style.transition = 'transform 1s';
  contentDiv.style.padding = '20px';
  contentDiv.style.backgroundColor = '#222';
  contentDiv.style.borderRadius = '10px';
  contentDiv.style.boxShadow = '0px 0px 20px rgba(0,0,0,0.5)';
  contentDiv.style.transform = 'rotateY(0deg)';
  contentDiv.innerHTML = `<pre>${netscapeCookies}</pre>`;

  overlay.appendChild(contentDiv);
  document.body.appendChild(overlay);

  // Trigger a 3D flip animation after adding the overlay
  setTimeout(() => {
    contentDiv.style.transform = 'rotateY(180deg)';
  }, 100);

  // Hide the overlay after the animation completes
  setTimeout(() => {
    overlay.style.display = 'none';
  }, 2000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment