Advertisement
prabapro

Finesweet Cookie Variable

Sep 14th, 2023
829
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function() {
  2.   var urlEncodedJson = {{cookie - fs-cc}};
  3.  
  4.   // Decode the URL-encoded JSON twice to get valid JSON
  5.   var decodedJson = JSON.parse(decodeURIComponent(decodeURIComponent(urlEncodedJson)));
  6.  
  7.   // Helper function to serialize an object with pipes and commas
  8.   function serializeObject(obj) {
  9.     var serialized = [];
  10.     for (var key in obj) {
  11.       if (obj.hasOwnProperty(key)) {
  12.         serialized.push(key + ':' + (typeof obj[key] === 'object' ? serializeObject(obj[key]) : obj[key]));
  13.       }
  14.     }
  15.     return serialized.join('|');
  16.   }
  17.  
  18.   // Serialize the object with properties separated by pipes and commas
  19.   var serializedString = Object.keys(decodedJson).map(function(key) {
  20.     return key + ':' + (key === 'consents' ? serializeObject(decodedJson[key]) : decodedJson[key]);
  21.   }).join('|');
  22.  
  23.   // Return the serialized string
  24.   return serializedString;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement