Files
grin-web-wallet/scripts/clipboard.js
2024-12-20 18:08:44 -08:00

49 lines
842 B
JavaScript
Executable File

// Use strict
"use strict";
// Classes
// Clipboard class
class Clipboard {
// Public
// Copy
copy(text) {
// Return promise
return new Promise(function(resolve, reject) {
// Check if clipboard API is supported
if(typeof navigator === "object" && navigator !== null && "clipboard" in navigator === true) {
// Return writing text to clipboard
return navigator["clipboard"].writeText(text).then(function() {
// Resolve
resolve();
// Catch errors
}).catch(function(error) {
// Reject error
reject("Writing to clipboard failed.");
});
}
// Otherwise
else
// Reject error
reject("Clipboard not supported.");
});
}
}
// Main function
// Set global object's clipboard
globalThis["Clipboard"] = Clipboard;