How to make a website store user data but anybody can see that data when they open the site? [closed]

I would like to use vanilla js for this if possible, what I would like to do would be to store data similar to the function localStorage but I want every user that opens the site to see the info.

I really cant find anything online about storing data in this way, I’ve looked at several different websites and used different searches but I can’t find anything on it.

How to listen to Container Style Query change

Update 1 – I found a horrible workaround based on a custom property + ResizeObserver + window.getComputedStyle(), it might hold the water until a better solution arrives. It’d be still be great to know if the listener is coming.

I’m looking to add a listener for a container style query change after exhausting all other avenues (such as MutationObserver etc.), by analogy with media queries.

Does this possibility exist even as an experimental feature or is it planned at all any inside is highly appreciated.

Does anyone knows how to fix this in react, im leaarning the language but it kept telling me this. Some help please? [closed]

I tried importing the NavBar from different parts in the src but still not working. I applied css, javascript on the NavBar but still wont work

import logo from "./logo.svg";
import "./App.css";
import NavBar from "../components/NavBar";
import "bootstrap/dist/css/bootstrap.min.css";

function App() {
  return (
    <div className="App">
      <NavBar />
    </div>
  );
}

export default App;
import { useState, useEffect } from "react";
import { Navbar, Container, Nav } from "react-bootstrap";
import logo from "../Assets/img/logo.svg";
import navIcon1 from "../Assets/img/nav-icon1.svg";
import navIcon2 from "../Assets/img/nav-icon2.svg";
import navIcon3 from "../Assets/img/nav-icon3.svg";`

Find duplicates from two arrays of objects and return boolean (Javascript)

There are two arrays of objects and I need to check if there’s any property that’s matching by comparing those two arrays. For example,

const array1 = [{name: 'foo', phoneNumber: 'bar'}, {name: 'hello', phoneNumber: 'world'}]
const array2 = [{name: 'hi', phoneNumber: 'earth'}, {name: 'foo', phoneNumber: 'bar'}]

In this case since 1 property from each array is matching and I would like to return true. In case of none of the properties matching I would like to return false.

Thanks in advance!

Error: Could not establish connection. Receiving end does not exis

So my issue is that I want to make a chrome extension to read the header and content of a webpage, but I am stuck at the initial stage of development, where this error shows up and the debug message doesn’t appear.
The code is as follows:
MANIFEST VERSION 3

content.js

(() => {
  chrome.runtime.onMessage.addListener((obj, sender, response) => {
    
      const { type, value } = obj;
  
        if (type === "NEW") {
        console.log("Hi");
        newVideoLoaded();
        response([]);
        chrome.runtime.lastError ;
      }
    });
  })();

background.js

chrome.tabs.onUpdated.addListener((tabId, tab) => {
    if (tab.url && tab.url.includes("cnbc")) {


        console.log("Hello world");
        chrome.tabs.sendMessage(tabId, {
        type : 'NEW',
        value: ''
        
      });
    }
  });

The error appears, and there is a similar question whose answers i tried but it didn’t work.
Please help!

I want to make a chrome extension to read the header and content of a webpage, but I am stuck at the initial stage of development, where this error shows up and the debug message doesn’t appear.

Trying to link to a specific shuffle state using Shuffle.js on another page

I’m using a gallery called Shuffle.js – https://vestride.github.io/Shuffle/ – for a house painter’s website. The gallery sorts by service type (i.e. “carpentry, etc.”) and it functions fine. I have links on individual service pages under the “What Makes Us Different” paragraph – https://scotlandpaintingco.com/carpentry.html – that say “see more examples of our carpentry work” that link to the gallery on the “Our Work” page – https://scotlandpaintingco.com/our-work.html. What I’m trying to do is make a unique href for each service page that links to the gallery already filtered for that category on page load (i.e. “carpentry”) instead of “Show All”.

I haven’t been able to figure out how to implement this but understand that I need to use JS to add a fragment link to “our-work.html”. (i.e. “our-work.html#carpentry”) whenever a specific filter is selected, and the fragment must have the service value (the gallery uses data-groups). Then I can link from the service pages using a url with the hashtag. I keep coming across “window.location.hash” in other forums but I can’t figure out how to use this to accomplish my goal or how to integrate it into the code.

javascript enter a value in textbox check my code

I am trying to fill in a text box on a browser using the code I have.
It adds the value to the text box but as soon as I click text box it disappears.

Looking at the Firefox element checker I can see the actual value =”” in HTML not changing only the front of html being inputted.

here is the code i have and html.

here is the javascript code am using

document.getElementsByClassName(
  'appearance-none block w-full px-3 py-2.5 border placeholder-gray-400 focus:outline-none text-sm rounded-lg border-gray-200 focus:ring-1 focus:border-transparent focus:ring-purple-1'
)[0].value = 'your value';

here is part of the html

<input
    class="appearance-none block w-full px-3 py-2.5 border placeholder-gray-400 focus:outline-none text-sm rounded-lg border-gray-200 focus:ring-1 focus:border-transparent focus:ring-purple-1"
    placeholder="Artificial Intelligence in Copywriting" 
    value="">

extra code

<div><div class="flex justify-between items-center relative w-full"><div class="flex flex-wrap mb-1 items-center "><label class="block text-base font-medium text-gray-700">Title</label><span class="ml-1 text-red-500">*</span></div><p class="text-xxs font-medium text-gray-400">1 / 200</p></div><div class="flex items-center"><div class="relative w-full"><input class="appearance-none block w-full px-3 py-2.5 border placeholder-gray-400 focus:outline-none text-sm rounded-lg border-gray-200 focus:ring-1 focus:border-transparent focus:ring-purple-1" placeholder="Artificial Intelligence in Copywriting" value=""></div></div></div>

Solidity mint function on multimint smart contract – payable nft not working

I have a smart contract in solidity of an NFT collection. The point is that I have 2 different mints. A mint that needs a whitelist of a soulbound NFT and another mint that would be a sales collection (with a cost in MATIC, ETH whatever). I already have the soulbound mint functional, but I’m not getting the sales mint to work. The safeMintNft() function is triggered to mint this sales collection.

function safeMintNft() public payable whenNotPaused {
    require(
        nftCost > 0, "NFT cost is not set"
    );

    require(
        keccak256(bytes(whitelistedAddresses[msg.sender].discordUser)) !=
            keccak256(""),
        "Address is not whitelisted"
    );

    require(
        keccak256(bytes(whitelistedAddresses[msg.sender].user_type)) == keccak256(bytes("buyer")),
        "Only buyers can mint the NFT"
    );
    uint256 minterBalance = address(msg.sender).balance;
    require(
        minterBalance >= nftCost,
        "not enough tokens to pay for this NFT"
    );

    
    uint256 tokenId = _tokenIdCounter.current();
    _tokenIdCounter.increment();
    tokenIdAddresses[tokenId] = msg.sender;

    address payable contractAddress = payable(address(this));
    contractAddress.transfer(nftCost);

    _safeMint(msg.sender, tokenId);
}

Then I’m testing it with chai. The code snippets that reach this case is below:

describe("User has enough eth to mint", async function() {
     beforeEach(async function() {
         await this.nft.setNftCost(ethers.utils.parseEther("0.1"));
      });
      it("should be able to mint", async function() {
         const tx = await this.nft.connect(this.normalUser).safeMintNft();
         const waitedTx = await tx.wait();
         expect(waitedTx.status).to.equal(1);
      });
});

When it reaches this case, we set the cost to 0.1 ether (and the account normalUser has it because it is a hardhat account with 999+ ether). When it reaches the it statement, I get this error:

Error: Transaction reverted: function call failed to execute
at MelkExp.safeMintNft (contracts/MelkExp.sol:107)

And the line 107 is contractAddress.transfer(nftCost);

Any ideas? If any info is missing, i’ll edit or answer in comments

Search button not working on pressing a second time (`addEventListener`)

I have a search field (input of type text) and a search button, as follows:

<div id = 'results-container'> 
    <input type="text" placeholder="Search..." id="search-bar">
    <button type="submit" id="search">Search</button>
</div>

in my HTML. Correspondingly, the JavaScript file looks like this:

const searchButton = document.getElementById('search');
const searchField = document.getElementById('search-bar');
const output = document.getElementById('results-container');
searchButton.addEventListener('click', getSongs);

function getSongs() {
    /* do something */
}

where “do something” is effectively to fetch data from the iTunes API and append it to the body of output (using output.innerHTML += "foo").

On reloading a page, the first search attempt runs properly–I enter a value, and click on the search button, and results show up, as expected. However, if I now enter another value into the search bar and press ‘Search’, nothing happens (I think: there are no console logs).

What could possibly be the issue?

React Js data.map creating formatting issue with divs

I have a Golf Scorecard that displays fine if I manually generate each row using divs but when I try and generate the divs in a data.map loop then it the formatting is all lost and doesnt display correctly.

Here is the code:

             <div className="griditem"></div>
          <div className="griditem">Total</div>
          <div className="griditem">
            <input type="text" className="input" />
          </div>
          <div className="griditem">
            <input type="text" className="input" />
          </div>
          <div className="griditem yellow">
            <input type="text" className="input" />
          </div>
          <div className="griditem">
            <input type="text" className="input" />
          </div>
          <div className="griditem">
            <input type="text" className="input" />
          </div>
          <div className="griditem">
            <input type="text" className="input" />
          </div>
          <div className="griditem">
            <input type="text" className="input" />
          </div>
          <div className="griditem">
            <input type="text" className="input" />
          </div>
          <div className="griditem red">
            <input type="text" className="input" />
          </div>
          <div className="griditem red">
            <input type="text" className="input" />
          </div>
          <div className="griditem fred">
            <input type="text" className="input fred" />
          </div>
        

This is how I put it in the data.map:

         {data.map((item, index) => (
        <div key={index}>
          <div className="griditem"></div>
          <div className="griditem">Total</div>
          <div className="griditem">
            <input type="text" className="input" />
          </div>
          <div className="griditem">
            <input type="text" className="input" />
          </div>
          <div className="griditem yellow">
            <input type="text" className="input" />
          </div>
          <div className="griditem">
            <input type="text" className="input" />
          </div>
          <div className="griditem">
            <input type="text" className="input" />
          </div>
          <div className="griditem">
            <input type="text" className="input" />
          </div>
          <div className="griditem">
            <input type="text" className="input" />
          </div>
          <div className="griditem">
            <input type="text" className="input" />
          </div>
          <div className="griditem red">
            <input type="text" className="input" />
          </div>
          <div className="griditem red">
            <input type="text" className="input" />
          </div>
          <div className="griditem fred">
            <input type="text" className="input fred" />
          </div>
        </div>
      ))}

How the formatting should appear

how the formatting appears in a data.map

You cannot access body after reading from request’s data stream

I keep getting the following error when trying to post to PayPal:

shippingData = json.loads(request.body)

django.http.request.RawPostDataException: You cannot access body after reading from request's data stream

I have tried removing the request.headers, this does nothing. I tried removing CRSF Token altogether and still the same error. I have also tried renaming request.body into a different variable, this also does not remove the error. Replacing with request.data just gives a different error also.

This is my view:

def create_order(request):
    customer = Customer.objects.get(user=request.user)
    shippingData = json.loads(request.body)
    first_name = customer.first_name
    last_name = customer.last_name
    
    ShippingAddress.objects.create(
        customer=customer,
        house=shippingData['shipping']['house'],
        street=shippingData['shipping']['street'],
        city=shippingData['shipping']['city'],
        postcode=shippingData['shipping']['postcode'],
    )

    # assuming you have retrieved the ShippingAddress object for the given customer
    shipping_address_queryset = ShippingAddress.objects.filter(customer=customer)
    if shipping_address_queryset.exists():
        shipping_address = shipping_address_queryset.first()

    # extract the necessary fields from the shipping_address object
    house = shipping_address.house
    street = shipping_address.street
    city = shipping_address.city
    postcode = shipping_address.postcode
    
    user_cart = Cart.objects.filter(user=request.user).first()

    if user_cart:
    # get cart items and total
        cart_items = user_cart.items.all()
        cart_total = user_cart.get_cart_total()

        # create the items list
        items = []
        for item in cart_items:
            items.append({
                "name": item.product.title,
                "description": "",
                "quantity": str(item.quantity),
                "unit_amount": {
                    "currency_code": "GBP",
                    "value": "{:.2f}".format(item.product.price)
                },
                "tax": {
                    "currency_code": "GBP",
                    "value": "0.00"
                }
            })

        # calculate the breakdown for the purchase unit
        item_total = sum(float(item["unit_amount"]["value"]) * int(item["quantity"]) for item in items)
        amount_breakdown = {
            "item_total": {
                "currency_code": "GBP",
                "value": "{:.2f}".format(item_total)
            },
            "shipping": {
                "currency_code": "GBP",
                "value": "0.00"
            },
        }
    
    access_token = settings.PAYPAL_ACCESS_TOKEN
    # Create a new PayPal order
    headers = {
        'Content-Type': 'application/json',
        'X-CSRFToken': request.headers['X-CSRFToken'],
        'Authorization': 'Bearer ' + access_token,
    }
    data = {
        "intent": "CAPTURE",
        "paypal": {
                "experience_context": {
                    "payment_method_preference": "IMMEDIATE_PAYMENT_REQUIRED",
                    "payment_method_selected": "PAYPAL",
                    "brand_name": "Martin Henson Prints",
                    "locale": "en-GB",
                    "landing_page": "LOGIN",
                    "user_action": "PAY_NOW",
                    "shipping_preference": "SET_PROVIDED_ADDRESS",
                }
            },
        "purchase_units": [{
            "amount": {
                "currency_code": "GBP",
                "value": "{:.2f}".format(cart_total),
                "breakdown": amount_breakdown
            },
            "items": items,
            "shipping": {
                    "name": {
                        "full_name": f"{first_name} {last_name}"
                    },
                    "address": {
                        "address_line_1": f"{house} {street}",
                        "admin_area_2": city,
                        "postal_code": postcode,
                        "country_code": "GB"
                    }
                }
            }]
        }

    response = requests.post('https://api.sandbox.paypal.com/v2/checkout/orders', headers=headers, json=data)

React redirect/push from Next lifecycle at event handler from class-based component

I need to make a redirect from inside an onSubmit call.

Currently the full code is as below, and I need to keep CampaignNew as a class-based component. How can I do it?

import React, { Component } from 'react';
import Layout from '../../components/layoyt';
import { Form, Button, Input, Message } from 'semantic-ui-react';
import factory from '../../components/factory';
import web3 from '../../components/web3';

class CampaignNew extends Component {
    state = {
        minimumContribution: '0',
        errorMessage: '',
        loading: false
    };

    onSubmit = async (event) => {
        event.preventDefault(); // Prevent the browser to attemp submission at initialization

        this.setState({ loading: true, errorMessage: '' });

        try {
            await window.ethereum.enable();
            const accounts = await web3.eth.getAccounts();
            console.log('Account :' + accounts[0]);

            await factory.methods
                .createCampaign(this.state.minimumContribution)
                .send({
                    from: accounts[0]
                });

            //// !!PUSH_TO_('/')

            this.setState({ loading: false });

        }
        catch (err) {
            this.setState({ errorMessage: err.message });
            this.setState({ loading: false });
        }

    };

    render() {
        return (
            <Layout>
                <h3>
                    Create a Campaign
                </h3>
                <Form onSubmit={this.onSubmit} error={!!this.state.errorMessage}>
                    <Form.Field>
                        <label>Minimum Contribution</label>
                        <Input label='wei'
                            labelPosition='right'
                            value={this.state.minimumContribution}
                            onChange={event => this.setState({ minimumContribution: event.target.value })}
                        />
                    </Form.Field>

                    <Message error header='There was some errors with your submission' content={this.state.errorMessage} />
                    <Button loading={this.state.loading} primary>Create</Button>
                </Form>
            </Layout>
        );
    }
}

export default CampaignNew;

Can’t get to move around inside iframe body

I have created an organization chart using divs and css.
I’ve connected children with parent using Leaderline.js library. I want to pinch and move around the chart but I cant because each move I need to position SVG lines because they are created auto outside div container. By using position() function its very laggy.

I’ve tried using iframe so that I could move body around and the lines would stay in place but I can’t move body for some reason in the outer html.
So maybe anyone know is there a global position for all lines instead of looping each variable line because I have around 700. Or how do I make it in iframe so that I could just move around the body like it’s a picture.

The chart is basic just a div container and inside chart container in which I loop through data and display it.

How to remove any JavaScript code From a Dom element

Question: How to remove any JavaScript code (functions, variables, events etc.) which is Inside a Dom element (div)

Note: This is not similar question like removing content from Dom element.

My Scenario:

My site has a menu. When I click on a menu item I am loading corresponding html file which also contains JavaScript code inside a div element(id=content).
When click on menu I am doing following code

function changeMenu(params){
  //need something here to remove previous js codes before load the file
  $('#content').load(params['file'],function (){
        ///ohters code
    })
}

It is working fine for first click and executing the JavaScript code as well inside that file.
But problem is it also increase executing JavaScript code number of times I click on the menu. Also when I load another file still previous JavaScript code executing because I had interval function there. Aslo if there is variable declared like this let x=10
it showing follwing error when I click the menu again

Uncaught SyntaxError: Identifier ‘x’ has already been declared

Asking Solution:
Is it posible remove all JavaScript codes when I click on the menu and How?