mirror of
https://github.com/transatoshi-mw/grin-web-wallet.git
synced 2025-10-07 00:02:47 +00:00
contents of zip
This commit is contained in:
48
scripts/clipboard.js
Executable file
48
scripts/clipboard.js
Executable file
@@ -0,0 +1,48 @@
|
||||
// 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;
|
Reference in New Issue
Block a user