-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.html
136 lines (126 loc) · 3.54 KB
/
options.html
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<html>
<head>
<title>Choose Highlight Style</title>
<script type="text/javascript" src="styles.js"></script>
<script type="text/javascript" src="inject.js"></script>
<script type="text/javascript" src="highlight.pack.js"></script>
<script type="text/javascript">
// Saves options to localStorage.
function save_options() {
var select = document.getElementById("style");
var favorite_style = select.children[select.selectedIndex].value;
localStorage["favorite_style"] = favorite_style;
for (var idx in {"defered_pages": null, "disabled_pages": null}){
localStorage[idx] = document.getElementById(idx).value;
}
set_style(favorite_style);
// Update status to let user know options were saved.
var status = document.getElementById("status");
status.innerHTML = "Options Saved.";
setTimeout(function() {
status.innerHTML = "";
}, 750);
}
function set_style(file_name){
var css_path = chrome.extension.getURL("styles/" + file_name + ".css");
var styles = document.getElementsByTagName("link");
var css_style = null;
for (var idx in styles) {
if (styles[idx].href && /.*styles\/.*css/.test(styles[idx].href)){
css_style = styles[idx];
}
}
if (!css_style){
var css_style = document.createElement("link");
css_style.setAttribute("rel", "stylesheet");
css_style.setAttribute("type", "text/css");
css_style.setAttribute("href", css_path);
document.head.appendChild(css_style);
} else {
css_style.setAttribute("href", css_path);
}
}
// Restores select box state to saved value from localStorage.
function restore_options() {
main();
var select_el = document.getElementById("style");
for (var idx in styles) {
var s = styles[idx];
var option = document.createElement("option");
option.text = s;
option.setAttribute("value", s);
select_el.appendChild(option);
}
var favorite = localStorage["favorite_style"];
if (favorite) {
for (var i = 0; i < select_el.children.length; i++) {
var child = select_el.children[i];
if (child.value == favorite) {
child.selected = "true";
break;
}
}
} else {
favorite = 'native';
}
for (var idx in {"defered_pages": null, "disabled_pages": null}){
document.getElementById(idx).value = localStorage[idx] || "";
}
set_style(favorite);
}
function toggle_advanced(){
var elem = document.getElementById("advanced_options_div");
if (elem.style.display){
elem.style.display = "";
} else {
elem.style.display = "none";
}
}
</script>
<style>
textarea {
width: 300px;
height: 150px;
}
body {
padding-left: 15%;
padding-right: 15%;
}
table {
width: 100%;
}
</style>
</head>
<body onload="restore_options()">
<span id="status"></span>
<div id="style-options">
<pre>
<code>@requires_authorization
def somefunc(param1, param2):
r'''A docstring'''
if param1 > param2: # interesting
print 'Gre\'ater'
print ''
return (param2 - param1 + 1) or None
class SomeClass:
pass</code></pre>
Style: <select id="style">
</select>
</div>
<a href="#" onclick="toggle_advanced()" id="advanced_options">advanced options >></a>
<div id="advanced_options_div" style="display:none;">
<table>
<tr>
<td>Disabled pages List</td>
<td>Live pages List</td>
</tr>
<tr>
<td><textarea id="disabled_pages"></textarea></td>
<td><textarea id="defered_pages"></textarea></td>
</tr>
</table>
</div>
<br/>
<button onclick="save_options()">Save</button>
</body>
</html>