Skip to content
This repository has been archived by the owner on Jan 11, 2025. It is now read-only.

Commit

Permalink
Create restore old accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
iKingNinja committed Jul 26, 2022
1 parent 961e4dc commit 9fe9e4f
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 4 deletions.
31 changes: 28 additions & 3 deletions source/index.js → source/background/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
importScripts('./loadCached.js');

//Functions

async function getCurrentCookie() {
Expand Down Expand Up @@ -121,8 +123,6 @@ async function promptSave(details, tabId) {
}
})

console.log(saveDecision);

if (saveDecision[0]) {
const userId = userData.UserId;
const avatarRes = await fetch(`https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds=${userId}&size=48x48&format=Png&isCircular=false`).catch((error) => {
Expand Down Expand Up @@ -274,6 +274,32 @@ function logWarning() {

//Events

chrome.runtime.onInstalled.addListener(async () => {
const oldCookiesFound = await scanForOldCookies();

if (oldCookiesFound) {
chrome.tabs.query({currentWindow: true}, async (tabs) => {
const robloxTabs = tabs.filter(tab => tab.url.includes('https://www.roblox.com'));

if (robloxTabs.length > 0) {
const firstTab = robloxTabs[0];
const tabId = firstTab.id;

const restoreDecision = await chrome.scripting.executeScript({
target: {tabId: tabId},
func: function() {
return window.confirm('Previously saved accounts were found: do you want to restore them?')
}
})

if (restoreDecision[0].result) {
restoreOldAccounts();
}
}
})
}
})

chrome.tabs.onUpdated.addListener((id, info) => {
if (info.status == 'complete') {
injectPopup();
Expand All @@ -296,7 +322,6 @@ chrome.webRequest.onCompleted.addListener(async (details) => {
}

async function onLoginUpdated(tabId, info) {
console.log(tabId, info);
if (info.status == 'complete' && tabId == id) {
chrome.tabs.onUpdated.removeListener(onLoginUpdated);

Expand Down
60 changes: 60 additions & 0 deletions source/background/loadCached.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
async function getExtensionCookies() {
return chrome.cookies.getAll({url: 'https://www.roblox.com'}).then((cookies) => cookies.filter(cookie => cookie.name.includes('AM.ROBLOSECURITY')));
}

async function scanForOldCookies() {
let cookies = await getExtensionCookies();
cookies = cookies.filter(cookie => cookie.name.includes('AM.ROBLOSECURITY'));

if (cookies.length > 0) {
return true;
} else {
return false;
}
}

async function restoreOldAccounts() {
const cookies = await getExtensionCookies();
const savedAccounts = await getSavedAccounts() || {};
const accounts = savedAccounts.accounts || {};

for (const cookie of cookies) {
const value = cookies.value;

const accountDataRes = await fetch('https://www.roblox.com/my/account/json', {
headers: {
Cookie: `.ROBLOSECURITY=${value}`
}
});

if (!accountDataRes.ok) {
continue;
}

const accountDataJson = await accountDataRes.json();

const userId = accountDataJson.UserId;
const username = accountDataJson.Name;

const avatarHeadshotURLRes = await fetch(`https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds=${userId}&size=48x48&format=Png&isCircular=false`).catch((err) => {
console.log(err);
})

if (!avatarHeadshotURLRes.ok) {
continue;
}

const avatarHeadshotURLJson = await avatarHeadshotURLRes.json();
const avatarURL = avatarHeadshotURLJson.data[0].imageUrl;

const data = {
userId: userId,
username: username,
avatarHeadshotURL: avatarURL
}

accounts[userId] = data;
}

chrome.storage.sync.set({accounts: accounts});
}
2 changes: 1 addition & 1 deletion source/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.1",
"manifest_version": 3,
"background": {
"service_worker": "index.js"
"service_worker": "background/index.js"
},
"permissions": [
"storage",
Expand Down

0 comments on commit 9fe9e4f

Please sign in to comment.