-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnullplatform-chrome.js
48 lines (40 loc) · 1.55 KB
/
nullplatform-chrome.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
const copyButton = document.getElementById('copyButton');
document.addEventListener('DOMContentLoaded', function() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.scripting.executeScript({
target: {tabId: tabs[0].id},
function: getAccessToken
}, (results) => {
// Update popup UI with the token
const pat = results[0]?.result;
const title = document.getElementById('title');
const label = document.getElementById('token');
if(pat) {
title.style.visibility = "visible";
title.innerHTML = "Here is your <b>personal</b> access token:";
label.textContent = pat;
copyButton.style.visibility = "visible";
} else {
title.innerHTML = "No token found, is this a nullplatform tab where you're logged in?";
title.style.visibility = "visible";
label.style.display = "none";
copyButton.style.display = "none";
}
});
});
});
copyButton.addEventListener('click', function() {
var copyText = document.getElementById('token');
navigator.clipboard.writeText(copyText.textContent)
.then(() => {
copyButton.innerHTML = "Copy to clipboard ✓";
console.log('Text copied to clipboard');
})
.catch(err => {
console.error('Failed to copy text: ', err);
});
});
function getAccessToken() {
// Access local storage and return the accessToken
return localStorage.getItem('accessToken');
}