-
Notifications
You must be signed in to change notification settings - Fork 4
/
options.js
70 lines (57 loc) · 2.23 KB
/
options.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
document.addEventListener("DOMContentLoaded", function () {
// Load existing values from storage and populate the input fields
chrome.storage.sync.get(["api_key", "secret_key"], function (data) {
var apiKey = data.api_key || "";
var secretKey = data.secret_key || "";
// Set initial input values to empty strings
var apiKeyInput = document.getElementById("api_key");
var secretKeyInput = document.getElementById("secret_key");
apiKeyInput.value = "";
secretKeyInput.value = "";
// Set event listener for save button click
document.getElementById("save").addEventListener("click", function () {
// Get values from input fields
var apiKey = apiKeyInput.value;
var secretKey = secretKeyInput.value;
// Load existing JSON data from storage
chrome.storage.sync.get(["info"], function (storedData) {
var existingInfo = storedData.info || {};
// Update existingInfo with the new apiKey and secretKey pair
existingInfo[apiKey] = secretKey;
// Save updated JSON data to storage
chrome.storage.sync.set(
{
info: existingInfo,
},
function () {
// Update status to indicate successful save
var status = document.getElementById("status");
status.textContent = "Saved!";
window.close();
setTimeout(function () {
status.textContent = "";
}, 1500);
}
);
});
});
});
chrome.storage.sync.get(["api_key", "secret_key", "info"], function (data) {
var apiKey = data.api_key;
var secretKey = data.secret_key;
var existingInfo = data.info || {};
// 取得した値を使用する処理を記述
existingInfo[apiKey] = secretKey;
console.log("Existing Data:", data);
console.log("Updated Info:", existingInfo);
// Save updated info back to storage
chrome.storage.sync.set(
{
info: existingInfo,
},
function () {
console.log("Updated info saved.");
}
);
});
});