Skip to content

Commit fff67c1

Browse files
feat: ✨ Share button
1 parent 4f62e7f commit fff67c1

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

frontend/index.pug

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ html(lang='en')
5252
span.viewcounter.noselect#viewcounter-count(style='visibility: hidden; display: none')
5353

5454
.bottom-button-wrapper
55+
button#share-button.btn(aria-label='Share' style='visibility: hidden')
5556
button#hide-button.btn(aria-label='Hide')
5657

5758
.scrollbar-container

frontend/src/icons.ts

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
EyeInvisibleOutlined,
1111
FireOutlined,
1212
FileMarkdownOutlined,
13+
ShareAltOutlined,
1314
} from "@ant-design/icons-svg"
1415
import { renderIconDefinitionToSVGElement } from "@ant-design/icons-svg/es/helpers"
1516
import tippy from "tippy.js"
@@ -22,9 +23,11 @@ const newButton = <HTMLButtonElement>document.getElementById("new-button")
2223
const copyButton = <HTMLButtonElement>document.getElementById("copy-button")
2324
const hideButton = <HTMLButtonElement>document.getElementById("hide-button")
2425
const githubButton = <HTMLButtonElement>document.getElementById("github-button")
26+
const shareButton = <HTMLButtonElement>document.getElementById("share-button")
2527
const markdownButton = <HTMLButtonElement>(
2628
document.getElementById("markdown-button")
2729
)
30+
2831
const singleViewButton = <HTMLButtonElement>(
2932
document.getElementById("single-view-button")
3033
)
@@ -47,6 +50,7 @@ renderIcon(githubButton, GithubOutlined)
4750
renderIcon(hideButton, EyeInvisibleOutlined)
4851
renderIcon(markdownButton, FileMarkdownOutlined)
4952
renderIcon(singleViewButton, FireOutlined)
53+
renderIcon(shareButton, ShareAltOutlined)
5054

5155
tippy("#save-button", {
5256
content: "Save paste<br><span class='keybind'>Ctrl + S</span>",
@@ -112,6 +116,14 @@ tippy("#hide-button", {
112116
allowHTML: true,
113117
})
114118

119+
tippy("#share-button", {
120+
content: "Share paste",
121+
placement: "top",
122+
animation: "scale",
123+
theme: "rosepine",
124+
allowHTML: true,
125+
})
126+
115127
const observer = new MutationObserver(callback)
116128

117129
function callback() {

frontend/src/index.ts

+13
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const saveButton = <HTMLButtonElement>document.getElementById("save-button")
3535
const newButton = <HTMLButtonElement>document.getElementById("new-button")
3636
const copyButton = <HTMLButtonElement>document.getElementById("copy-button")
3737
const hideButton = <HTMLButtonElement>document.getElementById("hide-button")
38+
const shareButton = <HTMLButtonElement>document.getElementById("share-button")
3839
const markdownButton = <HTMLButtonElement>(
3940
document.getElementById("markdown-button")
4041
)
@@ -127,6 +128,7 @@ function newPaste() {
127128
hide(codeViewPre)
128129
hide(viewCounterLabel)
129130
hide(viewCounter)
131+
hide(shareButton)
130132
viewCounterLabel.style.display = "none"
131133
viewCounter.style.display = "none"
132134
}
@@ -165,6 +167,17 @@ function viewPaste(content: string, views: string, singleView: boolean) {
165167
addMessage("This is a single-view paste!")
166168
}
167169

170+
if (navigator.canShare) {
171+
show(shareButton)
172+
173+
shareButton.addEventListener("click", function () {
174+
navigator.share({
175+
title: "zer0bin paste",
176+
url: window.location.toString(),
177+
})
178+
})
179+
}
180+
168181
disable(saveButton)
169182
disable(markdownButton)
170183
enable(newButton)

frontend/style/style.scss

+11
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,17 @@ a {
192192
}
193193
}
194194
}
195+
// #share-button {
196+
// position: fixed !important;
197+
// bottom: 0;
198+
// left: 0;
199+
// z-index: 10;
200+
// color: $muted;
201+
// &:hover {
202+
// color: $rose;
203+
// }
204+
// padding: 10px;
205+
// }
195206
.keybind {
196207
color: $subtle;
197208
font-size: 11px;

0 commit comments

Comments
 (0)