File tree Expand file tree Collapse file tree 3 files changed +60
-1
lines changed Expand file tree Collapse file tree 3 files changed +60
-1
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,11 @@ <h1 class="text-green-500">Get Raw Gists</h1>
22
22
By < a href ="https://aaanh.ca "> Anh H Nguyen</ a > | < a href ="https://github.com/aaanh/gist-stuff "> Github</ a >
23
23
</ div >
24
24
< 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 >
26
30
< h4 class ="text-lg font-bold "> What is a 'gist'?</ h4 >
27
31
< 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 >
28
32
< p > It functions similarly to < a href ="https://pastebin.com "> pastebin.</ a > </ p >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -19,4 +19,31 @@ a:hover {
19
19
# get-raw-now : hover {
20
20
cursor : pointer;
21
21
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 : 1e1 e1e;
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 ;
22
49
}
You can’t perform that action at this time.
0 commit comments