How can I continue fill the value after getting checkbox clicked?

I ran the code below in Automator in safari, and the first checkbox worked, but the rest two lines did not fill the value into the form. It got me crazy cause it works if I delete the checkbox code so I am wondering if the click() method interrupts the other two lines.

"document.getElementsByClassName('form__option-text')[0].click();"
 "document.getElementsByClassName('form__input')[0].value='123456789012345';"
 "document.getElementsByClassName('form__input--small')[0].value='1234';"

I would like to change only clicked header link text color with react

I started to learn coding recently and to create my portfolio. I am working on header and I would like to change the text color header link tag when it is only clicked one.
Text color changed to red when I clicked the link now but when I click another link, the previous link is still red.
enter image description here
I would like to change back text color from red to gray when I click another.
ex) OK – home about work skill contact NO – home about work skill contact

Header.jsx

import React, { useState } from "react";
import { Link as ScrollLink } from "react-scroll";

const Header = (props) => {
  const { headerPage } = props;
  const [onClickChangeColor, setOnClickChangeColor] = useState(false);
  const redText = () => {
    setOnClickChangeColor(!onClickChangeColor);
  };

  return (
    <div class="mr-8 cursor-pointer">
      <ScrollLink
        className={onClickChangeColor ? "text-[#FF5757]" : ""}
        onClick={redText}
        to={headerPage}
        smooth={true}
        duration={500}
      >
        {headerPage}
      </ScrollLink>
    </div>
  );
};

export default Header;
HeaderLayout.jsx

import React from "react";
import Header from "./Header";

const HeaderLayout = () => {
  const headerPages = ["home", "about", "work", "skill", "contact"];

  return (
    <div class="sticky top-0 flex justify-end h-20 text-md pt-10 mr-10 text-center bg-[#292929]">
      {headerPages.map((headerPage) => (
        <Header headerPage={headerPage}>{headerPage}</Header>
      ))}

      <div
        className="resume"
        class="w-24 h-8  text-[#FF5757] border border-[#FF5757] rounded-md"
      >
        <a
          href="https://drive.google.com/file/d/usp=sharing"
          class="block"
        >
          resume
        </a>
      </div>
    </div>
  );
};

export default HeaderLayout;

I am using React and Tailwind. English is my second language and I hope everyone understands what I want to do. Thank you in advance.

Vite – Multiple build outputs

I am using Nuxt 3 and there are many folders like pages, layouts, middlewares etc. which you can write in TS and it will build it JS into an folder named dist

Now i have an folder, lets call it specialfolder. This folder should get its own output folder lets say special_output

The structure looks like this:

-middlewares
-plugins
-specialfolder
-config
-layouts
-pages 

After build it should look like this:

-middleware
-plugins
-specialfolder
-config
-layouts
-special_output
-dist

Everything gets compiled normal, only specialfolder gets compiled to its own folder, is something like this possible in Nuxt 3 (vite)?

Passing ‘this’ scope to setInterval fails inside a class function

I’m trying to set an interval execution for a set of operations inside of a class, the first time it works but the next ones fails because the scope issue

I have this class:

class TaskManager {
    constructor() {
        this._taskFactory = new TaskFactory()
        this._publisher = new Publisher()
        this._currentTask = null
    }

    main = (args) => {
        if(args.interval > 0) {
            setInterval(() => this.executeTask(args), args.interval * 1000)
        } else {
            this.executeTask(args)
        }
    }

    executeTask = (args) => {
        const topicName = 'tasks-topic'
        this._currentTask = this._taskFactory.createTask(args.task)
        const response = this._currentTask.execute()
        this._publisher.publish(topicName, response)
    }
}

the first execution looks working fine and the next ones it loses the scope with the error:

this._currentTask = this._taskFactory.createTask(args.task)
                                              ^

TypeError: this._taskFactory.createTask is not a function

What I’m doing wrong?
Also I would like to set the interval dynamically, what should I add to it if possible?

How to show local html in React Native WebView without react-native-static-server or similar?

In React Native project, I have html document in src directory. (Assuming that it named “./src/green.html”).

And In MyScreen, I have a WebView for showing this page.

import WebView from 'react-native-webview';
import { Text, View, StyleSheet, Image } from 'react-native';

export default MyScreen (props) {
    const source = require('./green.html');
    const webviewSOurce = Image.resolveAssetSource(source);

    return (
        <View style>
            <WebView
                source={webSource}
                originWhitelist={["*"]}
                style={{
                    width:'100%',
                    minHeight:400
            }}/>
        </View>
    )

}

But it shows the content of html file as a plain text, not html.

    
    <div id="main-div">
    <h1>Hello World! I am alive!</h1>
    </div>

I visited https://github.com/react-native-webview/react-native-webview/blob/master/docs/Guide.md#loading-local-html-files, but I can’t get a clear image and react-native-http-server causes some issues on my app.

How can I deal it? Is there any alternative ways to show local html page in WebView without react-native-static-server or react-native-http-server?

Oauth2.0 Server with Nodejs

i have an application that is built with nodejs, this application uses the username and password flow of authentication.
A client approached me, he wanted my users in my app to be able to use the clients application (which is a no code platform, the client has an application that he leveraged a no code provider) without having to signup. Now this client’s application supports SSO (Oauth2.0) while my application is not offering a Oauth2.0 server(provider).

My question is: how can my nodejs application provide these details showed belowThis is the configuration page for SSO of the clients platform

second image

Please any help or resource will be appreciated, i hope my question is quite understandable.

Mapping ArrayBuffer bytes to corresponding Pixels Positions in Canvas

I have an ArrayBuffer (representing a PNG/JPG) and I want to create a dictionary so I know for each group of bytes what pixels and at what positions were generated on a canvas. The function that I need would look something like this:

getPixelsCoordinatesForBytes(arrayBuffer, bufferStart, bufferEnd){
  // crate Image on Canvas from buffer,
  // get location in canvas image for 
  // the pixels that were generated using the bytes beetween bufferStart and bufferEnd
 
  return x,y, img.width, img.height 
}

Basically, I need to reverse engineer the getImageData from Canvas context, tried looking into how V8 implements it but the code is a mess. From what I understand each file type is converted to ImageData based on some standard algorithm (also known as bitmaps/raster graphs). I was not able to find how this algorithm is working in javascript.

A solution in any programming language provided to this problem would also be useful as I may be able to rewrite it in Javascript.

Adding a function to add new objects and properties in javascript

Am stuck trying to add a function to add a new object to a const in javascript

const phonebook = {
  "Lily": {
    mobile: "+16235554420",
    work: "+12445552374",
    home: "+19775552223"
  },
  "Kyle, el hermano de Tim": {
    mobile: "+4235555616"
  }
};


function addPhoneNumber(name, numberType, number) {
  // write your code here
}
// when the function is ready, add the phone number of  xx
addPhoneNumber("Stephanie Noland", "mobile", "+4235555212");

console.log(phonebook["Stephanie Noland"].mobile); // "+4235555212"

I am aware that I can initiate a new object via

phonebook[name] = {}

But other than that I have trouble understanding how to add properties on that new object.

Normally a simple:

phonebook[name] = name,
phonebook[numberType] = numberType,
phonebook[number] = number

But that approach would only generate the following which is not what I need:

const phonebook = {
    mobile: "+16235554420",
    work: "+12445552374",
    home: "+19775552223"

As I need those to be under new objects with the name variable.

Keep uniform information in dataBase from events coming from smart contract in nodejs

I try to listen to two events I have in smart contracts (one of them smart contract factory) that are related to each other and save the information I get in the dataBase.
But once I have several users using a smart contract at the same time then the events are activated the information coming to the wrong dataBase gets confused among the users

const db = require("../connectDB/DB");
const Web3 = require("web3");
const HDWalletProvider = require("@truffle/hdwallet-provider");

const EzeyNFTABI = require("../../client/src/Artifacts/EzeyNFT.json");
const EzeyNFTFactoryABI = require("../../client/src/Artifacts/EzeyNFTFactory.json");

const wsProvider = new Web3.providers.WebsocketProvider(
  "wss://morning-twilight-cherry.matic-testnet.quiknode.pro/6ba9d2c5b8a046814b28f974c3643c679914f7ff/"
);

HDWalletProvider.prototype.on = wsProvider.on.bind(wsProvider);

let provider = new HDWalletProvider(
  "PRIVAE-KEY",
  wsProvider
);

const web3 = new Web3(provider);

let name;
let symbol;
let collectionAddress;
let addressWallet;
let walletID;
let tokenURI;
let description;

async function eventFactory_Handler(err, data) {
  let result = data.returnValues;
  if (!err) {
    name = result.name;
    symbol = result.symbol;
    collectionAddress = result.collectionAddress;
    addressWallet = result.addressWallet;
    walletID = result.walletID;
    console.log(result);
    EventFromMintNFT(collectionAddress);
  }
}
async function eventFromMintNFT_Handler(err, data) {
  let result = data.returnValues;
  try {
    if (!err) {
      tokenURI = result.tokenURI;
      description = result.description;
      console.log(result);
      await insertToCollectionTable();
    } else {
      console.log(err);
    }
  } catch (err) {
    console.log(err);
  }
}

async function eventFromMintNFT(newCollectionAddress) {
  try {
    let eventEmiterContract = new web3.eth.Contract(
      EzeyNFTABI.abi,
      newCollectionAddress
    );
    await eventEmiterContract.events.newCollection(eventFromMintNFT_Handler);
  } catch (error) {
    console.log(error);
  }
}
async function eventFromFactory() {
  try {
    let eventEmiterContract = new web3.eth.Contract(
      EzeyNFTFactoryABI.abi,
      "0x0a77174a8F78E64fFE589288D2C47AE83189dEAd"
    );
    await eventEmiterContract.events.newCollection(eventFactory_Handler);
  } catch (error) {
    console.log(error);
  }
} 

async function insertToCollectionTable(req, res) {
  try {
    async function insertToTable() {
      db.query(
        `INSERT INTO ezeyNFT.collectionNFT (NFTSymbol,NFTUrl,IDAddressWallet) VALUES ('${symbol}','${tokenURI}','${walletID}')  `,
        (err, newResult) => {
          if (err) throw err;
          console.log(newResult);
          return newResult;
        }
      );
    }

    db.query(
      `SELECT * FROM ezeyNFT.userNFT WHERE addressWallet = '${addressWallet}'  `,
      async (err, result) => {
        if (err) {
          throw err;
        } else if (result.length == 0) {
          async function newUser() {
            db.query(
              `INSERT INTO ezeyNFT.userNFT (id,addressWallet) VALUES ('${walletID}','${addressWallet}')  `,
              (err) => {
                if (err) throw err;
                return res;
              }
            );
          }
          await newUser();

          await insertToTable();
        } else {
          await insertToTable();
        }
        // console.log(result);
        // res.send(result);
        return result;
      }
    );
  } catch (error) {
    console.log(error);
  }
}  
}

eventFromFactory();


module.exports = {
  insertToCollectionTable, 
};

node writeFileSync not creating file

Here is the part that is not working:

fs.writeFileSync(`transcript${textChannel.id}.txt`,
                                        transcript.map(message =>
                                            `${message.author.tag}-${message.author.id} at ` +
                                            `${message.timestamp}: ${message.content}n` +
                                            `${message.embeds.join('n')}`
                                        ).join("nn")
                                    )

It is not creating the file, I don’t know what to do.

Turn traditional websites (HUGO in my case) into an SPA

The Problem

I’ve recently experimented with HUGO and it really surprised me how much I like how simple and fast it is compared to Gatsby and NextJS, the static website builders I’ve dealt with before.

The most important drawback from my perspective is that Gatsby produces

  • traditional static websites, where each site-internal navigation re-requests all common dependencies and loses all state, whereas the other two make
  • SPAs, where site-internal navigation does not cause common Javascript to be reprocessed.

While the advantages of SPAs are many, I’m only focusing on the points regarding in-page navigation:

  • It’s faster. It’s important to keep site navigation fast to avoid exposing a re-rendering of common page elements to the user (experienced as annoying flickering of the menus or even the page background). Static website pages can be served in 50ms or so, but browsers usually can’t do the rest quickly enough if they need to evaluate the scripts again.
    For example, the bootstrap docs, built with HUGO and quite responsive, are still not fast enough: It often flickers on navigation.
  • State can persist. That’s important because many Javascript tags used on traditional non-SPA websites can make use of that: For example, a chat window enters the screen in an animation, but only the first time – it then just stays where it is on internal navigation.

I’m asking here how I could, while keep using fast and simple HUGO, still at least get these two advantages.

A possible solution?

A somewhat hacky but very general approach I could think of would be to write a generic piece of Javascript that, just like SPAs,

  • intercepts browser navigation,
  • modifies all a tags to intercept clicks,
  • loads new pages with AJAX on those clicks rather than allowing browser handling,
  • change the content and fix the history.

In my case, I’d be perfectly happy to have the restriction to have the same head element and immutable outer layout (menus should be within that and still get loaded every time) except for a select few items such as the page title.

So, my questions here are

  • Is there an easier way?
  • Is there a problem with this approach I don’t see?
  • Do I have to write this myself or is there already something I could build upon?

how do i move a rectangle down in my javascript game

Im new to javaScript game development and I need to move a rectangle i created down for a simple movement in the game im making

player.downMovement = function() {
            let downBtn = document.getElementById('moveDown')
            downBtn.addEventListener('click', function movePlayerDown(){
                let playerY = player.y - 20
                function clearPlayer() {
                    ctx.clearRect(100, playerY + 20, 20, 20)
                }
                player.y = player.y + player.height;
                setTimeout(clearPlayer, 10)
            
            })  
            player.draw();
        }