-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
121 lines (108 loc) · 4.21 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var editor = ace.edit("editor");
// Saves options to chrome.storage
function save_options() {
let theme = document.getElementById('theme').value;
let font = document.getElementById("font").value;
let fontSize = document.getElementById("font-size").value;
let showId = document.getElementById("show-id").checked;
chrome.storage.sync.set({
selectedTheme: theme,
fontFamily: font,
fontSize: fontSize,
showId: showId
}, function () {
// Update status to let user know options were saved.
let status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function () {
status.textContent = '';
}, 750);
});
}
// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restore_options() {
chrome.storage.sync.get({
selectedTheme: 'styles/dracula.css',
fontFamily: 'fontFamilies/monospace.css',
fontSize: '12',
showId: false
}, function (items) {
document.getElementById('theme').value = items.selectedTheme;
document.getElementById('font').value = items.fontFamily;
document.getElementById('font-size').value = items.fontSize;
document.getElementById('show-id').checked = items.showId;
change_option();
});
}
const change_option = () => {
let theme = document.getElementById("theme").value.split(".")[0].split("/")[1];
editor.setTheme("ace/theme/"+theme);
let font = document.getElementById("font").value.split(".")[0].split("/")[1];
let fontSize = document.getElementById("font-size").value;
editor.setOptions({
fontFamily: font,
fontSize: fontSize+"px"
});
}
document.getElementById("theme").onchange = change_option;
document.getElementById("font").onchange = change_option;
for(let i = 8; i < 33; i++) {
let opt = document.createElement("option");
opt.value= i;
opt.innerHTML = i+"px";
document.getElementById('font-size').appendChild(opt);
}
document.getElementById("font-size").onchange = change_option;
chrome.runtime.getPackageDirectoryEntry(function(directoryEntry) {
directoryEntry.getDirectory('styles', {}, function(subDirectoryEntry) {
var directoryReader = subDirectoryEntry.createReader();
var filenames = [];
(function readNext() {
directoryReader.readEntries(function(entries) {
if (entries.length) {
for (var i = 0; i < entries.length; ++i) {
filenames.push(entries[i].name);
}
readNext();
} else {
filenames.forEach(item => {
let opt = document.createElement("option");
opt.value= "styles/"+item;
opt.innerHTML = item.split('.')[0];
document.getElementById('theme').appendChild(opt);
});
restore_options();
}
});
})();
});
directoryEntry.getDirectory('fontFamilies', {}, function(subDirectoryEntry) {
var directoryReader = subDirectoryEntry.createReader();
var filenames = [];
(function readNext() {
directoryReader.readEntries(function(entries) {
if (entries.length) {
for (var i = 0; i < entries.length; ++i) {
filenames.push(entries[i].name);
}
readNext();
} else {
filenames.forEach(item => {
let opt = document.createElement("option");
opt.value = "fontFamilies/"+item;
opt.innerHTML = item.split('.')[0];
document.getElementById('font').appendChild(opt);
});
restore_options();
}
});
})();
});
});
const startEditor = () => {
editor.setTheme("ace/theme/chrome");
editor.session.setMode("ace/mode/javascript");
}
startEditor();
document.getElementById('save').addEventListener('click', save_options);