-
Notifications
You must be signed in to change notification settings - Fork 7
/
options.js
58 lines (52 loc) · 2.24 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
const optionsForm = document.getElementById('options-form');
const sessionidInput = document.getElementById('sessionid-input');
const steamLoginSecureInput = document.getElementById('steamLoginSecure-input');
const infoBox = document.getElementById('info-box');
optionsForm.addEventListener('submit', (event) => {
event.preventDefault();
const sessionid = sessionidInput.value;
const steamLoginSecure = steamLoginSecureInput.value;
if (sessionid && steamLoginSecure) {
chrome.storage.sync.set({ sessionid, steamLoginSecure }, () => {
if (sessionid) {
chrome.cookies.set({
url: "https://store.steampowered.com/",
name: "sessionid",
value: sessionid,
secure: true,
httpOnly: true
}, () => {
console.log("sessionid cookie value is set");
});
}
if (steamLoginSecure) {
chrome.cookies.set({
url: "https://store.steampowered.com/",
name: "steamLoginSecure",
value: steamLoginSecure,
secure: true,
httpOnly: true
}, () => {
console.log("steamLoginSecure cookie value is set");
});
}
// Update existing info box
infoBox.classList.remove('error');
infoBox.classList.add('success');
infoBox.textContent = 'Cookie values are set for the extension and for the Steam store.';
});
} else {
chrome.storage.sync.set({ sessionid: "", steamLoginSecure: "" }, () => {
sessionidInput.value = '';
steamLoginSecureInput.value = '';
// Update existing info box
infoBox.classList.remove('success');
infoBox.classList.add('error');
infoBox.textContent = 'Cookie values are cleared for the extension. We\'ll get them from the Steam store.';
});
}
});
chrome.storage.sync.get(['sessionid', 'steamLoginSecure'], ({ sessionid, steamLoginSecure }) => {
sessionidInput.value = sessionid || '';
steamLoginSecureInput.value = steamLoginSecure || '';
});