-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
32 lines (29 loc) · 1.17 KB
/
Copy pathbackground.js
File metadata and controls
32 lines (29 loc) · 1.17 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
// Listen for message from popup
chrome.runtime.onMessage.addListener((data, sender, sendResponse) => {
// Get list of Google accounts
fetch('https://accounts.google.com/ListAccounts?gpsia=1&source=ogb&mo=1&origin=https://accounts.google.com')
.then(response => (
response.text()
))
.then(rawText => (
// Parse HTML to get the inner JS script text
new DOMParser()
.parseFromString(rawText, 'application/xml')
.querySelector('script')
.innerHTML
// Get the first tokenized string in the JS
.split('\'')[1]
// Replace JS string hex escapes (best way unfortunately, no built in function for this like for decodeURI)
.replace(/\\x([0-9a-fA-F]{2})/g, (match, paren) => (
String.fromCharCode(parseInt(paren, 16))
))
// Replace JS string slash and newline escapes
.replace(/\\\//g, '\/')
.replace(/\\n/g, '')
))
.then(text => (
JSON.parse(text)
))
.then(sendResponse);
return true // Indicates async response
});