-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
205 lines (167 loc) · 5.97 KB
/
Copy pathbackground.js
File metadata and controls
205 lines (167 loc) · 5.97 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
const defaultOptions = {
'unused_menus': true,
'accounts_saveask': true,
'accounts_savepass': false,
'accounts_autosave': false,
'accounts_autoswitch': false,
'quick_withdraw_toggle': true,
'targetGroup': 0,
}
var updateCookie = false;
var accPassword = "";
async function storageGet(key) {
return new Promise((resolve, reject) =>
browser.storage.sync.get(key).then((result) => {
resolve(result[key])
}));
}
async function storageSet(key, value) {
return new Promise((resolve, reject) =>
browser.storage.sync.set({[key] : value}).then(() => {
resolve(value);
}));
}
async function returnIfNotExist(key, returnValue) {
let data = await storageGet(key);
if (typeof data !== 'undefined') {
return data;
} else {
return returnValue;
}
}
async function getCurrentTab() {
const response = await browser.tabs.query({ active: true, currentWindow: true });
if (response.length > 0) {
return response[0]
}
}
async function updateOptions(oldValue, defaultValue) {
let newOptions = oldValue
Object.keys(defaultValue).forEach(async (key) => {
if (!newOptions.hasOwnProperty(key)) {
newOptions[key] = defaultValue[key];
}
});
return newOptions;
}
async function openTab(url) {
browser.tabs.create({ url: browser.runtime.getURL(url) })
}
browser.runtime.onInstalled.addListener(async function(details){
let oldOptions = await returnIfNotExist('options', defaultOptions)
let newOptions = await updateOptions(oldOptions, defaultOptions)
await storageSet('options', newOptions)
console.log('updated options')
console.log(newOptions)
if (details.reason == "install") {
await storageSet('accounts', {})
openTab('onboarding.html')
}
});
async function httpGetAsync(url) {
return new Promise((resolve, reject) => {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
resolve(xmlHttp.responseText);
}
xmlHttp.open("GET", url, true); // true for asynchronous
xmlHttp.send(null);
})
}
async function getCookie(key) {
const cookie = await browser.cookies.get({
url: "https://www.roblox.com",
name: key
});
return cookie
}
async function setCookie(key, value) {
updateCookie = true;
const futureDate = new Date();
futureDate.setFullYear(futureDate.getFullYear() + 30);
const expirationDate = Math.floor(futureDate.getTime() / 1000);
await browser.cookies.set({
url: "https://www.roblox.com",
domain: ".roblox.com",
name: key,
value: value,
httpOnly: true,
sameSite: "no_restriction",
secure: true,
expirationDate: expirationDate
});
}
async function saveAccount(password, savePass) {
var cookie = await getCookie('.ROBLOSECURITY')
if (cookie && cookie.value && cookie.value != "") {
const cookieData = cookie.value
console.log(cookieData)
const http = await httpGetAsync("https://users.roblox.com/v1/users/authenticated")
const account = JSON.parse(http)
console.log(account)
var accountsData = await storageGet('accounts')
if (!savePass) {
password = "unsaved"
}
accountsData[account.id] = {cookie: cookieData, id: account.id, username: account.name, displayName: account.displayName, password: password}
await storageSet('accounts', accountsData)
console.log(`saved account ${account.name}`)
console.log(accountsData)
} else {
console.log("delaying")
console.log(cookie.value)
setTimeout(saveAccount, 5000, password, savePass)
}
}
var debounce = false;
browser.cookies.onChanged.addListener(async (changeInfo) => {
if (changeInfo.cookie.name === '.ROBLOSECURITY' && changeInfo.cookie.domain === ".roblox.com" && !changeInfo.removed) {
if (debounce == false) {
debounce = true;
if (!updateCookie) {
console.log("cookie updated")
console.log(changeInfo.cookie.value)
const options = await storageGet('options')
var ifSaveAcc
if (!options.accounts_autosave) {
await new Promise(resolve => setTimeout(resolve, 5000));
const tab = await getCurrentTab()
ifSaveAcc = await browser.tabs.sendMessage(tab.id, {type: 'confirmationPopup', data: { text: 'Would you like to save this account to RobloxTools?'}})
} else {
ifSaveAcc = true;
}
if (ifSaveAcc) {
console.log(options.accounts_savepass)
saveAccount(accPassword, options.accounts_savepass);
}
}
else {
updateCookie = false;
}
setTimeout(() => {debounce = false}, 1000)
}
}
});
browser.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
if (message.type === "resetSettings") {
await storageSet('options', defaultOptions)
//data
} else if (message.type === "getData") {
const data = await storageGet(message.data.key)
return data;
} else if (message.type === "setData") {
await storageSet(message.data.key, message.data.value)
/*} else if (message.type == "saveAccount") {
console.log("saving account")
setTimeout(saveAccount, 5000, message.data.password, message.data.savePass)*/
} else if (message.type === "openTab") {
openTab(message.data)
} else if (message.type === "setCookie") {
await setCookie(message.data.key, message.data.value)
return true
} else if (message.type === "sendPassword") {
console.log(`recieved password ${message.data.password}`)
accPassword = message.data.password
}
});