-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaste.html
More file actions
46 lines (38 loc) · 1.51 KB
/
Copy pathpaste.html
File metadata and controls
46 lines (38 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://thunkable.github.io/webviewer-extension/thunkableWebviewerExtension.js" type="text/javascript"></script>
</head>
<body>
<span id="messageDisplay"></span>
<br />
<button type="button" id="messageButton">Click to send a message to the app</button>
</body>
<script type="text/javascript">
// when the button is clicked, send a message to the app
let paste = document.getElementById('messageButton')
paste.onclick = async function() {
navigator.clipboard.readText()
.then(text => {
ThunkableWebviewerExtension.postMessage(text);
})
.catch(e => {
ThunkableWebviewerExtension.postMessage(e.message);
});
};
// when we get a message from the app, display it on the page
ThunkableWebviewerExtension.receiveMessage(function(message) {
document.getElementById('messageDisplay').innerHTML = message;
});
// when we get a message from the app that needs a return value
// return the string 'fast response' unless the message is
// 'slow message'. If the message is 'slow message', wait for
// four seconds, then return the string 'slow response'.
// The slow response shows how this could work for API calls that
// take time to execute.
ThunkableWebviewerExtension.receiveMessageWithReturnValue(function(message, callback) {
const text = document.execCommand('paste')
callback(text);
});
</script>
</html>