-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.ejs
54 lines (47 loc) · 1.79 KB
/
code.ejs
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
<%- include('./partials/header') %>
<div class="container article-container code-page">
<article class="shadow-box" style="padding: 16px">
<%- include('./partials/page-info') %>
<div class="control-panel" style="margin-top: 16px">
<button class="btn btn-light" id="darkBtn" onclick="changeBackground()">Focus</button>
<button class="btn btn-light" onclick="copyCode()">Copy</button>
</div>
<pre>
<code id="code-display"><%=page.content%></code>
</pre>
<%- config.copyright %>
<%- config.ad %>
<label>
<textarea id="hiddenTextArea" style="position: absolute;left: -100%;"></textarea>
</label>
</article>
<%- include('./partials/prev-next') %>
<%- include('./partials/comment') %>
</div>
<script>
const body = document.getElementsByTagName("body")[0];
const darkBtn = document.getElementById('darkBtn');
let dark = false;
function copyCode() {
const copyText = document.getElementById("code-display").textContent;
const textArea = document.getElementById('hiddenTextArea');
textArea.textContent = copyText;
document.body.append(textArea);
textArea.select();
document.execCommand("copy");
}
let e = document.querySelector('#code-display');
function changeBackground() {
const comment = document.getElementsByClassName("comment")[0];
let backgroundColor = getComputedStyle(e).backgroundColor;
if(dark){
body.setAttribute('style', '');
if(comment) comment.style.cssText = "";
}else{
body.setAttribute('style', 'background:'+backgroundColor);
if(comment) comment.style.cssText = "visibility:hidden";
}
dark = !dark;
}
</script>
<%- include('./partials/footer') %>