-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
123 lines (110 loc) · 4.28 KB
/
index.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html>
<head>
<title>Opti Taco Feeder</title>
<meta charset="UTF-8">
<link rel="icon" href="data:," type="image/x-icon">
<style>
#qr-code-container {
position: absolute;
width: 120px; /* Set the width to match the qr-code width */
height: 120px; /* Set the height to match the qr-code height */
background-color: rgba(255, 255, 255, 1);
border-radius: 10px;
margin-bottom: 10px;
margin-right: 10px;
}
#qr-code {
width: 120px;
height: 120px;
border-radius: 12px;
}
#sats_left {
position: absolute; /* Position the sats_left element */
bottom: 0; /* Align to the bottom */
left: 50%; /* Center horizontally */
transform: translateX(-50%); /* Adjust for centering */
font-size: 10px;
font-weight: bold;
font-family: 'Arial', sans-serif;
text-align: center;
background-color: rgba(255, 255, 255, 0.7);
border-radius: 12px;
padding: 2px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div id="qr-code-container">
<div id="qr-code">
<img id="qr-img" src="" width='120' height='120'">
<img id="lightning-img" src="" width='120' height='120' style=" display: none;">
</div>
<div id="sats_left"></div>
</div>
<script>
const wallet = "4e74146c232f4aa8a8959080026f159e"; // wallet id from lnbits
const LNURL = "LNURL1DP68GURN8GHJ7MRWVGHXYMMVWEJHY6M9WGHXXMMD9AKXUATJD3CZ75MRTQUK5JS5AL0DY"; // lnurl from lnbits lnulp extension
const server = "lnb.bolverker.com"; // could also use legend.lnbits.com if your wallet is there (any public lnbits url)
const christine = 666; // legarde limit in sats
let balance = 0;
let ws;
const WS_URL = `wss://${server}/api/v1/ws/${wallet}`;
let reconnectInterval = 30000;
function updateSatsLeftElem(receivedAmount, toggle) {
const satsLeftElem = document.getElementById('sats_left');
if (toggle) {
satsLeftElem.innerText = `${receivedAmount} sats received`;
} else {
satsLeftElem.innerText = ``;
}
}
function initWebSocket() {
ws = new WebSocket(WS_URL);
ws.addEventListener('open', function() {
console.log("WebSocket is open now.");
});
ws.addEventListener('close', function() {
console.log("WebSocket is closed now.");
setTimeout(initWebSocket, reconnectInterval);
});
ws.addEventListener('error', function(error) {
console.log("WebSocket Error: " + error);
if (ws.readyState === WebSocket.OPEN) {
ws.close();
}
});
ws.addEventListener('message', function(event) {
const data = JSON.parse(event.data);
if (data.wallet_balance !== undefined) {
balance = data.wallet_balance;
const receivedAmount = data.payment.amount / 1000;
// Toggle the QR code to lightning image
if (receivedAmount > 0) {
updateSatsLeftElem(receivedAmount, true);
const qrCode = document.querySelector('#qr-code img:first-child');
const lightningImg = document.getElementById('lightning-img');
qrCode.style.display = 'none';
if (receivedAmount == christine) { // Let him who hath understanding...
lightningImg.src = './legarde.jpg'; // Display legard.jpg
} else {
lightningImg.src = './taco.jpg'; // Display taco.jpg
}
lightningImg.style.display = 'block';
setTimeout(() => {
updateSatsLeftElem(receivedAmount, false);
qrCode.style.display = 'block';
lightningImg.style.display = 'none';
}, 2000);
}
}
});
}
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('qr-img').src = `https://${server}/api/v1/qrcode/${LNURL}`;
initWebSocket();
});
</script>
</body>
</html>