mirror of https://github.com/raftario/filite.git
Copy URLs to clipboard instead of opening them (fixes #4)
This commit is contained in:
parent
aa8bd8b9f4
commit
9d2f8c7e16
|
@ -59,6 +59,19 @@ const randomUrl = () => {
|
||||||
return Math.floor(Math.random() * 2147483647).toString(36);
|
return Math.floor(Math.random() * 2147483647).toString(36);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateClipboard = (data) => {
|
||||||
|
navigator.permissions
|
||||||
|
.query({ name: "clipboard-write" })
|
||||||
|
.then((result) => {
|
||||||
|
if (result.state === "denied") {
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(() => navigator.clipboard.writeText(data))
|
||||||
|
.then(() => alert("URL copied to clipboard"))
|
||||||
|
.catch(() => alert(data));
|
||||||
|
};
|
||||||
|
|
||||||
for (const group in tabs) {
|
for (const group in tabs) {
|
||||||
tabs[group][0].onclick = () => {
|
tabs[group][0].onclick = () => {
|
||||||
const active = document.querySelectorAll(".active");
|
const active = document.querySelectorAll(".active");
|
||||||
|
@ -75,7 +88,7 @@ for (const group in inputs) {
|
||||||
const submitButton = inputs[group][inputs[group].length - 1];
|
const submitButton = inputs[group][inputs[group].length - 1];
|
||||||
|
|
||||||
const urlInput = inputs[group][0];
|
const urlInput = inputs[group][0];
|
||||||
urlInput.addEventListener("input", () => {
|
urlInput.addEventListener("input", (e) => {
|
||||||
if (urlInput.value[urlInput.value.length - 1] === " ") {
|
if (urlInput.value[urlInput.value.length - 1] === " ") {
|
||||||
urlInput.value = randomUrl();
|
urlInput.value = randomUrl();
|
||||||
checkValidity();
|
checkValidity();
|
||||||
|
@ -171,7 +184,7 @@ for (const group in inputs) {
|
||||||
if (status !== 201) {
|
if (status !== 201) {
|
||||||
throw new Error(text);
|
throw new Error(text);
|
||||||
} else {
|
} else {
|
||||||
window.open(url, "_blank");
|
updateClipboard(url);
|
||||||
clearInputs();
|
clearInputs();
|
||||||
filesValueInput.value = "";
|
filesValueInput.value = "";
|
||||||
fetchUsed();
|
fetchUsed();
|
||||||
|
@ -201,7 +214,7 @@ for (const group in inputs) {
|
||||||
if (status !== 201) {
|
if (status !== 201) {
|
||||||
throw new Error(text);
|
throw new Error(text);
|
||||||
} else {
|
} else {
|
||||||
window.open(url, "_blank");
|
updateClipboard(url);
|
||||||
clearInputs();
|
clearInputs();
|
||||||
fetchUsed();
|
fetchUsed();
|
||||||
}
|
}
|
||||||
|
@ -228,7 +241,7 @@ for (const group in inputs) {
|
||||||
if (status !== 201) {
|
if (status !== 201) {
|
||||||
throw new Error(text);
|
throw new Error(text);
|
||||||
} else {
|
} else {
|
||||||
window.open(url, "_blank");
|
updateClipboard(url);
|
||||||
clearInputs();
|
clearInputs();
|
||||||
fetchUsed();
|
fetchUsed();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue