I need this for my parser. It’s written in Javascript. I have looked at the ok.ru API documentation and there is no such method.Is there an API to find users by their full name in ok.ru. Or any other solution for Javascript?
Category: javascript
Category Added in a WPeMatico Campaign
How to connect a database to javascript?
I am interested in knowing a lot about the databases that I can manage with this language
I am interested in learning more about databases and their control.
I don’t have much experience and I want something detailed, please.
Pan Camera to follow mouse cursor in React Three.js
I am working with a 3d model in my react app using Three.js. I want to implement an effect where the camera follows the mouse cursor, similar to the effect used here https://tkmh.me/.
I am using OrbitControls like this :
const RoomModelViewer = () => {
return (
//this is three.js, every code inside the Canvas is Three.js code
//canvas is used to render 3d stuff
<Canvas camera={{
position: [0, 0, 10],
fov: 35,
}}>
<Suspense fallback={null}>
<RoomModel/>
<OrbitControls autoRotate={false}
autoRotateSpeed={0.5}
enablePan={true}
enableZoom = {true}
enableRotate = {true}
minPolarAngle={-Math.PI / 1.5}
maxPolarAngle={Math.PI / 2.5}
dampingFactor={0.2}
/>
</Suspense>
</Canvas>
);
};
How to move a div into the space of another after removing it?
It seems the old Slack desktop UI finally broke, too bad.
So I opened /slackdevtools and moved the control strip to the left: strip = document.querySelector('div.p-control_strip');document.querySelector('div.p-workspace_switcher_prototype').appendChild(strip);strip.style.left='0px' then removed the pesky, completely unnecessary tab rail document.querySelector('div.p-tab_rail').remove() but an empty space remains:
Before:
After:
Desirable: #general is right next to the + sign where “Later” used to be. In other words, how do I force div.p-client_workspace__layout to occupy the space which div.p-tab_rail used to? That’s not even a Slack desktop question , that’s a JS/CSS question. Obviously I need to save something before removing it but what? (I know nothing. I am a backend dev.)
Nodejs: JSOn.stringify is rounding the numbers
Iam having a very weird problem. After making the call to the creditcard processor (CCBILL) with a payment token , they send back a subscription id .For example
0124058201000005323 should get returned. however what gets back is
124058201000005330. As you can see it has been rounded.
I also released that JSON.stringify(0124058201000005323) = ‘124058201000005330’
Now the weird thing is that when i use postman the response is not rounded and is as expected. am i not making the correct request
I am using node latest v 20
my function is as follows
function chargeCCbill(authToken, sendData){
return fetch(`${ccBillBaseUrl}/transactions/payment-tokens/${sendData.paymentTokenId}`,{
method:'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${authToken}`,
},
body:JSON.stringify(sendData)
})
.then((subData) => subData.json())
.then((json)=>{
if(json.subscriptionId !== null && json.declineCode === null && json.approved === true ){
// the json.subscriptionId is rounded here
return {status:'success',subscriptionData:json}
}
else{
return {status:'fail',subscriptionData:json}
}
})
I hope you guys can see what i might be doing wrong
I hope you guys can see what i might be doing wrong.
Also there was a option to add the following header
application/vnd.mcn.transaction-service.api.v.1+json
i dont know if that has any bearing. because i dont add that in postman and still gets the correct result. am i making the wrong call?
I am sending a cookie from the server-side of my application. Cookie is visible in the response, it does not appear in the browser’s cookie tab
so here the response cookie is visible when i inspect in network fetch in devtool
but not in cookie tab enter image description here
and this is my server side code for sending cookies
function sendCookie(res, key, value, expDay) {
const exDate = new Date(Date.now() + expDay * 24 * 60 * 60 * 1000);
const cookieOptions = {
path: “/”,
expires: exDate,
httpOnly: true,
};
res.cookie(key, value, cookieOptions);
}
module.exports = { sendCookie };
// setting two cookies, the first one without option and second one with options
// also in chrome i’ll getting only one cookie in response but in firefox i’ll get both
sendCookie(res,"sessionToken", token, 365)
return res.status(201).json({
error: false,
message: `Welcome Again ${userData.name}`,
user: userData,
});
// and this is my cors policy
app.use(
cors({
origin: “http://localhost:3000”,
methods: [“GET”, “POST”, “PUT”, “DELETE”],
credentials: true,
})
);
i don’t know what i’m doing wrong
Conditional statement inside EventListener is not working
I am trying to calculate bmi and after doing that have a button appear that provides more information on the calculation result. When the ‘what does this mean’ button is clicked, info should pop up based on the bmi score calculated.
const generatebutton = document.getElementById("explainbutton");
const wt = document.getElementById("b2");
const ht = document.getElementById("b3");
const bmi = document.getElementById("b5");
const calc = document.getElementById("b7");
const clr = document.getElementById("b8");
// // calculate bmi funtion
function calculate() {
const wt = document.getElementById("b2").value;
const ht = document.getElementById("b3").value;
const solve = Number.parseFloat(wt / ht ** 2).toFixed(2);
document.getElementById("b5").textContent = solve;
};
// function make explain button appear
function genbutton () {
generatebutton.style.visibility = "visible";
};
calc.addEventListener("click", function(){
calculate();
genbutton();
});
clr.addEventListener("click", function () {
wt.value = "";
ht.value = "";
bmi.textContent = "";
});
//set variables for explanation
const explain= document.getElementById("explain")
const under= document.getElementById("under")
const healthy= document.getElementById("healthy")
const over= document.getElementById("over")
const obese= document.getElementById("obese")
//pop up text
var btn = document.getElementById("explainbutton");
btn.addEventListener("click", function () {
const bmi = document.getElementById("b5");
if (bmi<18.5)
{
explain.classList.toggle("open-under")}
else if (bmi>=18.5 && bmi<24.9)
{
explain.classList.toggle("open-healthy") }
else if (bmi> 24.9 && bmi<29.9)
{
explain.classList.toggle("open-overweight")}
else
{explain.classList.toggle("open-obese")}
});
#explainbutton {
visibility: hidden;
margin-left: 190px;
}
/* pop-up explanation options */
.box {
background: white;
visibility: hidden;
margin: 20px auto;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.open-under .under {
visibility: visible;
width: 300px;
height: 100px;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.open-healthy .healthy {
visibility: visible;
width: 300px;
height: 100px;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.open-over .over {
visibility: visible;
width: 300px;
height: 100px;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.open-obese .obese {
visibility: visible;
width: 300px;
height: 100px;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
/* */
<div id="b1">
<span id="sp1">
WEIGHT(kg) :
</span>
<input type="number" id="b2">
</input>
</div>
<br>
<div id="b9">
<span id="sp2">
HEIGHT(m) :
</span>
<input type="number" id="b3">
</input>
</div>
<br>
<div id="bmibox">
BMI :
<span id="b5"> </span>
<INPUT TYPE="BUTTON" VALUE="What does this mean?" class="styled-button-2" id="explainbutton" />
<div class="box" id="explain">
<span class="under", id="under">You are in the underweight range</span>
<span class="healthy" id="healthy"> You are in the healthy range </span>
<span class="over" id="over"> You are in the overweight range </span>
<span class="obese" id="obese"> You are in the obese range</span>
</div>
</div>
<br>
<br>
<div id="b6">
<INPUT TYPE="BUTTON" VALUE="Calculate" class="styled-button-2" id="b7" />
<button id="b8">Clear</button>
</div>
The basic pop-up function works fine without the condition.
So I’m not sure what is stopping the script from running. I’ve also tried making the conditional a function in a separate block before adding it back into the EventListener.
Download and Post file in one click for Embedded Software Updates using Javascript
I have an embedded (Raspberry Pi Pico) system that can perform software updates by posting the new *.bin file via a USB web interface. At the moment this is done in three steps:
- User clicks a link to download the bin file from remote storage to their computer
- User browses for that file in a Post form
- User clicks Upload and that file gets sent to the Embedded system and update commences.
What I’d like to have happen is a single step:
- User clicks a link and bin file gets downloaded and posted to the embedded system.
Is there a way to do this? Perhaps using a Blob?
The above three steps all work and are summarized in the following code:
// Download Latest Code
await fetch(`https://oursite.com/version.json`)
.then(async (allData) => {
console.log(allData);
return await allData.json();
})
.then((version) => {
// version numbers get filled in by embedded system
if ((version.majorVersion > 1) || (version.minorVersion != 0)) {
versionDiv.innerHTML=`SOFTWARE UPDATE AVAILABLE: Latest Version is
V${version.majorVersion}.${version.minorVersion}
<div class="action-box">
<a class="action-button" href="${version.fileUrl}">Download BIN</a>
</div>`;
}
});
// User clicks Browse on webpage and selects Bin file, which then calls this function:
function uploadSoftware(event) {
event.preventDefault();
// Make sure files are selected
var thisFile = filesInput.files[0];
// checks for file validity removed from here for clarity
// Create the form object
var uploadFormData = new FormData(uploadForm);
// Initiate the AJAX request
var request = new XMLHttpRequest();
// Ensure the request method is POST
request.open('POST', uploadForm.action);
// Attach the progress event handler to the AJAX request
request.upload.onprogress = function(event) {
// show progress bar - works, removed for clarity
};
request.onreadystatechange = () => {
if (request.readyState == 4 && request.status == 200) {
// Call the software update function on embedded system
loadSW();
uploadForm.querySelector('.result').innerHTML = `<div>File Transfer Successful,
Installing... </div>`;
} else {
uploadForm.querySelector('.result').innerHTML = `<div>Something went wrong!</div> `;
}
};
// Execute request
request.send(uploadFormData);
};
I imagine there’s a way to replace the fileUrl hyperlink with some Javascript that takes the data from the file at the fileUrl and stores it as a variable, to then use as thisFile in the next step, but not sure how to do it. Any thoughts greatly appreciated.
My bootstrap modal has an error Uncaught TypeError: Cannot read properties of null (reading ‘hide’) at HTMLAnchorElement. when used
Bootstrap modal does not work on a specific page but works well in another page. When I click the Profile It only shows this error:
Uncaught TypeError: Cannot read properties of null (reading 'hide') at HTMLAnchorElement.<anonymous>
Here is the code:
<div id="settings-dropdown" class="dropdown-content1">
<div class="profile-name-container" id="mobile">
<div><a class="profile-name"><?php echo $_SESSION['firstName']; ?></a></div>
<div><a class="profile-role"><?php echo $_SESSION['role']; ?></a></div>
<hr>
</div>
<a class="profile-hover" href="#" data-bs-toggle="modal" data-bs-target="#viewModal" >
<i class="bi bi-person profile-icons"></i>Profile
</a>
<a class="profile-hover" href="#" id="logoutBtn">
<i class="bi bi-box-arrow-left "></i>Logout
</a>
</div>
I have tried changing the bootstrap versions, changing order of the scripts etc. and still no clue why does this occur.
using refs works fine on dev mode but not working in build mode in Vue composition API
this is my html:
<input ref="file" type="file" accept="image/*" capture="environment" style="display:none" />
<v-btn @click="openCamera()">take photo</v-btn>
I’m trying to open camera(or choose a file) with a custom button:
<script setup>
import { ref } from 'vue';
const file = ref(null)
function openCamera() {
file.value[0].click()
}
<script>
everything goes fine when I’m running the app using yarn dev (vite) but when I build it using yarn build and serve it on server the app throws this error:
Cannot read properties of null (reading '0')
and the file is null.
Any help would be appreciated.
Thanks
I need to fetch Facebook events manager data via API
Bundling nodes in d3js
I am trying to bundle nodes using the below javascript any help would be appreciated and the original code can found below:
https://codepen.io/suchibharani/pen/xxbgrKd
function bundleNodes(groupId) { var bundleFactor = 0.1; // Adjust this value to control the bundling intensity node .filter(function(d) { return d.group == groupId; }) .each(function(d) { var dx = centroid[0] - d.x; var dy = centroid[1] - d.y; d.x += dx * bundleFactor; d.y += dy * bundleFactor; // Optionally, you can fix the nodes' positions after bundling to prevent them from moving back due to the force simulation. // d.fx = d.x; // d.fy = d.y; }); simulation.alphaTarget(0.3).restart(); // Reheat the simulation to reflect changes }
400 bad request error posting thru node-fetch
const fetch = require("node-fetch").default;
let iApi = express.Router();
iApi.post("/update/:name/:value", async (req, res) => {
const name = req.params["name"];
const value = req.params["value"];
const headers = { ...req.headers };
const url = `${process.env.URL}/name/${name}/value/${value}`;
const options = {
url: url,
method: "post",
headers: headers,
gzip: true,
};
try {
const response = await fetch(url, options);
handleResponseNoBody(
response.ok,
response.status,
response.body,
res,
url
);
} catch (err) {
handleResponseNoBody(false, 500, err, res, url);
}
});
function handleResponseNoBody(ok, status, data, res, url) {
const loggerOpts = Object.assign({}, LOG_DEFAULTS, {
endpoint_url: url,
application: "app1",
});
if (!ok) {
loggerOpts.description = url + " error retrieving endpoint";
loggerOpts.response_obj = { status_code: 500 };
loggerOpts.err = data;
logger.error(loggerOpts);
res.status(status).send(data);
} else if (status === 200) {
loggerOpts.description = `${url} return 200`;
loggerOpts.response_obj = { status_code: 200 };
loggerOpts.response_body = data;
logger.info(loggerOpts);
res.status(status).send(data);
} else {
loggerOpts.description = url + " endpoint did not return 200 status";
loggerOpts.error = data;
loggerOpts.response_obj = { status_code: status };
logger.info(loggerOpts);
res.status(status).send(data);
}
}
This code works and gives 200 when “,” (comma) or string “tab” is passed as the value and works as expected, but when I try to pass “%7C” ( | – pipe ) it gives 400 bad request, I am not why that is the case can anyone help me with this? much appreciated.
https://xxx/name/NAME/value/, – works
https://xxx/name/NAME/value/tab – works
https://xxx/name/NAME/value/%7C – does not work
Spans generated with Renderer2 and appended are appended in incorrect order
I’m using setInterval to print text to a div similar to an RPG. If the div is navigated away from, the text is stored and kept so that it can be preserved and the print resumed once the div is visible again.
The stored text, if any, is appended to the empty div first, then the print is resumed. However, the newly generated text appears before the previously appended text, with it seeming to appear in the correct spot at the front without staying there.
I know this is very vague, but I have a StackBlitz created with all of the code inside to show what I mean, as that is a lot easier to see than me explaining it here.
I simply want the text to append as intended – after the stored content instead of at the front. In the StackBlitz start the print, then toggle visibility back and forth to see it in action.
How to make an image appear and disappear with a button/Link in Next.js
I’m new at React and Next and I have this code:
import Link from 'next/link';
import Image from 'next/image';
async function getPalpedia() {
const response = await fetch(`http://localhost:3000/api/palpedia`, {
method: "GET",
})
return response.json();
}
export default async function palpedia() {
const palpediaJSON = await getPalpedia();
const palpedia = JSON.stringify(palpediaJSON)
return (
<div>
<div className="fixed z-20 top-[4rem] bottom-0 right-[max(0px,calc(50%-58rem))] w-[15.5rem] py-10 overflow-y-auto hidden xl:block">
{palpediaJSON.map((pal) => (
<div className="palInfo" key={pal.id}>
<Link href="#" >{pal.name}</Link>
<p>Types: {pal.types.join(", ")}</p>
<p>HP: {pal.hp}</p>
<p>ATK: {pal.atk}</p>
<p>DEF: {pal.def}</p>
</div>
))}
</div>
<div className="overlay">
<Image id="chikipi" src="/chikipi.png" width={0} height={0} alt="Chikipi" />
</div>
</div>
);
}
This is a page in which I’m trying to show a list called Palpedia, and when clicking a Link element, I would like the image to appear, of course I’ll add a lot of images but first I’m trying with this one.
Also feel free to tell everything that is wrong/bad practice, as I made this without much knowledge.
Thank you!
I’ve already tried by adding a “useState hook”, but it seems this page belongs to the server side and I can only use that hook on the client side, so I do not know if I can apply that solution.
I’ve also tried to use the “use client” in the first line, same result.


