mirror of
https://github.com/transatoshi-mw/grin-web-wallet.git
synced 2025-10-06 15:52:47 +00:00
49 lines
842 B
JavaScript
Executable File
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;
|