-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·44 lines (41 loc) · 1.77 KB
/
app.js
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
window.onload = function() {
webview = document.querySelector("webview")
var cloudtagsNfc = new CloudTagsNfc({
onRead: function(value) {
webview.executeScript({code: `document.dispatchEvent(new CustomEvent('nfc_tap', { detail: {tag_data: '${value}' }}))`, runAt: 'document_end' })
},
onWrite: function(value) {
document.querySelector("#write-value").value = "";
document.querySelector("#success-message").innerHTML = "<strong>Wrote: </strong>" + value;
document.querySelector("#success-message").style.display = 'block';
setTimeout(function(){
document.querySelector("#success-message").style.display = 'none';
}, 5000)
},
onReadError: function(value) {
webview.executeScript({code: `document.dispatchEvent(new CustomEvent('nfc_error', { detail: {tag_data: '${value}' }}))`, runAt: 'document_end' })
},
onWriteError: function(value) {
document.querySelector("#write-value").value = "";
document.querySelector("#error-message").innerHTML = "<strong>Error: </strong>" + value;;
document.querySelector("#error-message").style.display = 'block';
setTimeout(function(){
document.querySelector("#error-message").style.display = 'none';
}, 5000)
},
getWriteData: function() {
return document.querySelector("#write-value").value
},
});
webview.addEventListener('loadcommit', function(e) {
webview.insertCSS({code: "#nfc-panel { display: block !important }" })
});
$("#is-development").click(function(){
if($("#is-development:checked").length > 0) {
webview.setAttribute("src", "https://cloudtags-api-staging.herokuapp.com")
}
else {
webview.setAttribute("src", "https://cloudtags-api-production.herokuapp.com")
}
})
}