This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
options.js
53 lines (50 loc) · 2.07 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
// Saves options to chrome.storage.sync.
function save_options() {
var defaultfontSize = document.getElementById('defaultfontSize').value;
var showAllMessages = document.getElementById('showAllMessages').checked;
var showMyMessages = document.getElementById('showMyMessages').checked;
var showUsername = document.getElementById('showUsername').checked;
var pinWeixinTab = document.getElementById('pinWeixinTab').checked;
var showNotifications = document.getElementById('showNotifications').checked;
var danmuDebug = document.getElementById('danmuDebug').checked;
chrome.storage.sync.set({
defaultfontSize: defaultfontSize,
showAllMessages: showAllMessages,
showMyMessages: showMyMessages,
showUsername: showUsername,
pinWeixinTab: pinWeixinTab,
showNotifications: showNotifications,
danmuDebug: danmuDebug
}, function() {
// Update status to let user know options were saved.
$('#status').show();
setTimeout(function() {
$('#status').hide();
}, 750);
});
}
// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restore_options() {
chrome.storage.sync.get({
defaultfontSize: 48,
showAllMessages: true,
showMyMessages: true,
showUsername: false,
pinWeixinTab: false,
showNotifications: false,
danmuDebug: false
}, function(items) {
document.getElementById('defaultfontSize').value = items.defaultfontSize;
document.getElementById('showAllMessages').checked = items.showAllMessages;
document.getElementById('showMyMessages').checked = items.showMyMessages;
document.getElementById('showUsername').checked = items.showUsername;
document.getElementById('pinWeixinTab').checked = items.pinWeixinTab;
document.getElementById('showNotifications').checked = items.showNotifications;
document.getElementById('danmuDebug').checked = items.danmuDebug;
});
}
$('#status').hide();
document.addEventListener('DOMContentLoaded', restore_options);
$('input[type=checkbox]').on('click', save_options);
$('input[type=number]').on('change', save_options);