-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
38 lines (33 loc) · 1.67 KB
/
popup.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
// popup.js
// Add event listener to save the clientId to local storage when the user types in the clientId field.
document.getElementById('clientId').addEventListener('input', function() {
const clientId = this.value;
chrome.storage.local.set({'clientId': clientId});
});
// Add event listener to save the clientSecret to local storage when the user types in the clientSecret field.
document.getElementById('clientSecret').addEventListener('input', function() {
const clientSecret = this.value;
chrome.storage.local.set({'clientSecret': clientSecret});
});
// Load and populate the clientId and clientSecret fields from local storage when the popup is opened.
document.addEventListener('DOMContentLoaded', function() {
chrome.storage.local.get(['clientId', 'clientSecret'], function(result) {
if (result.clientId) {
document.getElementById('clientId').value = result.clientId;
}
if (result.clientSecret) {
document.getElementById('clientSecret').value = result.clientSecret;
}
});
});
// Add event listener to calculate the encoded credentials when the user clicks the calculate button.
document.getElementById('calculate').addEventListener('click', () => {
const clientId = document.getElementById('clientId').value;
const clientSecret = document.getElementById('clientSecret').value;
const encodedAuth = window.encodeCredentials(clientId, clientSecret);
document.getElementById('result').textContent = `Basic ${encodedAuth}`;
});
// Load the authUtils.js script to make the encodeCredentials function available.
const authScript = document.createElement('script');
authScript.src = 'authUtils.js';
document.head.appendChild(authScript);