-
Notifications
You must be signed in to change notification settings - Fork 21
/
options.js
100 lines (95 loc) · 3.04 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function saveOptions() {
var customapikey = document.getElementById('customapikey').value;
if (document.getElementById('radioCustom').checked && customapikey != '') {
//use custom key
chrome.storage.sync.set({ customapikey: customapikey }, function () {
chrome.storage.sync.set(
{
greentext: !document.getElementById('chkGreentext').checked,
showcommunitybans: document.getElementById('chkCommunityBans').checked
},
function () {
var status = document.getElementById('statusSaved');
status.style.visibility = 'visible';
setTimeout(function () {
status.style.visibility = 'hidden';
}, 750);
}
);
});
} else if (
document.getElementById('radioDefault').checked ||
customapikey == ''
) {
//use default key
chrome.storage.sync.remove('customapikey', function () {
chrome.storage.sync.set(
{
greentext: !document.getElementById('chkGreentext').checked,
showcommunitybans: document.getElementById('chkCommunityBans').checked
},
function () {
var status = document.getElementById('statusSaved');
status.style.visibility = 'visible';
document.getElementById('radioDefault').checked = true;
document.getElementById('customapikey').value = '';
setTimeout(function () {
status.style.visibility = 'hidden';
}, 750);
}
);
});
}
}
function restoreOptions() {
chrome.storage.sync.get(
['customapikey', 'greentext', 'showcommunitybans'],
function (data) {
if (typeof data['customapikey'] == 'undefined') {
} else {
document.getElementById('customapikey').value = data['customapikey'];
document.getElementById('radioCustom').checked = true;
}
if (typeof data['greentext'] == 'undefined') {
} else if (data['greentext'] == false) {
document.getElementById('chkGreentext').checked = true;
}
if (typeof data['showcommunitybans'] == 'undefined') {
} else if (data['showcommunitybans'] == true) {
document.getElementById('chkCommunityBans').checked = true;
}
}
);
}
function getPermissions() {
chrome.permissions
.request({
origins: ['*://steamcommunity.com/*', 'https://api.steampowered.com/*']
})
.then(() => {
location.reload();
});
}
function initOptions() {
restoreOptions();
document.getElementById('save').addEventListener('click', saveOptions);
chrome.permissions?.contains(
{
origins: ['*://steamcommunity.com/*', 'https://api.steampowered.com/*']
},
hasPermissions => {
if (!hasPermissions) {
document.querySelector('#permissions').style.display = 'block';
document
.getElementById('grantPermissions')
.addEventListener('click', getPermissions);
}
}
);
}
if (
document.location.protocol != 'http:' &&
document.location.protocol != 'https:'
) {
document.addEventListener('DOMContentLoaded', initOptions);
}