parent
a766d5d596
commit
1dd0d17ba5
@ -19,4 +19,12 @@ body {
|
|||||||
|
|
||||||
pre {
|
pre {
|
||||||
padding-left: 4ex; /* approx 4 monospaced spaces */
|
padding-left: 4ex; /* approx 4 monospaced spaces */
|
||||||
|
}
|
||||||
|
|
||||||
|
.success {
|
||||||
|
color: #008000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fail {
|
||||||
|
color: #800000;
|
||||||
}
|
}
|
39
assets/js/copyclipboard.js
Normal file
39
assets/js/copyclipboard.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const COPY_TO_CLIPBOARD_STATUS_ID = "copyToClipboardStatus";
|
||||||
|
let copyToClipboardCtr = 0;
|
||||||
|
|
||||||
|
function copyToClipboardSuccess() {
|
||||||
|
let statusElem = document.getElementById(COPY_TO_CLIPBOARD_STATUS_ID);
|
||||||
|
statusElem.innerText = "URL copied!";
|
||||||
|
statusElem.classList.remove("fail");
|
||||||
|
statusElem.classList.add("success");
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyToClipboardFail(cause) {
|
||||||
|
let statusElem = document.getElementById(COPY_TO_CLIPBOARD_STATUS_ID);
|
||||||
|
if (!cause) cause = "unknown error";
|
||||||
|
statusElem.innerText = "copy failed: " + cause;
|
||||||
|
statusElem.classList.remove("success");
|
||||||
|
statusElem.classList.add("fail");
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyToClipboard(url) {
|
||||||
|
let copyEventIdx = ++copyToClipboardCtr;
|
||||||
|
|
||||||
|
if (!window.navigator.clipboard) {
|
||||||
|
let msg = "could not access clipboard";
|
||||||
|
if (window.location.protocol !== "https:") {
|
||||||
|
msg += ": website not using HTTPS"
|
||||||
|
}
|
||||||
|
copyToClipboardFail(msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.navigator.clipboard.writeText(url).then(() => {
|
||||||
|
if (copyToClipboardCtr !== copyEventIdx) return;
|
||||||
|
copyToClipboardSuccess();
|
||||||
|
}, () => {
|
||||||
|
if (copyToClipboardCtr !== copyEventIdx) return;
|
||||||
|
copyToClipboardFail();
|
||||||
|
});
|
||||||
|
}
|
@ -2,8 +2,15 @@
|
|||||||
'{{.Paste.Key}}{{.FileExt}}' metadata - rushlink
|
'{{.Paste.Key}}{{.FileExt}}' metadata - rushlink
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
{{define "head-append"}}
|
||||||
|
<script type="text/javascript" src="/js/copyclipboard.js" defer></script>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
{{define "body"}}
|
{{define "body"}}
|
||||||
<pre>
|
<pre>
|
||||||
|
<button onclick="copyToClipboard('{{.RootURL}}/{{.Paste.Key}}{{.FileExt}}')">Copy URL to clipboard</button> <span id="copyToClipboardStatus"></span>
|
||||||
|
</pre>
|
||||||
|
<pre>
|
||||||
<a href="{{.RootURL}}/{{.Paste.Key}}{{.FileExt}}">{{.RootURL}}/{{.Paste.Key}}{{.FileExt}}</a>
|
<a href="{{.RootURL}}/{{.Paste.Key}}{{.FileExt}}">{{.RootURL}}/{{.Paste.Key}}{{.FileExt}}</a>
|
||||||
---
|
---
|
||||||
{{if and (ne .Paste.State.String "deleted") .CanDeleteBool}}
|
{{if and (ne .Paste.State.String "deleted") .CanDeleteBool}}
|
||||||
|
Loading…
Reference in New Issue
Block a user