ToKeiChun

Cookie to JSON Converter

May 17th, 2023 (edited)
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // this code is from : https://leaksradar.com/converter
  2. function addCookieToArr(cookieStr, arrObjects) {
  3.   var kuka = cookieStr.split("\t");
  4.  
  5.   if (kuka.length > 6) {
  6.     var cook = new Object();
  7.     cook.domain = kuka[0];
  8.     cook.expirationDate = parseInt(kuka[4]);
  9.     cook.httpOnly = kuka[1] === "TRUE";
  10.     cook.name = kuka[5];
  11.     cook.path = kuka[2];
  12.     cook.secure = kuka[3] === "TRUE";
  13.     cook.value = kuka[6];
  14.     arrObjects.push(cook);
  15.   }
  16. }
  17.  
  18. function NetscapeToJson(cookieStr) {
  19.   var arrObjects = [];
  20.   var cookieStrings = cookieStr.trim().split("\n");
  21.  
  22.   for (var i = 0; i < cookieStrings.length; i++) {
  23.     addCookieToArr(cookieStrings[i], arrObjects);
  24.   }
  25.  
  26.   var cookieStr = JSON.stringify(arrObjects);
  27.   return cookieStr;
  28. }
  29.  
  30. // Call the function and pass the cookie strings as a single string input
  31. var cookieStr = `.netflix.com   TRUE    /   FALSE   1693188644  nfvdid  xxxxxxx
  32. .netflix.com    TRUE    /   FALSE   1697318415  memclid xxxxxxx
  33. .netflix.com    TRUE    /   FALSE   1701284757  NetflixId   xxxxxxx
  34. .netflix.com    TRUE    /   FALSE   1701284757  SecureNetflixId xxxxxxx`;
  35. var result = NetscapeToJson(cookieStr);
  36. console.log(result);
Add Comment
Please, Sign In to add comment