Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
322661db
Commit
322661db
authored
Nov 04, 2023
by
Timothy J. Baek
Browse files
feat: copy code block enhancement
parent
7f203c3b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
9 deletions
+39
-9
src/routes/+page.svelte
src/routes/+page.svelte
+39
-9
No files found.
src/routes/+page.svelte
View file @
322661db
...
...
@@ -108,14 +108,44 @@
// only add button if browser supports Clipboard API
if
(
navigator
.
clipboard
&&
block
.
childNodes
.
length
<
2
)
{
let
button
=
document
.
createElement
(
'
button
'
);
button
.
innerText
=
'
Copy Code
'
;
block
.
appendChild
(
button
);
let
code
=
block
.
querySelector
(
'
code
'
);
code
.
style
.
borderTopRightRadius
=
0
;
code
.
style
.
borderTopLeftRadius
=
0
;
let
topBarDiv
=
document
.
createElement
(
'
div
'
);
topBarDiv
.
style
.
backgroundColor
=
'
#343541
'
;
topBarDiv
.
style
.
overflowX
=
'
auto
'
;
topBarDiv
.
style
.
display
=
'
flex
'
;
topBarDiv
.
style
.
justifyContent
=
'
space-between
'
;
topBarDiv
.
style
.
padding
=
'
0 1rem
'
;
topBarDiv
.
style
.
paddingTop
=
'
4px
'
;
topBarDiv
.
style
.
borderTopRightRadius
=
'
8px
'
;
topBarDiv
.
style
.
borderTopLeftRadius
=
'
8px
'
;
let
langDiv
=
document
.
createElement
(
'
div
'
);
langDiv
.
textContent
=
code
?.
className
.
split
(
'
'
)[
0
].
slice
(
9
);
langDiv
.
style
.
color
=
'
white
'
;
langDiv
.
style
.
margin
=
'
4px
'
;
langDiv
.
style
.
fontSize
=
'
0.75rem
'
;
button
.
addEventListener
(
'
click
'
,
async
()
=>
{
await
copyCode
(
block
,
button
);
});
let
button
=
document
.
createElement
(
'
button
'
);
button
.
textContent
=
'
Copy Code
'
;
button
.
style
.
background
=
'
none
'
;
button
.
style
.
fontSize
=
'
0.75rem
'
;
button
.
style
.
border
=
'
none
'
;
button
.
style
.
margin
=
'
4px
'
;
button
.
style
.
cursor
=
'
pointer
'
;
button
.
style
.
color
=
'
#ddd
'
;
button
.
addEventListener
(
'
click
'
,
()
=>
copyCode
(
block
,
button
));
topBarDiv
.
appendChild
(
langDiv
);
topBarDiv
.
appendChild
(
button
);
block
.
prepend
(
topBarDiv
);
// button.addEventListener('click', async () => {
// await copyCode(block, button);
// });
}
});
...
...
@@ -126,11 +156,11 @@
await
navigator
.
clipboard
.
writeText
(
text
);
// visual feedback that task is completed
button
.
innerText
=
'
Code
Copied
'
;
button
.
innerText
=
'
Copied
!
'
;
setTimeout
(()
=>
{
button
.
innerText
=
'
Copy Code
'
;
},
7
00
);
},
10
00
);
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment