-
Notifications
You must be signed in to change notification settings - Fork 3
/
redactions.html
141 lines (128 loc) · 4.42 KB
/
redactions.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
137
138
139
140
141
<!DOCTYPE html>
<html lang="en-us">
<head>
<title>Object-Oriented Design and Data Structures: Redactions</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Cache-Control" content="public, max-age=600" /> <!-- cache for only 1 hour -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="styles/default.css" />
<script src="js/ezdom.js"></script>
</head>
<body>
<div id="header">
<div id="identity">
<center>
<h1 class=booktitle>Object-Oriented Design and Data Structures<br>
<small>Andrew Myers and Dexter Kozen</small></h1>
</div>
</center>
</div>
<div id=content>
<h1>Manage Redactions</h1>
<p>
A customized view of this online book can be constructed by specifying
<em>redactions</em>. The text of any heading in the text can be
used to name a section or subsection that should not appear in the
reader's view. In addition, marked sections in the book can also
be redacted. Redactions are remembered by the browser on a given
computer; using this page, an active link can be created that will cause
any browser to remember the specified redactions so that future visits
to the book still redact information as originally specified.
</p>
<p>Note that the capitalization used to name the redacted section
must be exactly the same as in the document file. The table of contents
puts chapter titles in lower case, which sometimes differs from the way
it is presented in the chapter.
</p>
<p>
Your current list of redactions follows:
</p>
<table id=current_redactions>
<tr><th>
<input type=checkbox id=check_all onclick="check_all()"></input>
Remove </th><th>Name</th>
</table>
<script>
var current_redactions = document.getElementById("current_redactions")
with (EZDom) {
let redactions = localStorage.getItem("OODDS.redactions")
const list = redactions ? redactions.split(/ *\n */) : []
for (const t of list) {
app(current_redactions,
tr(td(input({type: "checkbox"})), td(t)))
}
}
function check_all() {
const checkbox = document.getElementById("check_all")
for (const tr of current_redactions.getElementsByTagName('TR')) {
if (!tr.tagName || tr.firstChild.tagName == 'TH') continue
tr.firstChild.firstChild.checked = checkbox.checked
}
}
</script>
<p>
<button id="add_redaction"
onclick="add_redaction()">
Add new redaction</button>
<input id=new_redaction type=text onchange="add_redaction()"></input>
</p>
<script>
function update_storage() {
const items = []
for (const tr of current_redactions.getElementsByTagName('TR')) {
if (!tr.tagName || tr.firstChild.tagName == 'TH') continue
items.push(tr.childNodes[1].innerText)
}
localStorage.setItem("OODDS.redactions", items.join("\n"))
create_page()
}
function add_redaction() {
with (EZDom) {
const new_redaction = document.getElementById("new_redaction").value
if (new_redaction.match(/^\s*$/)) return
app(current_redactions,
tr(td(input({type: "checkbox"})), td(new_redaction)))
}
update_storage()
}
</script>
<p>
<button id=remove_redactions onclick="remove_redactions()">Remove checked redactions</button>
</p>
<script>
function remove_redactions() {
const items = new Set(current_redactions.getElementsByTagName('TR'))
for (const tr of items) {
if (!tr.tagName || tr.firstChild.tagName == 'TH') continue
if (tr.firstChild.firstChild.checked) {
tr.parentNode.removeChild(tr)
}
}
document.getElementById("check_all").checked = false
update_storage()
}
</script>
<p>
The following HTML page will redirect to the table of contents
while also setting the redactions as indicated.
</p>
<pre id=active_page>
</pre>
<span id=toc_link></span>
<script>
function create_page() {
const page = document.getElementById("active_page")
let href = window.location.href.replace(/\/[^\/]*$/, "/toc.html")
const data = localStorage.getItem("OODDS.redactions") || ""
href += "?redactions=" + encodeURIComponent(data)
page.innerText =
('<!DOCTYPE html>\n<html lang="en-us">\n<script>\nwindow.location = "')
+ href+'"\n\x3C/script\x3E\n\x3C/html\x3E'
document.getElementById('toc_link').innerHTML = '<a target=x href="' + href + '">' + 'Open table of contents</a>'
}
create_page()
</script>
</div>
</body>
</html>