-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (39 loc) · 1.29 KB
/
script.js
File metadata and controls
51 lines (39 loc) · 1.29 KB
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
function addStyleSheet(properties) {
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
for (key in properties) {
link[key] = properties[key];
}
head.appendChild(link);
}
// add Font Awesome stylesheet for toggle button
addStyleSheet({
'rel': 'stylesheet',
'href': 'https://use.fontawesome.com/releases/v5.7.2/css/all.css',
'crossorigin': 'anonymous'
});
function toggleCSS() {
var button = document.getElementById('cssToggleButton');
if ('fas fa-toggle-off' == button.className) {
button.classList.replace('fa-toggle-off', 'fa-toggle-on');
addStyleSheet({'href': 'csl-alt.css', 'rel': 'stylesheet'});
} else {
button.classList.replace('fa-toggle-on', 'fa-toggle-off');
addStyleSheet({'href': 'csl.css', 'rel': 'stylesheet'});
}
}
var div = document.createElement('div');
div.style.position = 'fixed';
div.style.bottom = '5px';
div.style.right = '10px';
var a = document.createElement('a');
a.onclick = toggleCSS;
var label = document.createTextNode('Alternate CSS ');
var span = document.createElement('span');
span.className = 'fas fa-toggle-off';
span.id = 'cssToggleButton';
a.appendChild(label);
a.appendChild(span);
div.appendChild(a);
var body = document.getElementsByTagName('body')[0];
body.appendChild(div);