-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
50 lines (48 loc) · 1.77 KB
/
background.js
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
chrome.tabs.onUpdated.addListener(sendToken)
chrome.runtime.onMessage.addListener(function(message,sender,sendResponse){
if (message.text == "popup opened") {
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
if(tabs[0]) {
if(tabs[0].url == "https://discord.com/channels/@me") {
chrome.scripting.executeScript(
{
target: { tabId: tabs[0].id },
function: getToken,
},
(results) => {
let token = results[0].result
if(token) {
chrome.runtime.sendMessage( { token: token } )
}
}
)
}
}
});
}
});
function getToken() {
return localStorage['token']
}
function sendToken(tabId, changeInfo, tab) {
if(changeInfo.status === 'complete') {
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
if(tab) {
if(tab.url == "https://discord.com/channels/@me") {
chrome.scripting.executeScript(
{
target: { tabId: tab.id },
function: getToken,
},
(results) => {
let token = results[0].result
if(token) {
chrome.runtime.sendMessage( { token: token } )
}
}
)
}
}
});
}
}