Created
March 26, 2025 20:52
-
-
Save RKursatV/2d1d2902d62b5890d8f2de946f020264 to your computer and use it in GitHub Desktop.
apply session details
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const session_storage_data = {}; | |
| const local_storage_data = {}; | |
| const cookie_data = ""; | |
| function setSessionStorage(session_storage_data) { | |
| try { | |
| for (const [key, value] of Object.entries(session_storage_data)) { | |
| sessionStorage.setItem(key, JSON.stringify(value)); | |
| } | |
| console.log('Session storage data applied successfully'); | |
| } catch (error) { | |
| console.error('Error setting session storage:', error); | |
| } | |
| } | |
| function setLocalStorage(local_storage_data) { | |
| try { | |
| for (const [key, value] of Object.entries(local_storage_data)) { | |
| localStorage.setItem(key, JSON.stringify(value)); | |
| } | |
| console.log('Local storage data applied successfully'); | |
| } catch (error) { | |
| console.error('Error setting local storage:', error); | |
| } | |
| } | |
| function setCookies(cookie_string) { | |
| try { | |
| const cookiePairs = cookie_string.split('; ').map(pair => pair.trim()); | |
| cookiePairs.forEach(pair => { | |
| const [key, value] = pair.split('='); | |
| if (key && value) { | |
| // Default cookie settings: expires in 7 days | |
| const expires = new Date(); | |
| expires.setDate(expires.getDate() + 7); | |
| document.cookie = `${key}=${encodeURIComponent(value)}; expires=${expires.toUTCString()}; path=/`; | |
| } | |
| }); | |
| console.log('Cookies applied successfully'); | |
| } catch (error) { | |
| console.error('Error setting cookies:', error); | |
| } | |
| } | |
| function applyAllStorage() { | |
| setSessionStorage(session_storage_data); | |
| setLocalStorage(local_storage_data); | |
| setCookies(cookie_data); | |
| } | |
| function verifyStorage() { | |
| console.log('Session Storage:', Object.fromEntries(Object.entries(sessionStorage))); | |
| console.log('Local Storage:', Object.fromEntries(Object.entries(localStorage))); | |
| console.log('Cookies:', document.cookie); | |
| } | |
| applyAllStorage(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment