Repository navigation
Expand file tree
/
Copy pathpopup.js
More file actions
181 lines (163 loc) · 7.23 KB
/
Copy pathpopup.js
File metadata and controls
181 lines (163 loc) · 7.23 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Copyright 2022 BadAimWeeb. All rights reserved. MIT license.
var stringToBlob = function (str, mimetype) {
var raw = str;
var rawLength = raw.length;
var uInt8Array = new Uint8Array(rawLength);
for (var i = 0; i < rawLength; ++i) {
uInt8Array[i] = raw.charCodeAt(i);
}
var bb = new Blob([uInt8Array.buffer], {
type: mimetype
});
return bb;
};
window.onload = function () {
function importFunc(e, encrypted) {
if (e.currentTarget.files[0]) {
console.log(e.currentTarget.files[0]);
if (e.currentTarget.files[0].type != "application/json") {
alert("Invalid file given");
}
var fr = new FileReader();
fr.readAsText(e.currentTarget.files[0], "UTF-8");
fr.onload = function (evt) {
try {
let data = evt.target.result;
if (encrypted) {
// Asking for key
let pwdKey = prompt("Please enter key to encrypt:");
let keyHash = [...sha256(pwdKey || "").match(/.{2}/g)].map(e => parseInt(e, 16));
let bytes = aesjs.utils.hex.toBytes(data);
let aesCtr = new aesjs.ModeOfOperation.ctr(keyHash);
let decryptedData = aesCtr.decrypt(bytes);
data = aesjs.utils.utf8.fromBytes(decryptedData);
}
var j = JSON.parse(data);
if (Array.isArray(j)) {
chrome.cookies.getAll({
domain: "facebook.com"
}, async function (cookies) {
for (let i in cookies) {
await new Promise(resolve => {
chrome.cookies.remove({
url: `https://facebook.com${cookies[i].path}`,
name: cookies[i].name
}, resolve);
});
}
for (let i in j) {
if (j[i].domain == "facebook.com") {
await new Promise(resolve => {
chrome.cookies.set({
url: `https://facebook.com${j[i].path}`,
name: j[i].key,
value: j[i].value,
expirationDate: (Date.now() / 1000) + (84600 * 30),
domain: ".facebook.com"
}, resolve);
});
}
}
chrome.tabs.query({
active: true
}, function (tabs) {
var {
host
} = new URL(tabs[0].url);
if (host.split(".")[1] == "facebook") {
chrome.tabs.update(tabs[0].id, {
url: tabs[0].url
});
}
});
});
} else {
alert("Invalid JSON file (not a FBState JSON file).");
}
} catch (_) {
alert("Failed to load JSON file (malformed?)");
}
}
}
}
function exportFunc(encrypted) {
chrome.cookies.getAll({
domain: "facebook.com"
}, function (cookies) {
var cok = cookies.map(v => ({
key: v.name,
value: v.value,
domain: "facebook.com",
path: v.path,
hostOnly: v.hostOnly,
creation: new Date().toISOString(),
lastAccessed: new Date().toISOString()
}));
var fbstate = JSON.stringify(cok, null, 4);
if (encrypted) {
// Asking for key
let pwdKey = prompt("Please enter key to encrypt:");
let keyHash = [...sha256(pwdKey || "").match(/.{2}/g)].map(e => parseInt(e, 16));
let bytes = aesjs.utils.utf8.toBytes(fbstate);
let aesCtr = new aesjs.ModeOfOperation.ctr(keyHash);
let encryptedData = aesCtr.encrypt(bytes);
fbstate = aesjs.utils.hex.fromBytes(encryptedData);
}
const yourFbstate = document.getElementById("yourFbstate");
const btnCopy = document.getElementById("btnCopy");
const btnDownload = document.getElementById("btnDownload");
yourFbstate.value = fbstate;
btnCopy.onclick = function () {
yourFbstate.select();
document.execCommand("copy");
window.alert('Success! The fbstate was copied to your clipboard');
};
btnDownload.onclick = function () {
var blob = stringToBlob(fbstate, "application/json");
var url = window.webkitURL || window.URL || window.mozURL || window.msURL;
var a = document.createElement('a');
a.download = 'fbstate.json';
a.href = url.createObjectURL(blob);
a.textContent = '';
a.dataset.downloadurl = ['json', a.download, a.href].join(':');
a.click();
a.remove();
};
});
}
function logout() {
const result = confirm("Are you sure you want to logout?");
if (result) {
chrome.cookies.getAll({
domain: "facebook.com"
}, function (cookies) {
// * it helps you not to lose the list of recently logged in accounts
cookies = cookies.filter(c => c.name != "sb" && c.name != "dbln");
for (let i in cookies) {
chrome.cookies.remove({
url: `https://facebook.com${cookies[i].path}`,
name: cookies[i].name
});
}
chrome.tabs.query({
active: true
}, function (tabs) {
var {
host
} = new URL(tabs[0].url);
if (host.split(".")[1] == "facebook") {
chrome.tabs.update(tabs[0].id, {
url: tabs[0].url
});
}
});
});
}
}
document.getElementById("import").onchange = (e) => importFunc(e, false);
document.getElementById("importenc").onchange = (e) => importFunc(e, true);
document.getElementById("export").onclick = () => exportFunc(false);
document.getElementById("exportenc").onclick = () => exportFunc(true);
document.getElementById("logout").onclick = () => logout();
exportFunc(false);
};