I’m a student from Korea.
I’m currently working on making Tower Defense Game with javascript canvas for a group project.
I’m stuck on making monsters/enemies with delay then make them move.
I tired the animation thing, setTimeout, setInterval, for loops, etc.. but they all didn’t work.
What can I do?
Category: javascript
Category Added in a WPeMatico Campaign
How to click button on dapp/website then confirm transaction in metamask? Then repeat every xx hour
TL;DR I want to automate clicking a button in a dapp then confirm the transaction in Metamask then wait xx time and repeat
So far, I have started working on creating a script using dappeteer and puppeteer which I will share below.
So far with dappeteer I can’t get it to switch network to BNB and every time the script runs it has to setup metamask with an account etc which I don’t think is ideal!
Can this be done using a chrome extension? I’d prefer this as then it can connect to the existing plugin.
Any help or ideas would be appreciated!
Sincerely, Rohin.
Code
import puppeteer from 'puppeteer';
import dappeteer from '@chainsafe/dappeteer';
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function main() {
const browser = await dappeteer.launch(puppeteer, { metamaskVersion: 'v10.15.0', defaultViewport: null });
const metamask = await dappeteer.setupMetamask(browser,{seed: "xxx xxx xxx xxx xxx xxx xxx xxx"});
await metamask.addNetwork({networkName: "BSC",rpc: "https://bsc-dataseed.binance.org",chainId: "56",symbol: "BNB"})
await metamask.switchNetwork('main')
await sleep(2000);
const page = await browser.newPage()
await page.goto('https://app.solarfarm.finance/?ref=xxxxxxxxxxxxxx');
await sleep(2000);
await page.waitForXPath('//div[contains(@class,"chakra-button css-1voh9rj")]');
var originSelector = await page.$x('//div[contains(@class,"chakra-button css-1voh9rj")]');
await originSelector[0].click();
var input = await page.$x('//button[contains(text(),"Connect")]');
await input[0].click();
input = await page.waitForSelector("button#connect-METAMASK");
await input.click();
await metamask.approve({allAccounts: false});
page.bringToFront();
await sleep(2000);
await metamask.confirmTransaction();
}
main()
How to show diff between 2 rich texts like we use to see on github but only want to see text not the html tags (on react js)
the final results
hello
this
is a (this line should be red)
hello
this
is a sample text (this line should be green)
old text and new text are given down
old Text : <div>hello<br>this<br>is a</div>
new Text : <div>hello<br>this<br>is a sample text</div>
Execute queries on redshift using Javascript code
I have been following aws-sdk for javascript to execute sql queries on redshift cluster but haven’t been able to connect.
Can someone guide me which module to use for redshift connection in javascript (except node-redshift) or share a skeleton code with proper parameter names?
Uncaught TypeError: Cannot set properties of undefined (setting ‘style’)
I’m having trouble creating this function, can anyone help me?
function AlteraCor(objeto,style){
document.querySelector(objeto).style=style}
AlteraCor(‘.page-cart .footer’,’background:#324973;margin:0px;’)
How to define custom Express.js route for vite dev server
I am translating my app from webpack configuration into vite. My current webpack dev server has custom endopint configured for doing some stuff. I need to have this same endpoint in vite config as well. How to do this? How can I define an express.js route for vite dev server?
This endpoint is for loading environment variables from a service during runtime.
How would you remove trailing comma when writing to a stream json in node.js?
Suppose I have code as below:
const fs = require('node:fs')
const csvParser = require('csv-parser')
const rs = fs.createReadStream(dir)
const ws = fs.createWriteStream(outDir)
ws.write('[' + 'n')
rs.pipe(
csvParser({
mapHeaders: mapper,
}),
)
.on('data', (data) => {
ws.write('t' + JSON.stringify({ ...data, provider } + ',n'))
})
.on('end', () => {
ws.write(']')
console.log('writing to a file has been completed >> ', OUT_DIR)
})
Basically what this code does is to read from large csv file then stream this into write a json file. As seen in the code, I append ‘,n’ as separator for each row such that all the json code is formatted once streaming has been completed.
The issue with such method is that it leaves comma at the end of each entry that you would have to manually format the file (i.e. removing trailing comma) each time document write is completed.
For instance, the result would come out be as such:
[
{"key1":"value1", "key2":"value2"},
{"key1":"value1", "key2":"value2"}, // <- note the trailing comma here.
]
Any suggestion as to handling the trailing comma?
Also, what would be alternative way of handling read and write stream better, please let me know. Thanks in advance.
I want to print the data as a list when the QR Code is scanned
There will be a special qr code and there will be sequential information in this qr code.Can I print the information in the incoming qr code on the bottom line when it sees a space or a symbol(@)?
https://www.hizliresim.com/qc4feyi —– Screen output is undesirable
https://www.hizliresim.com/rkajsoy —– Desired
https://www.hizliresim.com/lnd387j —– Processes and permissions when scanned
How to recreate this Qlik Extension on plain HTML and Javascript?
This is a Qlik Extension. I’d like to know if it is possible to recreate this on HTML/JS specifically this control:
Discord Bot JS interaction reply does not wait until the code finish executing
I just started to code and trying to build a discord js bot. I am scraping data from a website. My problem is that the await interaction.reply(randomFact); will execute immediately while my code have not finish scraping and return the result. I have tried async/await but still does not work. The error I get is
TypeError: Cannot read properties of undefined (reading ‘ephemeral’)
module.exports = {
data: new SlashCommandBuilder()
.setName("tips")
.setDescription("Scrap from website"),
async execute(interaction) {
let randomFact;
let healthArray = [];
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://www.example.com/health-facts/");
const pageData = await page.evaluate(() => {
return {
html: document.documentElement.innerHTML,
};
});
const $ = cheerio.load(pageData.html);
$(".round-number")
.find("h3")
.each(function (i, el) {
let row = $(el).text().replace(/(s+)/g, " ");
row = $(el)
.text()
.replace(/[0-9]+. /g, "")
.trim();
healthArray.push(row);
});
await browser.close();
randomFact =
healthArray[Math.floor(Math.random() * healthArray.length)];
})();
await interaction.reply(randomFact);
},
};
Sorry if there is anything lacking in my post. I just joined stack overflow.
Uncaught TypeError: Cannot read properties of undefined (reading ‘play’). I can’t make my 3d object clickable
Faced an issue with adding action.play
Dear developers could you please help me to solve this issue?
I want my 3d object to be clickable so that when I click the object it will jump. But unfortunately, I see this error. However, when I looked at examples of other projects where this click function is implemented, I don’t see any differences between those projects and my code.
here below I attached my code(Squirrel.js):
import React, { useRef, useState, useEffect } from 'react'
import { useGLTF} from '@react-three/drei/useGLTF';
import {useAnimations} from "@react-three/drei/useAnimations";
export default function Model(props) {
const [UpDown, setUpDown] = useState(false);
const group = useRef()
const { nodes, materials, animations } = useGLTF('/squirrel.glb')
const { actions } = useAnimations(animations, group);
console.log(actions);
useEffect(() => {
if (UpDown) {
actions.UpDown.stop();
} else {
actions.UpDown.play();
}
});
return (
<group ref={group} {...props} dispose={null}>
<mesh
onClick={() => setUpDown(!UpDown)}
geometry={nodes.Plane155.geometry}
material={materials['Material.010']}
position={[-10,32,25]}
name = "Squirrel"
/>
</group>
)
}
useGLTF.preload('/squirrel.glb')
How to use Javascript module in typescript
I have a third-party Javascript module that is done in AMD way. I do not have typing file (type.d) for it nor I can create the typing file.
But I need to use the module in one of the typescript How can I do it.
Please note I have also a few javascript files which are using the third-party javascript module there I am using it this way
require(["thirdPartyModule"], function(module){
//this is just example code
module.doSomething();
//more code here
}
How can I do the same thing in typescript asking it to load the Js module as a dependency. Also we since another Javascript is already loading the module hence we have the third party module loaded in DOM already through requireJs
Any help or pointer to read will highly be appricated
how to set moves count in chess clock made by javascript -setlntimer
I have made chess clock by java script -set ln timer . I have events like start ,switch and reset .
I am not able to set an event which can count the number of moves played / count of switches done. how can I add this event ????
react-spring makes a request after animation leaves
hi this is the code where problem happens
const transitions = useTransition(currentPageData, {
from: { opacity: 0, transform: "translateY(-100px)" },
enter: { opacity: 1, transform: "translateY(0px)" },
leave: { opacity: 0, transform: "translateY(-100px)" },
key: currentPageData =>currentPageData.id,
});
the problem is when I send DELETErequest to delete an item and when the ” leave: ” property happens
it sends an extra POST request ( i don’t even know how that request is happening, I didn’t write that) for example
if I have 2 fields filled with some data
when I delete an item
it will make another item itself
Custom tooltip not showing
I have a table like this:
<tr data-id="{{ $user->id ?? '' }}"
data-name="{{ $user->name ?? '' }}">
<td>{{ $user->id }}</td>
<td><a class="information text-danger float-left"><i class="fa fa-info-circle"></i></a>{{ $user->name }}</td>
</tr>
As you can see I have passed data-id and data-name to <tr>.
And this is the script for showing those information on Tooltip:
$(document).on('mouseover','.information',function(){
let elementMouseOver = $(this);
elementMouseOver.tooltip({
title: "<table class='table table-responsive table-borderless text-light'>" +
"<tr><td>UserId:</td><td>" + elementMouseOver.closest('tr').attr('data-id') + "</td></tr><tr><td>UserName:</td><td>" + elementMouseOver.closest('tr').attr('data-name') + "</td></tr></table>",
html: true,
placement: "left",
container: 'body'
});
});
Then I’ve added this style:
.tooltip-inner {
max-width: none;
white-space: nowrap;
background:#000000;
-webkit-box-shadow: 0px 3px 3px 0px rgba(0,0,0,0.3);
-moz-box-shadow: 0px 3px 3px 0px rgba(0,0,0,0.3);
box-shadow: 0px 3px 3px 0px rgba(0,0,0,0.3);
color:gray;
margin:0;
padding:0;
}
So now it should be showing the information but it’s not.
In fact when I console.log the elementMouseOver.closest('tr').attr('data-id') and elementMouseOver.closest('tr').attr('data-name'), they properly appears.
There must be a problem with the CSS part that does not show the Tooltip.
So if you have any idea about this, please let me know…
