forked from uptechteam/default.wtf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoffscreen.js
More file actions
32 lines (28 loc) · 1005 Bytes
/
offscreen.js
File metadata and controls
32 lines (28 loc) · 1005 Bytes
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
// Offscreen document for parsing Google accounts response
// DOMParser is not available in service workers, so we use this offscreen document
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'parse_accounts') {
try {
const parser = new DOMParser();
const doc = parser.parseFromString(message.rawText, 'application/xml');
const scriptElement = doc.querySelector('script');
if (!scriptElement) {
sendResponse({ error: 'No script element found' });
return;
}
const html = scriptElement.innerHTML;
const parsed = html
.split("'")[1]
.replace(/\\x([0-9a-fA-F]{2})/g, (match, paren) =>
String.fromCharCode(parseInt(paren, 16))
)
.replace(/\\\//g, '/')
.replace(/\\n/g, '');
const result = JSON.parse(parsed);
sendResponse({ result });
} catch (error) {
sendResponse({ error: error.message });
}
return true;
}
});