mirror of https://github.com/zer0bin-dev/zer0bin
Change save to download when viewing a paste
This commit is contained in:
parent
df60aacb4a
commit
82c6035e44
|
@ -48,7 +48,7 @@ renderIcon(hideButton, EyeInvisibleOutlined)
|
|||
renderIcon(markdownButton, FileMarkdownOutlined)
|
||||
renderIcon(singleViewButton, FireOutlined)
|
||||
|
||||
tippy("#save-button", {
|
||||
export const saveTippy = tippy("#save-button", {
|
||||
content: "Save paste<br><span class='keybind'>Ctrl + S</span>",
|
||||
placement: "bottom",
|
||||
animation: "scale",
|
||||
|
|
|
@ -8,13 +8,15 @@ import "./icons"
|
|||
import hljs from "../min/highlight.min"
|
||||
|
||||
import config from "../config.json"
|
||||
import { toggleHiddenIcon } from "./icons"
|
||||
import { toggleHiddenIcon, saveTippy } from "./icons"
|
||||
const apiUrl = config.api_url
|
||||
const confettiChance = parseInt(config.confetti_chance)
|
||||
let rawContent = ""
|
||||
let buttonPaneHidden = false
|
||||
let isMarkdown = false
|
||||
let singleView = false
|
||||
let inView = false
|
||||
let viewId = ""
|
||||
|
||||
const jsConfetti = new JSConfetti()
|
||||
|
||||
|
@ -117,6 +119,8 @@ function newPaste() {
|
|||
disable(newButton)
|
||||
disable(copyButton)
|
||||
enable(singleViewButton)
|
||||
saveTippy.setContent("Save paste<br><span class='keybind'>Ctrl + S</span>")
|
||||
|
||||
|
||||
editor.value = ""
|
||||
rawContent = ""
|
||||
|
@ -145,6 +149,7 @@ function addMessage(message: string) {
|
|||
}
|
||||
|
||||
function viewPaste(content: string, views: string, singleView: boolean) {
|
||||
inView = true
|
||||
lineNumbers.innerHTML = ""
|
||||
if (
|
||||
content.startsWith("---") ||
|
||||
|
@ -170,6 +175,7 @@ function viewPaste(content: string, views: string, singleView: boolean) {
|
|||
enable(newButton)
|
||||
enable(copyButton)
|
||||
disable(singleViewButton)
|
||||
saveTippy.setContent("Download paste<br><span class='keybind'>Ctrl + S</span>")
|
||||
|
||||
hide(editor)
|
||||
show(codeViewPre)
|
||||
|
@ -188,6 +194,11 @@ function viewPaste(content: string, views: string, singleView: boolean) {
|
|||
}
|
||||
|
||||
async function savePaste() {
|
||||
if (inView) {
|
||||
window.location = `${apiUrl}/p/d/${viewId}`
|
||||
return
|
||||
}
|
||||
|
||||
if (editor.value === "") {
|
||||
return
|
||||
}
|
||||
|
@ -200,6 +211,7 @@ async function savePaste() {
|
|||
window.history.pushState(null, "", `/${res["data"]["id"]}`)
|
||||
|
||||
rawContent = res["data"]["content"]
|
||||
viewId = res["data"]["id"]
|
||||
viewPaste(rawContent, "0", res["data"]["single_view"])
|
||||
|
||||
const rand = Math.floor(Math.random() * confettiChance * 6)
|
||||
|
|
Loading…
Reference in New Issue