generated from songquanpeng/blog-theme-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.ejs
52 lines (45 loc) · 1.81 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
<%- include('./partials/header') %>
<div class="w3-content" style="max-width:960px">
<div class="w3-card-4 w3-white" style="margin: 16px 3px;overflow: auto; padding: 8px 16px 16px">
<%- include('./partials/page-info') %>
<div class="w3-container w3-large article-font">
<div class="control-panel" style="margin-top: 16px">
<button class="w3-button w3-green" id="darkBtn" onclick="changeBackground()">Focus</button>
<button class="w3-button w3-green" onclick="copyCode()">Copy</button>
</div>
<pre>
<code id="code-display"><%=page.content%></code>
</pre> <%- config.copyright %>
<%- config.ad %>
</div>
</div>
<%- 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') %>