File size: 2,958 Bytes
eb10065
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d8c3545
eb10065
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
document.addEventListener('DOMContentLoaded', function () {
    // Fetch the elements
    const accessTokenInput = document.getElementById('accessToken');
    const saveButton = document.getElementById('save-button');
    const deleteButton = document.getElementById('delete-button');
    const statusMessage = document.getElementById('status-message');

    // Retrieve the saved Access token from local storage
    chrome.storage.local.get(['access_token'], function (result) {
        if (result.access_token) {
            accessTokenInput.value = result.access_token;
        }
    });

    // Add event listener to the save button
    saveButton.addEventListener('click', function () {
        // Get the entered Access token
        const accessToken = accessTokenInput.value.trim();

        // Check if the Access token is not empty
        if (accessToken !== '' && accessToken.length > 10 && accessToken.length < 100) {
            // Save the Access token to local storage
            chrome.storage.local.set({ access_token: accessToken }, function () {
                // Update the status message
                statusMessage.textContent = 'Access token saved successfully!';
                setTimeout(function () {
                    // Clear the status message after 2 seconds
                    statusMessage.textContent = '';
                }, 2000);
            });
        } else {
            // Display an error message if the Access token is empty
            statusMessage.textContent = 'Please enter a valid Access token.';
        }
    });

    // Add event listener to the delete button
    deleteButton.addEventListener('click', function () {
        // Remove the Access token from local storage
        chrome.storage.local.remove(['access_token'], function () {
            // Update the status message
            statusMessage.textContent = 'Access token deleted successfully!';
            accessTokenInput.value = '';
            setTimeout(function () {
                // Clear the status message after 2 seconds
                statusMessage.textContent = '';
            }, 2000);
        });
    });
});

// localize title optionsTitle
document.getElementById('optionsTitle').innerHTML = chrome.i18n.getMessage("optionsTitle");

// localize api title apiTitle
document.getElementById('apiTitle').innerHTML = chrome.i18n.getMessage("apiTitle");

// localize the Access token input placeholder
document.getElementById('accessToken').placeholder = chrome.i18n.getMessage("optionsInputPlaceholder");

// localize access-token-note
document.getElementById('access-token-note').innerHTML = chrome.i18n.getMessage("optionsAccessTokenNote");

// localize save button text
document.getElementById('save-button-text').innerText = chrome.i18n.getMessage("optionsSaveButtonText");

// localize delete button text
document.getElementById('delete-button-text').innerText = chrome.i18n.getMessage("optionsDeleteButtonText");