WooCommerce Hook for Javascript Event

My goal here is to trigger:

('button.save-action').trigger('click');

After adding a product in the admin order creator because I am adding meta via the woocommerce_ajax_add_order_item_meta event but it will not show to the admin until either recalculate or save button is clicked.

here: plugins/woocommerce/assets/js/admin/meta-boxes-order.min.js:333 (need to reformat / unminify to see line number) I found this code:

    success: function( response ) {
                    if ( response.success ) {
                        $( '#woocommerce-order-items' ).find( '.inside' ).empty();
                        $( '#woocommerce-order-items' ).find( '.inside' ).append( response.data.html );

                        // Update notes.
                        if ( response.data.notes_html ) {
                            $( 'ul.order_notes' ).empty();
                            $( 'ul.order_notes' ).append( $( response.data.notes_html ).find( 'li' ) );
                        }

                        wc_meta_boxes_order_items.reloaded_items();
                        wc_meta_boxes_order_items.unblock();
                    } else {
                        wc_meta_boxes_order_items.unblock();
                        window.alert( response.data.error );
                    }
                },
                complete: function() {
                    window.wcTracks.recordEvent( 'order_edit_add_products', {
                        order_id: woocommerce_admin_meta_boxes.post_id,
                        status: $( '#order_status' ).val()
                    } );
                },
                dataType: 'json'
            });

Is there a way to listen to either this event:

window.wcTracks.recordEvent( 'order_edit_add_products', {

I have tried code like this but it doesn’t work:

jQuery().on('order_edit_add_products',function(){console.log('event triggered')})

I also saw this reference but I don’t think this way works either: https://nebula.gearside.com/how-to-use-the-javascript-wordpress-hooks-api-without-any-extra-libraries/

State Management for navigation bar

Im trying to use state management to modify my app and make it more generic. basicaly my app is react web app embedded with tableau dashboards, i need that specific routes (which hold specific dashboards) will be populated in the app through reading a json from the backend which specifies the project we want.

i need it in two ways:

UI project switch which lets me switch between projects
through the JWT which the front side recieves from a login attempt (upon sucsess)
i figured the only state needs managing is the navigation bar and its data, ill render the relevant paths and thus enable only the relevant dashboards by project/user.

this is the code for my navbar:

import React, { useState, useEffect } from "react";
import { Link, useLocation } from "react-router-dom";
import { NavbarData } from "./NavbarData";
import { IconContext } from "react-icons";
import "./Navbar.css";
import Hamburger from "./Icons/Hamburger.svg";
import "./Icons/p_logo_color.png";
import Persona from "./Icons/Persona.svg";
import Logout from "./Icons/Logout.svg";
//someting





//Navbar function
function Navbar() {
  const [sidebar, setSidebar] = useState(false);
  const showSidebar = () => setSidebar(!sidebar);
  const [pageName, setPageName] = useState('Operational Overview');
  const location = useLocation();
  

  

  const getPageTitleByUrl = (path) => {
    NavbarData.filter((navItem) => {
    
      if(navItem.path === path) {
        setPageName(navItem.title);
      }
     return true; 
    } )
    


  };

  const userConfigPageTitle = (path) => {
    setPageName("User Information");

  }

  

  useEffect(() => {
    if(location.pathname) {
      getPageTitleByUrl(location.pathname);
    }
  }, [location] ); 
  

  return (
    <>
      <IconContext.Provider value={{ color: "undefined" }}>
        <div className="navbar">
          <Link to="#" className="menu-bars">
             <img src={Hamburger} alt="hamburger" onClick={showSidebar} />
          </Link>

          <div className="criminal-records">Elecciones Guatemala |</div> 
          <div className="pageTitle"><h1>{pageName}</h1></div>

          <>
          <div><img className="userIcon" src={Persona} alt="persona" /> </div>
          <div className="userButton">User123#</div>
          </>

          <Link to='/' className="logout-button">
          <div><img className="logoutIcon" src={Logout} alt="persona" /> </div>
          <div className="logoutButton">Logout</div> 
          </Link>
          
        </div>
        <nav className={sidebar ? "nav-menu active" : "nav-menu"}>
          <ul className="nav-menu-items" onClick={showSidebar}>
            <li className="navbar-toggle">
          
            </li>
            {NavbarData.map((item, index) => {
              return (
                <li key={index} className={item.cName}>
                  <Link to={item.path}>
        
                  <span className="navbutton-icon">{item.icon}</span><span className="navbutton-text" >{item.title}</span>
                    
                    
                  </Link>
                  
                </li>
                
              );
            })}
          </ul>
        </nav>
      </IconContext.Provider>
    </>
  );
}

export default Navbar;

and this is NavbarData:

import React from 'react'



import startpageIcon from './Icons/startpage.svg';
import performance from './Icons/performance.svg';
import bars from './Icons/bars.svg';
import simulation from './Icons/simulation.svg';
import fraud from './Icons/fraud.svg';
import deployForNow from './Icons/Profiles.svg';
import Planning from './Icons/plan.svg';
import deployment from './Icons/layer1.svg';
import barswithperson from './Icons/barswithperson.svg'





export const NavbarData = [
    {
        title: 'Simulación',
        path: '/monitoringoverview',
        icon: <img  src={simulation} alt="" />,
        cName: 'nav-text'
    },
    {
        title: "Empadronados",
        path: "/performancequality",
        icon: <img src={barswithperson} alt="" />,
        cName: 'nav-text'
    }


]

so basically all i need is to connect the dropdown switcher to change the json structured data inside NavbarData, and define each of these variations as state. So since this is quite a simple state managing task i want to use React Context to solve it, how can i do it?

Thanks in advance!

While Next.js simplifies SSR implementation, certain bugs can still occur. Why?

I am working with Next.js and have noticed that while it simplifies server-side rendering (SSR) implementations, I have encountered some bugs. Specifically, I am curious about why these bugs can still occur despite using Next.js. Can anyone provide insights or explanations on this matter?

I was expecting that Next.js would handle SSR seamlessly and minimize the likelihood of encountering such issues. However, since that hasn’t been the case, I’m seeking further insights from the community to better understand the underlying causes of these bugs.

Javascript – tag/mention a person

I am trying to make a module in which you can tag/mention a person in your newsfeed. For example, if I am typing @sam then all persons with Sam’s name will come up. I am storing the entire user list in JSON in sessionStorage to make them load quickly (loading from Ajax wasn’t an option). The module is ready but the problem is currently it’s having only 200 users and that’s why it’s working perfectly. When the website will be having 50-60,000 users, sessionStorage/localStorage won’t be the feasible option as it has a capacity of 5 MB only.

The question is, is there any other alternative to these?

FYI – The JSON list contains 4 values: user ID (encrypted), user_name, profile_picture_url, and location.

Javascript and Jqeury consecutive countdown

I found a countdown script

JS FIDDLE

how do I change hours, minutes, second and title with JSON object like this?

[{"id":"1","title":"countdown 1","hour":"0","minute":"0","second":"10"},{"id":"2","title":"countdown 2","hour":"0","minute":"0","second":"10"},{"id":"3","title":"countdown 3","hour":"0","minute":"0","second":"10"}]

and show it one by one consecutively then redirect when all countdown done?

already using foreach loop, but it broke the countdown.
this script is different than other countdown that use Date.

Why am I getting double event triggers when changing the progress bar in Svelte?

It is my code, just add event listeners to a <video>:

<script >
    import {onMount} from "svelte";
    let video
    let time
    onMount(()=>{
        const events=["canplay","canplaythrough","seeked","seeking"]
        events.forEach((value)=>{
            video.addEventListener(value,()=>{
                console.log(value)})
        })
    })
</script>

<video src="/suzhou.mp4" controls
       bind:this={video}
       bind:currentTime={time}
></video>

When I changed the progress bar of <video>, it double triggers events.
double triggers

if I don’t bind the currentTime, it will only trigger once, which is my expected.
enter image description here

Pixi.js + gsap? Blurry background animation on mouse position change. How do they do it?

I found this cool looking website and I would like to understand how they’ve done this effect: https://monopo.london/

The background is a blurry, multiple color mesh gradient or something like that. When you move the mouse, the gradient points changes position but in a very interesting way.
As far as I can tell the website is using gsap and pixi.js . I looked into the pixi.js docs but cound’nt find any help there.

Can someone help me understand how they did this effect? I would really appreciate any help! Thanks 🙂

React.js : Getting CORS error when loading third-party website in an iframe

I am trying to load a third-party website in a React application using iframe in my website. I do not have access to the third-party website server so I cannot request them to add my domain in CORS policy.
The initial page of the third-party website loads successfully but when I try to login into the third-party website ends with CORS error.
I have tried few solutions below but none of them worked:

  1. making a proxy server using http-proxy-middleware.
  2. tried bypassing CORS restriction using JSONP
  3. I also tried cookies setting.

Someone on internet called this issue is caused by CSRF token which is implemented on server-side that generate a unique token for each user session to protect against Cross-Site request forgery attacks , in this case we can’t create this unique token exactly the same.

Please help me to solve this. Any suggestions/solutions would be appreciated.
Thanks in advance!!

How to fix the “Unexpected end of file” error

I hope this message finds you well. I am currently facing an issue with my code where I am encountering an error message stating “Unexpected end of file.” Despite my efforts, I have been unable to identify the specific cause of this error. I am reaching out to the community to seek guidance and insights into why this error occurs and how to resolve it.

I have thoroughly reviewed my code for missing or incorrect syntax elements, ensuring that all opening and closing symbols (braces, parentheses, brackets) are properly balanced. However, I have not been able to pinpoint the exact issue leading to the “Unexpected end of file” error.I was expecting for the error to vanish.

How to disable mouse gestures in edge browser with JavaScript?【The key is the edge browser】

I want to disable mouse gestures in edge browser with JavaScript,Because it interferes with my right-drawing function

I tried some event monitoring, but it didn’t work


<!doctype html>
<html lang='en'>
<head>
  <meta charset='UTF-8'>
  <meta name='viewport'
        content='width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0'>
  <meta http-equiv='X-UA-Compatible' content='ie=edge'>
  <title>edge mouse gestures</title>
</head>
<body>

<script>
  const fn = (e) => {
    e.preventDefault()
    e.stopPropagation()
  }
  document.addEventListener('mousedown', fn)
  document.addEventListener('contextmenu', fn)
  document.addEventListener('mousemove', fn)
  document.addEventListener('touchstart', fn, false)
  document.addEventListener('touchend', fn, false)
  document.addEventListener('touchmove', fn, false)
  window.addEventListener('mousedown', fn)
  window.addEventListener('contextmenu', fn)
  window.addEventListener('mousemove', fn)
  window.addEventListener('touchstart', fn, false)
  window.addEventListener('touchend', fn, false)
  window.addEventListener('touchmove', fn, false)
</script>
</body>
</html>

How to access a spreadsheet in local file system using a chrome extension?

I want to create a chrome extension that create a spreadsheet once installed on the browser and then get the path of this spreadsheet file and be ready to update that spreadsheet according to user interactions, i am using sheet.js to create and handle the spreadsheet

chrome.runtime.onMessage.addListener( () => {
 if(message.action  ='createWorkbook') {
     try{
         //creating the workbook object sheet.js
         const workbook = XLSX.utils.book_new();
         //hard coded spreadsheet header labels
         const worksheet = XLSX.utils.aoa_to_sheet(["name", "number", "age"]);
         var binaryString = XLSX.write(workbook, { type: "binary", bookType: "xlsx" });
         XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1");

         chrome.downloads.download({
             url: "data:application/octet-stream;base64," + btoa(binaryString),
              filename: "workbook.xlsx"
         })
     }

 }
})

now this works and prompt the user to save the file to the local file system correctly, but i need also to get the path where the user saved the file so i can save it to the local storage and use it later to reach the spreadsheet location when the user interact with the extension so it can modify the spreadsheet using the data collected from the user interaction with the extension on a certain website.

I tried alot of things, i think chrome.fileSystem API is now deprecated, How can i achieve that?

How to remove external js file on button press

!– begin snippet js hide false console true babel false —

!– language lang-js —

   suraj.js
  var mins=.1;
    var secs=mins60;
    function countdown() {
        setTimeout('Decrement()',60);
    }
    function Decrement() {
        if(document.getElementById) {
            minutes=document.getElementById(minutes);
            seconds=document.getElementById(seconds);
            if(seconds59) {
                seconds.value=secs;
            }
            else {
                minutes.value=getminutes();
                seconds.value=getseconds();
            }
            if(mins1) {
                minutes.style.color=red;
                seconds.style.color=red;
            }
            if(mins0) {
                 alert('time up');
                minutes.value=0;
                seconds.value=0;
            }
            else {
                secs--;
                setTimeout('Decrement()',1000);
            }
        }
    }
 
    function getminutes() {
        mins=Math.floor(secs60);
        return mins;
    }
 
    function getseconds() {
        return secs-Math.round(mins60);
    }

!– language lang-html —

!DOCTYPE html
html xmlns=httpwww.w3.org1999xhtml
head

!--LINK external js--
script type=textjavascript src=suraj.js data-scriptid=MyDomScriptscript

!-- Link jquery --
script type=textjavascript src=httpajax.googleapis.comajaxlibsjquery1.7.1jquery.min.jsscript

head
body onload=countdown()!-- Your web--
   
   button id=myBtnTry itbutton


 div style=display flex; width80%;
                justify-contentcenter; padding-top 0%;
        Time Left 
    div
    div style=display flex; width80%;
                justify-contentcenter; padding-top 0%;
        input id=minutes type=text style=width 3%; border none; font-size 16px;
                      font-weight bold; color black;
        font size=5
            
        font
        input id=seconds type=text style=width 3%; border none; font-size 16px;
                      font-weight bold; color black;
    div
    script type=textjavascript

document.getElementById(myBtn).addEventListener(click, function() {

let domScripts = document.querySelectorAll('[data-scriptid=MyDomScript]');
   domScripts.forEach(function(s) {
   s.remove();
});
});
script
body
html

!– end snippet —

How can i stop the timer on button press that will destroy js imported…or any manual way?

I want to remove script tag from DOM && completely erase the variables or events already defined by the script.