-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
66 lines (63 loc) · 2.64 KB
/
popup.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
let stringToBlob = function (str, mimetype) {
let raw = str;
let rawLength = raw.length;
let uInt8Array = new Uint8Array(rawLength);
for (let i = 0; i < rawLength; ++i) {
uInt8Array[i] = raw.charCodeAt(i);
}
let bb = new Blob([uInt8Array.buffer], {
type: mimetype
});
return bb;
};
function bardCookies(){
function toastNotification(message) {
let x = document.getElementById("snackbar");
x.addEventListener("click", function() {
x.className = x.className.replace("show", "");
});
x.innerHTML = message;
x.className = "show";
setTimeout(function () {
x.className = x.className.replace("show", "");
}, 3000);
}
chrome.tabs.executeScript({
code: 'performance.getEntriesByType("resource").map(e => e.name)',
}, data => {
if (chrome.runtime.lastError || !data || !data[0]) return;
let urls = data[0].map(url => url.split(/[#?]/)[0]);
let uniqueUrls = [...new Set(urls).values()].filter(Boolean);
Promise.all(uniqueUrls.map(url =>new Promise(resolve => {
chrome.cookies.getAll({url}, resolve);
}))).then(results => {
let session = [
...new Map([].concat(...results).map(c => [JSON.stringify(c), c])).values()
];
session = session.filter(e=>e.name==='__Secure-1PSID')
let cookies = JSON.stringify(session,null,4);
cooki = document.getElementById("cookies");
cooki.value = cookies;
let btnCopy = document.getElementById("btnCopy");
let btnDownload = document.getElementById("btnDownload");
btnCopy.onclick = function () {
cooki.select();
document.execCommand("copy");
toastNotification('Success! The BardAI Session was copied to your clipboard!');
};
btnDownload.onclick = function () {
let blob = stringToBlob(cookies, "application/json");
let url = window.webkitURL || window.URL || window.mozURL || window.msURL;
let a = document.createElement('a');
a.download = 'bardSession.json';
a.href = url.createObjectURL(blob);
a.textContent = '';
a.dataset.downloadurl = ['json', a.download, a.href].join(':');
a.click();
toastNotification('Success! The BardAI Session was downloaded ' + a.download);
a.remove();
};
});
});
}
window.onload=bardCookies;