javascript how to get percetage increase in array of numbers

I am new to using vuejs and js lets say I have an array

[0, 2, 10, 13.5, 20, 30, 10, 10]

I want to be able to get their percentage increase. So in this example I should get an array like this:

[400%, 35%, 48.1481%, 50%, -66.6667%, 0%]

How do I get this result? I saw some solutions like:
Get percentage value from difference between two arrays javascript

But in that example there are two arrays, in mine I only have one array

Grouping elements of array on the basis of property

I have a array as follows:

data = [
{
  "id":1
  "name":"london"
},
{
  "id":2
  "name":"paris"
},
{
  "id":3
  "name":"london"
},
{
  "id":4
  "name":"paris"
},
{
  "id":5
  "name":"australia"
},
{
  "id":6
  "name":"newzearland"
}
]

At runtime this array can have n number of elements. I want to group this array with respect to name attribute. All the elements with same name should be moved to a separate array. I don’t know the what value can name have in advance. This is coming at runtime. For example, from above array I want final output as follows:

output:

newArray1 = [
 {
  "id":1
  "name":"london"
},
{
  "id":3
  "name":"london"
}
]

newArray2 = [
{
  "id":2
  "name":"paris"
},
{
  "id":4
  "name":"paris"
}
]

newArray3 = [
{
  "id":5
  "name":"australia"
}
]

newArray4 = [
{
  "id":6
  "name":"newzearland"
}
]

How can I do that?

Fabric JS Canvas loses editability and resizability when assigned to Vue data attribute

I have a Vue 3 Single File Component which houses a canvas element. I am using the fabric npm package. If I initialize the fabric canvas in the mounted hook using

data: function () {
 return {
  canvas: null,
 }
},
mounted: function () {
 const canvasElement = vm.$refs['canvas']
 const canvas = new fabric.Canvas(canvasElement)
}

The canvas works fine and I am able to resize components, edit text objects etc.

But when I add this line:

this.canvas = canvas

then all objects on the canvas lose their editable and resizable nature. (Double click on text doesn’t work, the corners don’t allow resizing when using the cursor). Has anyone else experienced this? Is there a known solution?

Javascript input form | display “creating… ” and refresh page

Below I have script js and form.

$(document).on('submit','#form_create_user',function(e){
    e.preventDefault();
    var fd = new FormData(this);
    var obj = $(this);
    fd.append('course_id', "<?php echo $this->uri->segment(4); ?>");
    obj.find('input[type="submit"]').val("Creating...")
    $.ajax({
        url: $(this).attr("action"),
        data: fd,
        cache: false,
        processData: false,
        contentType: false,
        type: 'POST',
        success: function (dataofconfirm) {
            // do something with the result
           // obj.find('input[type="submit"]').val("Confirm")
        }
    });
    $.ajax({
        url: "<?php echo site_url('home/saveValues/'); ?>",
        data: fd,
        cache: false,
        processData: false,
        contentType: false,
        type: 'POST',
        success: function (dataofconfirm) {
            // do something with the result
            toastr.success("Success created user.");
            obj.find('input[type="submit"]').val("Confirm")
        }
    });
  })
<form action="?" method="post" name="form_create_user" id="form_create_user">
      <input name="username" type="text" id="username" value="test"><input type="submit" name="Submit" value="Confirm">
</form>

When I click on submit form then this script change text on button from “create” to “creating…” and display success action. But now this take about 1sec.

I need extand this script and I need:
display “creating…” for one minute and then return a success action.

note: the script run by form I need to set to run immediately, but only return success after a minute and reload the page.

Can anyone help me?

web3 contract function on click is sending batch transactions

Background
I have a web3 dapp that is currently minting NFT’s correctly without issue.
When I call this mintNFT function, it sends a single transaction and succeeds each time.

I am adding functionality to “merge” two NFT’s using a contract function.
When I tie this new mergeTwoNFT to a button click, it seems to run the function multiple times as I get a metamask request for multiple transactions at once, sometimes 10-20 transactions to accept/reject at one time.
The first of these transactions will succeed however of course the remainder will fail because the tokenID 1/2 variables that we are merging are no longer owned by this user.

Request
I’m stuck on this sending multiple transactions. If I change the function call to be automatically run when the user “checks” two images they own, instead of using a button click event, it seems to work better without duplicate transactions but I don’t want this function to be called automatically upon two images being selected in case they’d like to undo it.

Code
This is my merge function. I have the same function for minting which works.
In the below example, alts is referencing the “checked” images on the UI that the user has selected.

async function mergeNFTs() {
    const alts = $("#NFTGallery2 > li > input:checked + label img").map(function() {
        return this.alt
    }).get();
    var nftChosen1 = alts[0]
    var nftChosen2 = alts[1]
    
    setFeedback(`Merging your ${nftChosen1} and ${nftChosen2}...`);
    setClaimingNft(true);

    dispatch(fetchData(blockchain.account));
    myContract.methods
        .mergeTwoNFT(nftChosen1, nftChosen2)
        .send({
            from: blockchain.account
        })
        .once('error', (err) => {
            console.log(err);
            setFeedback(
                "Sorry, something went wrong when Merging your NFT's please try again later."
            );
            setClaimingNft(false);
        })
        .then((receipt) => {

        var tokenId = receipt.events.Transfer[2].returnValues.tokenId;
        console.log(
          'Your new NFT ID is: ' + receipt.events.Transfer[2].returnValues.tokenId
        );

        
        setFeedback(
          `WOW, the ${CONFIG.NFT_NAME}  #${tokenId} is yours!`
        );

        myContract.methods
          .tokenURI(tokenId)
          .call()
          .then(function (res) {
            
            $.getJSON(res, function (data) {
              
              const mintedNFTImage = `  
                    <div class="layeredImg "sc-gKseQn gTjrPu" id="mintedImage">
                    <img id="imgbg" src="${data.image}"/>
                    
                    
                    </div>
                    <br>
                    `; 
              document.getElementById('NFTEmbed').innerHTML = mintedNFTImage;
            });
          })
          .catch(function (err) {
            console.log(err);
          });
        

        setClaimingNft(false);
        dispatch(fetchData(blockchain.account));
        getData();
        getData2();
    });
        
};
<button id="mergingButton" onclick=mergeNFTs() class="">MERGE</button>

Grease/tamper monkey script to look for specific HTML in page and alert

I would like a grease/tamper monkey script, that when I visit a page, it looks for the following HTML on the page, and if it is present alert.

<p>
  <script 
    type='text/javascript' 
    src='https://site_im_visiting.com/?a(6 hex characters)=(numbers)'>
  </script>
</p>

Additionally, I would like to look inside an array (of about 4k sites), to see if the site is in the array.

Vue 3 components not importing other vue components

My Vue component navbar.vue not import other components.

This is Vue 3 whit Option API, somebody can help me?

I’ve all components imported by index.js in the component folder

import navbar from '@/components/navbar.vue'
import btn from '@/components/btn.vue'

export {
  navbar,
  btn
}

This is the navbar.vue:

<template>
  <header class="navbar">
    <ul>
      <li>
        <router-link to="/">Home</router-link>
      </li>
      <li>
        <btn></btn>
      </li>
    </ul>
  </header>
</template>

<script>
import { btn } from '@/components'

export default {
  name: 'navbar',
  components: {
    btn
  }
}
</script>

This is the btn.vue components:

<template>
  <button class="btn" @click="$emit('click')">
    <slot/>
  </button>
</template>

<script>
export default {
  name: 'btn'
}
</script>

how to condition the display of a field in a reactjs form?

I’m using ReactJs as a frontend library. Actually I want to condition the display of a field in my form.
the field that I want to condition its display is “long_escalier”
I want to said : If(floor_no !=”rée de chanssée){ dispaly the field of long_escalier}
This is my code:


      <Form className='mt-2 pt-50'>
        <Row>
          <Col sm='12' className='mb-1'>

            <Label className='form-label' for='name'>
              Floor Number <span className='text-danger'>*</span>
            </Label>
            <input type='text' className="form-control"
              onChange={(e) =>
                setFloorno(e.target.value)
              }
              placeholder="floor no" />
            <small className='text-danger'>{errorList.floor_no}</small>
            <br />
          </Col>

        </Row>
        <Row>
          <Col sm='12' className='mb-1'>
        


            <Label className='form-label' for='long_escalier'>
              Longueur Escalier <span className='text-danger'>*</span>
            </Label>
            <input type='text' className="form-control"
              onChange={(e) =>
                setLongEscalier(e.target.value)
              }
              placeholder="Stair length" />
            <small className='text-danger'>{errorList.long_escalier}</small>
            <br/>
          </Col>
        </Row>
        <Row>
          <Col sm='12' className='mb-1'>

            <Label className='form-label' for='dispo_ascenseur'>
              Elevator availability
              <span className='text-danger'>*</span>
            </Label>
            <select id='dispo_ascenseur' className='form-control' onChange={(e) => setAscenseur(e.target.value)}>
              <option value='disponible'> Disponible </option>
              <option value='non disponible'> Non Disponible </option>
            </select>
            <small className='text-danger'>{errorList.dispo_ascenseur}</small>
            <br/>
          </Col>
        </Row>

        <Button onClick={addFloor} className='me-1' color='primary'>
          Submit
        </Button>
        <Button type='reset' color='secondary'>
          Cancel
        </Button>
      </Form>

And thanks for advance for anyone will help me

Getting image data from blob url

I have image elements in my DOM that use blob URL in their src attribute.
Think like this:

 <img class="full-media opacity-transition slow open shown" width="432"
 height="432" alt="" draggable="true"
src="blob:https://web.telegram.org/1c037f99-5201-45de-937c-548da5706021">

What I want is to be able to do some ocr on this image , however fetching the full url or even without the blob gives me a 404. How can I get the image either as a file or any acceptable format for tesseract.recognize?

Run Build command in React is giving me Error: Invalid Mapping

I keep getting this error when I run “npm run Build”. I.m making use of React and Tailwind CSS

Failed to compile.

static/css/main.fe47aa2f.css from Css Minimizer plugin
Error: Invalid mapping: {“generated”:{“line”:4,”column”:16607},”source”:”static/css/main.fe47aa2f.css”,”original”:{“line”:723,”column”:null},”name”:null}

Error using slate editor: Cannot read properties of undefined (reading ‘createElement’)

I’m trying to use slate editor, following the example exposed in the documentation.
I’m getting the next error:

page.tsx:33 Uncaught TypeError: Cannot read properties of undefined (reading 'createElement')
    at Widget (page.tsx:33:9)
    at renderWithHooks (react-dom.development.js:15015:20)
    at mountIndeterminateComponent (react-dom.development.js:17841:15)
    at beginWork (react-dom.development.js:19079:18)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3942:16)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3991:18)
    at invokeGuardedCallback (react-dom.development.js:4053:33)
    at beginWork$1 (react-dom.development.js:23994:9)
    at performUnitOfWork (react-dom.development.js:22806:14)
    at workLoopSync (react-dom.development.js:22737:7)

This is my code:

import {useState} from "react";
import {createEditor} from 'slate'

// Import the Slate components and React plugin.
import {Slate, Editable, withReact} from 'slate-react'
// TypeScript users only add this code
import {BaseEditor, Descendant} from 'slate'
import {ReactEditor} from 'slate-react'
import React from "react";

type CustomElement = { type: 'paragraph'; children: CustomText[] }
type CustomText = { text: string }

declare module 'slate' {
    interface CustomTypes {
        Editor: BaseEditor & ReactEditor
        Element: CustomElement
        Text: CustomText
    }
}

export /*bundle*/
function Widget() {
    const initialValue: CustomElement[] = []
    const [editor] = useState(() => withReact(createEditor()))
    const [value, setValue] = useState([])
    console.log("SI?", Slate, editor, Editable)
    return (
        <Slate
            editor={editor}
            value={value}
            onChange={newValue => setValue(newValue)}
        >
            <Editable />
        </Slate>
    )
}

I followed this documentation

Can anybody help me to understand where is the problem?

Javascript jquery AutoComplate İnput not Working

Javascript jquery AutoComplate İnput not Working .I can try but not this. Add package link but AutoComplate İnput not Working.
I want only add pack after autocomplete input working. Only this..I think insertCell Hard this.I dont understend this. id =’dap’

<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <title></title>
</head>
<body>
<script>
          $(function() {
    var availableTags = [
                          "arta",
                          "barta",
                          "barta2",
                  ];


  $("#dap").autocomplete({
      source:availableTags
  });
});
     </script> 


                                             <form method="post" action="add.php">
                                           <table id="table1">
                                           <tr>
                                            <br>
                                             <td colspan="4"><a onclick="myFunction1()"  style=" color: #000; margin-top: 10px" ><i></i> Paket Ekle</a>&nbsp;&nbsp; <a onclick="myDeleteFunction1()"  style="color: #000; margin-top: 10px" ><i ></i> Paket Sil</a></td>
                                             
                                          </tr>
                                          <tr>
                                          
                                             <td valign="bottom"><strong>GTIP No.</strong></td>
                                      
                                            </tr>
                                          <tr>
                                      
                                         <td><input name="dap" type="text"   style="width:90%; margin-top: 15px"></td>

                                        
                                             <script>
                                       var i = 1;
                                          function myFunction1() {
                                              var table = document.getElementById("table1");
                                              var row = table.insertRow(-1);
                                              var cell1 = row.insertCell(0);
                                           
                                             
                                          cell1.innerHTML = "<input name='dap"+i+"'  id='dap'  type='text'  style='width:90%;margin-top:15px;' >";
                    
                                          i++;
                                          }

                                          function myDeleteFunction1() {
                                              document.getElementById("table1").deleteRow(-1);
                                          }

  
                                       </script> 
                                       </table>
                                     </form>
</body>
</html>

how to get which field clicked in formly-form?

I have a formly-form with icon addon wrapper. i want to get fields value when user clicked icon of that field.

Look in Addon wrapper there is icon and onClick call showFile funtion and there want to get which field of form icon clicked with that field value.

fields: FormlyFieldConfig[] = [
    {
      key: 'input',
      type: 'input',
      templateOptions: {
        label: 'name',
        addonRight: {
           icon:'remove_red_eye',
        },
      },
    },
  }

Form

<form  [formGroup]="form">
    <formly-form [model]="model" [fields]="fields"  [form]="form"></formly-form>
</form>

Addon wrapper

import { Component, TemplateRef, ViewChild, AfterViewInit } from '@angular/core';
import { FieldWrapper } from '@ngx-formly/core';

@Component({
  selector: 'formly-wrapper-addons',
  template: `
  <ng-container #fieldComponent></ng-container>

  <ng-template #matSuffix>
    <span
      *ngIf="to.addonRight"
      [ngStyle]="{cursor: to.addonRight.onClick ? 'pointer' : 'inherit'}"
      (click)="addonRightClick($event)"
    >
    
      &nbsp;<mat-icon *ngIf="to.addonRight.icon" type="button" (click)="showFile($event)">{{ to.addonRight.icon }}</mat-icon>
      &nbsp;<span *ngIf="to.addonRight.text">{{ to.addonRight.text }}</span>
    </span>
  </ng-template>
  `,
})
export class FormlyWrapperAddons extends FieldWrapper implements AfterViewInit {
  @ViewChild('matSuffix') matSuffix: TemplateRef<any>;

  ngAfterViewInit() {
    

    if (this.matSuffix) {
      Promise.resolve().then(() => this.to.suffix = this.matSuffix);
    }
  }

  addonRightClick($event: any) {
    if (this.to.addonRight.onClick) {
      this.to.addonRight.onClick(this.to, this, $event);
     
    }
  }
  showFile($event:any){
    //here i got mouse event
    //want to know which field of form icon clicked with input value
    console.log($event)
  }
}