Skip to content

Commit a724e97

Browse files
authored
added example gist url
1 parent e80714c commit a724e97

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

frontend/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ <h1 class="text-green-500">Get Raw Gists</h1>
2222
By <a href="https://aaanh.ca">Anh H Nguyen</a> | <a href="https://github.com/aaanh/gist-stuff">Github</a>
2323
</div>
2424
<div>
25-
25+
26+
<h4 class="text-lg font-bold">Try with this gist URL</h4>
27+
<pre><code class="language-url">
28+
https://gist.github.com/aaanh/2d8b322170ec9fa3c2273e7b92b48327
29+
</code></pre>
2630
<h4 class="text-lg font-bold">What is a &apos;gist&apos;?</h4>
2731
<p>Gist is a code or text snippet that is hosted on Github. <a href="https://docs.github.com/en/get-started/writing-on-github/editing-and-sharing-content-with-gists/creating-gists">Docs</a> here.</p>
2832
<p>It functions similarly to <a href="https://pastebin.com">pastebin.</a></p>

frontend/script.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const copyButtonLabel = "Copy Code";
2+
3+
// you can use a class selector instead if you, or the syntax highlighting library adds one to the 'pre'.
4+
let blocks = document.querySelectorAll("pre");
5+
6+
blocks.forEach((block) => {
7+
// only add button if browser supports Clipboard API
8+
if (navigator.clipboard) {
9+
let button = document.createElement("button");
10+
button.innerText = copyButtonLabel;
11+
button.addEventListener("click", copyCode);
12+
block.appendChild(button);
13+
}
14+
});
15+
16+
async function copyCode(event) {
17+
const button = event.srcElement;
18+
const pre = button.parentElement;
19+
let code = pre.querySelector("code");
20+
let text = code.innerText;
21+
await navigator.clipboard.writeText(text);
22+
23+
button.innerText = "Code Copied";
24+
25+
setTimeout(()=> {
26+
button.innerText = copyButtonLabel;
27+
},1000)
28+
}

frontend/style.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,31 @@ a:hover {
1919
#get-raw-now:hover {
2020
cursor: pointer;
2121
background-color: #bbbbbb;
22+
}
23+
24+
pre[class*="language-"] {
25+
position:relative;
26+
overflow: auto;
27+
margin:5px 0;
28+
padding:1.75rem 0 1.75rem 1rem;
29+
border-radius:10px;
30+
}
31+
32+
button{
33+
position:absolute;
34+
top:5px;
35+
right:5px;
36+
37+
font-size:.9rem;
38+
padding:.15rem;
39+
background-color:#828282;
40+
color:1e1e1e;
41+
border:ridge 1px #7b7b7c;
42+
border-radius:5px;
43+
text-shadow:#c4c4c4 0 0 2px;
44+
}
45+
46+
button:hover{
47+
cursor:pointer;
48+
background-color:#bcbabb;
2249
}

0 commit comments

Comments
 (0)