mirror of
https://github.com/lus/pasty.git
synced 2023-08-10 21:13:09 +03:00
Skip unnecessary clipboard-write permission check (fixes #35)
This commit is contained in:
parent
befc9615d5
commit
7a99f85060
@ -324,13 +324,11 @@ function setupButtonFunctionality() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
BUTTON_COPY_ELEMENT.addEventListener("click", async () => {
|
BUTTON_COPY_ELEMENT.addEventListener("click", async () => {
|
||||||
// Ask for clipboard permissions
|
if (!navigator.clipboard) {
|
||||||
if (!(await askForClipboardPermission())) {
|
Notifications.error("Clipboard API not supported by your browser.");
|
||||||
Notifications.error("Clipboard permission denied.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the current code
|
|
||||||
await navigator.clipboard.writeText(CODE);
|
await navigator.clipboard.writeText(CODE);
|
||||||
Notifications.success("Successfully copied the code.");
|
Notifications.success("Successfully copied the code.");
|
||||||
});
|
});
|
||||||
@ -400,18 +398,6 @@ function setupButtonFunctionality() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asks for clipboard write permission
|
|
||||||
async function askForClipboardPermission() {
|
|
||||||
try {
|
|
||||||
const state = await navigator.permissions.query({
|
|
||||||
name: "clipboard-write"
|
|
||||||
});
|
|
||||||
return state.state === "granted" || state.state === "prompt";
|
|
||||||
} catch (error) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1:1 skid from https://stackoverflow.com/questions/7404366/how-do-i-insert-some-text-where-the-cursor-is
|
// 1:1 skid from https://stackoverflow.com/questions/7404366/how-do-i-insert-some-text-where-the-cursor-is
|
||||||
function insertTextAtCursor(element, text) {
|
function insertTextAtCursor(element, text) {
|
||||||
let value = element.value, endIndex, range, doc = element.ownerDocument;
|
let value = element.value, endIndex, range, doc = element.ownerDocument;
|
||||||
|
Loading…
Reference in New Issue
Block a user