Disabling Cargo Collective Navigation Shortcuts

I am a typeface designer and just built a website in Cargo.site. (pedroglifos.com) I am using Fontdue type testers integration so my customers can test the fonts. Everything was fine until I realized that Cargo has a built in code that has some unnecessary navigation functionalities, such as: when pressing the “R” key, a random page will load. Pressing shift+E triggers the admin console. The arrow keys cycle through the website pages…

This is all FUN until it prevents my type testers to work correctly. The very first lines of their code are supposed to prevent these functionalities to work on inputs and textareas, but their script doesn’t recognize my type testers as such because they’re scripts as well.

Cargo only allows me to place custom scripts in the head element, globally, or to each page. I have tried several things, from from trying to disable handleGlobalKeyDown entirely, trying to intercept it to change it’s functionality, and even tried to trick the script in thinking my type-testers are textareas by dynamically modifying the nodeName property of the type testers elements — but then they stop working.

Is there a sensible way I can stop this Cargo core script from working?

Heres the problematic portion of the Cargo Script global-events-handler.js:

handleGlobalKeyDown = e => {

        if(
            e.target.nodeName === "INPUT"
            || e.target.nodeName === "TEXTAREA"
        ) {
            // ignore key events when typing in input fields / textareas
            return;
        }

        const state = this.props.store.getState();

        if(!this.props.adminMode) {

            if( ( this.isMac && e.metaKey && e.which === 191 ) || ( !this.isMac && e.ctrlKey && e.which === 191 ) ) {
                
                    // cmd + / / cmd + ? to recognize Cargo sites
                    this.showCargoSiteIndicator();

                    // Only listen to metakey event in special cases so we don't 
                    // break native functionality like cmd + r to refresh
                    return;
            }

            if( ( this.isMac && e.metaKey && e.which === 27 ) || ( !this.isMac && e.ctrlKey && e.which === 27 ) ) {
                
                    // cmd + esc
                    this.openAdmin();
                    
                    // Only listen to metakey event in special cases so we don't 
                    // break native functionality like cmd + r to refresh
                    return;
            }

            // shift + a / shift + e
            if(
                e.shiftKey 
                && (e.keyCode === 65 || e.keyCode === 69) 
                && !state.frontendState.contactForm.inited 
                && !state.frontendState.cartOpen
                && !state.frontendState?.quickView?.inited 

            ){

                if (this.props.inAdminFrame) {

                    // make sure viewers aren't escaping preview
                    if(this.props.editorRole !== "Viewer") {

                        if(this.props.activePID && this.props.activePID.length > 0 && this.props.activePID !== 'root') {
                            parent.navigateAdmin('/' + this.props.activePID);
                        } else {
                            parent.navigateAdmin('/');
                        }

                    }

                } else {
                    this.openAdmin();
                }
            }
            // left, right, r
            if(
                e.keyCode === 82
                && !state.frontendState.contactForm.inited
                && !state.frontendState.cartOpen
                && !state.frontendState?.quickView?.inited
                && !e.metaKey
                && !e.ctrlKey
            ) {
                e.preventDefault();
                this.loadRandomPage();
            } else if(
                // arrow left
                e.keyCode === 37
                && !state.frontendState.contactForm.inited
                && !state.frontendState.cartOpen
                && !state.frontendState?.quickView?.inited 
                && !e.metaKey
                && !e.ctrlKey
            ) {
                e.preventDefault();
                this.loadPrevPage();
            } else if(
                // arrow left
                e.keyCode === 39
                && !state.frontendState.contactForm.inited
                && !state.frontendState.cartOpen
                && !state.frontendState?.quickView?.inited 
                && !e.metaKey
                && !e.ctrlKey
            ) {
                e.preventDefault();
                this.loadNextPage();
            }

My Fontdue type testers are integrated with an initial code in head:

<link rel="stylesheet" href="https://js.fontdue.com/fontdue.css">
<script type="text/javascript" src="https://js.fontdue.com/fontdue.js"></script>
<script>
  fontdue.initialize({
    url: "https://store.pedroglifos.com",
    config: {
      typeTester: {      
        min: 6,
        max: 480,
        selectable: true,
        textInput: true,
        groupEdit: false,
        initialMode: 'local',
        shy: false,
        buyButton: false,
        truncate: true,
        selectButtonLabel: 'Get',
        selectButtonStyle: 'outlined',
      },
    },
  });
</script>

And modular components where I want them to appear in the body:

<!-- Type Tester Start -->
<fontdue-type-testers collection-id="Rm9udENvbGxlY3Rpb246MTY5MDQzMDM5OTg5OTM1MDY2OA=="></fontdue-type-testers>

<!-- Character Viewer Start -->
<fontdue-character-viewer collection-id="Rm9udENvbGxlY3Rpb246MTY5MDQzMDM5OTg5OTM1MDY2OA=="></fontdue-character-viewer>

I tried overriding:

<script>
  function handleGlobalKeyDown(e) {
  }
</script>

Also tried to trick Cargo into thinking my type testers are text areas

<link rel="stylesheet" href="https://js.fontdue.com/fontdue.css">
<script type="text/javascript" src="https://js.fontdue.com/fontdue.js"></script>
<script>
  fontdue.initialize({
    url: "https://store.pedroglifos.com",
    config: {
      typeTester: {      
        min: 6,
        max: 480,
        selectable: true,
        textInput: true,
        groupEdit: false,
        initialMode: 'local',
        shy: false,
        buyButton: false,
        truncate: true,
        selectButtonLabel: 'Get',
        selectButtonStyle: 'outlined',
      },
    },
  });

  document.addEventListener('DOMContentLoaded', function() {
    const fontdueTypeTesters = document.querySelectorAll('fontdue-type-testers');
    fontdueTypeTesters.forEach(function(element) {
      Object.defineProperty(element, 'nodeName', { value: 'TEXTAREA', writable: false });
    });
  });
</script>

Error: missing arguemnt: types/values length mismatch (count=0, expectedCount=1, code=MISSING_ARGUMENT, version=6.11.1)

how can i deploy the contracts below as Transparent upgradable proxies using hardhat and javaScript, note that initialValue argument are required in order to call getEmetisContractAddress in the base contract and Base contract address is need in order to initialize the Messenger contract
`Solidity

// Contract Base.sol
//SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

contract Messenger {
    address private baseContractAddress;

    function initialize(address _baseContractAddress) external {
        baseContractAddress = _baseContractAddress;
    }

    function printAddress() public view returns (address) {
        return baseContractAddress;
    }
}
// Contract Base.sol 
//SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

contract Base {
    address private messengerContractAddress;

    function initialize(bytes calldata initialValue) external {
        // Decode the address from the initialization data
        messengerContractAddress = abi.decode(
            initialValue,
            (messengerContractAddress)
        );
    }

    function getMessengerContractAddress() public view returns (address) {
        return messengerContractAddress;
    }
}

error message

Nextjs struggling to improve LCP for text

I am trying to improve my LCP score by optimizing my text but still now it’s same and I don’t know why my LCP not improving. see the screenshot:

enter image description here

It is saying that ‘Popular Products for Daily Shopping’ is my Largest Contentful Paint element, and it’s taking almost 3,590 ms. If I remove this text from my page.js, then another text appears, and if I remove that text, another text shows up again for LCP.

I tried to laod google font on my server side but didn’t work.

my page.js

import HomePage from '../components/Home/Home'
import { headers } from 'next/headers'
import { Inter } from 'next/font/google'

const inter = Inter({subsets:['latin']})

export default async function Home() {return (
    <>
    
    <main className={inter.className}>
      <HomePage />
    
     
    </main>
    </>
  );
}

here is my Popular Products section

<div className="mb-10 flex justify-center">
        <div className="text-center w-full lg:w-2/5">
          <h2 className="text-xl lg:text-2xl mb-2 text-emerald-500 font-semibold">
            Popular Products for Daily Shopping
          </h2>
        
        </div>
      </div>

My text is only one line, and I don’t understand how a one-line text can be the Largest Contentful Paint (LCP) of my page when my images are well-optimized, and there isn’t even any LCP for images.

JavaScript custom .sort() of double array object using .localeCompare() not working

I was working on a solution to a leetcode problem (https://leetcode.com/problems/sender-with-largest-word-count/) when I hit a scenario I spent hours trying to debug and still can’t figure out what’s going on. To simplify, given an object:

let items = [
  [ 'K', 4 ],           [ 'kFIbpoFxn', 10 ],  [ 'yErgn', 6 ],
  [ 'N', 8 ],           [ 'wtJesr', 9 ],      [ 'rusffeL', 14 ],
  [ 'KlpoodEd', 5 ],    [ 'qGcQqIVdFr', 1 ],  [ 'ztmCdK', 10 ],
  [ 'HFILjKln', 12 ],   [ 'TmmQZ', 18 ],      [ 'R', 7 ],
  [ 'CNh', 7 ],         [ 'YMQDBkOWy', 22 ],  [ 'kjiSc', 4 ],
  [ 'cGMsZxxx', 6 ],    [ 'PPqsmNBewN', 21 ], [ 'gbtn', 10 ],
  [ 'nQNcL', 8 ],       [ 'rK', 10 ],         [ 'ppr', 16 ],
  [ 'LhSVp', 11 ],      [ 'Ub', 7 ],          [ 'QGRFMLY', 11 ],
  [ 'SdDObYkD', 9 ],    [ 'q', 3 ],           [ 'suAakSCuHz', 6 ],
  [ 'dnzhjdwrEt', 8 ],  [ 'ubIEXAO', 22 ],    [ 'EsBuLal', 11 ],
  [ 'xlQqQRrdTv', 12 ], [ 'mWxCG', 8 ],       [ 'DmwIEmS', 5 ],
  [ 'nBQLLS', 6 ],      [ 'QhF', 4 ],         [ 'bmtYQKYv', 5 ],
  [ 'PRiNk', 7 ],       [ 'QyYJw', 7 ],       [ 'QIFauTN', 3 ],
  [ 'zJLcUq', 13 ],     [ 'TU', 1 ],          [ 'lCkGjDY', 7 ],
  [ 'A', 6 ]
]

I am attempting to sort it based first on highest integer, but if those values are equal, by largest lexicographical value, ie the .reverse() of how JS sorts strings by default

my sorting code is:

items.sort(function(a, b) {
  return b[1] !== a[1] ? b[1] - a[1] : -a[0].localeCompare(b[0]);
});

resulting in:

[
  [ 'YMQDBkOWy', 22 ], [ 'ubIEXAO', 22 ],    [ 'PPqsmNBewN', 21 ],
  [ 'TmmQZ', 18 ],     [ 'ppr', 16 ],        [ 'rusffeL', 14 ],
  [ 'zJLcUq', 13 ],    [ 'xlQqQRrdTv', 12 ], [ 'HFILjKln', 12 ],
  [ 'QGRFMLY', 11 ],   [ 'LhSVp', 11 ],      [ 'EsBuLal', 11 ],
  [ 'ztmCdK', 10 ],    [ 'rK', 10 ],         [ 'kFIbpoFxn', 10 ],
  [ 'gbtn', 10 ],      [ 'wtJesr', 9 ],      [ 'SdDObYkD', 9 ],
  [ 'nQNcL', 8 ],      [ 'N', 8 ],           [ 'mWxCG', 8 ],
  [ 'dnzhjdwrEt', 8 ], [ 'Ub', 7 ],          [ 'R', 7 ],
  [ 'QyYJw', 7 ],      [ 'PRiNk', 7 ],       [ 'lCkGjDY', 7 ],
  [ 'CNh', 7 ],        [ 'yErgn', 6 ],       [ 'suAakSCuHz', 6 ],
  [ 'nBQLLS', 6 ],     [ 'cGMsZxxx', 6 ],    [ 'A', 6 ],
  [ 'KlpoodEd', 5 ],   [ 'DmwIEmS', 5 ],     [ 'bmtYQKYv', 5 ],
  [ 'QhF', 4 ],        [ 'kjiSc', 4 ],       [ 'K', 4 ],
  [ 'QIFauTN', 3 ],    [ 'q', 3 ],           [ 'TU', 1 ],
  [ 'qGcQqIVdFr', 1 ]
]

the issue is ‘ubIEXAO’ should be sorted ahead of ‘YMQDBkOWy’. when you do the isolated -a.compareLocale(b) it works correctly, and in other test cases this part of the code correctly sorts other strings. but not in this test case. what am I missing? thank you!

(I know there are myriad other ways to solve this problem, I just want to know why this sort function isn’t working as intended for this object)

How to handle asynchronization between 2 function while passing an array

In my product service, I have this function:

// POST: /products
const create = async ({ name, price, description, images, comments, category }) => {
    try {
        const commentPromises = await Promise.all(comments.map(async (comment) => {
            const added = await CommentRepo.create(comment.text, comment.author, comment.rate);
            return added;
        }));
        const imagePromises = await Promise.all(images.map(async (image) => {
            const added = await ImageRepo.create(image.url, image.caption, image.name);
            return added;
        }));
        console.log(commentPromises) //have data
        const newUser = await ProductRepo.create({ name, price, description, imagePromises, commentPromises, category });
        return newUser;
    } catch (e) {
        console.log(e.toString());
        throw new Error(e.toString());
    }
}

The Idea of this function is I tried to save the comments and images in different collections and then take their return value to save to the product collection.
This is my code of the ProductRepo.create function

const create = async ({ name, price, description, images, comments, category }) => {
    try {
        console.log(comments); //undefine

        // convert images id to string
        const convertedImages = await Promise.all((images ?? []).map(async (img) => {
            img._id = img._id.toString();
            delete img.name;
            return img;
        }));

        const convertedComments = await Promise.all((comments ?? []).map(async (cmt) => {
            cmt._id = cmt._id.toString();
            delete cmt.rate;
            return cmt;
        }));

        // Create new product
        const newProduct = await Products.create({
            name,
            price,
            description,
            convertedImages,
            convertedComments,
            category
        });

        return newProduct._doc;
    } catch (error) {
        throw new Error(error.toString());
    }
};

However, I can not pass comments array and image array to this function (I tried to console.log and it return to undefined).
How can I fix this problem? Thanks in advance

How to toggle existing class with JavaScript

I have a navbar with Bootstrap icon inside the anchor tags

Here’s my code:

<li class="nav-item">
    <a href="#" class="nav-link">
        <i class="bi bi-house"></i>
    </a>
</li>
<li class="nav-item">
    <a href="#" class="nav-link">
        <i class="bi bi-heart"></i>
    </a>
</li>
<li class="nav-item">
    <a href="#" class="nav-link">
        <i class="bi bi-envelope"></i>
    </a>
</li>

I want to add -fill if it clicked, and remove it when clicking on another navigation. I’ve tried classList.toggle, but is seems just adding new class without appending it.

<li class="nav-item">
    <a href="#" class="nav-link">
        <i class="bi bi-house-fill"></i>
    </a>
</li>
<li class="nav-item">
    <a href="#" class="nav-link">
        <i class="bi bi-heart"></i>
    </a>
</li>
<li class="nav-item">
    <a href="#" class="nav-link">
        <i class="bi bi-envelope"></i>
    </a>
</li>

Finding Where A Variable Created From A JSON File Originally Got Its Value

So I’ve got a JSON File a bit like this:

{
  "Collection Name": {
    "Tier Numbers": [
      { *Object 1 Decsription* },
      { *Object 2 Decsription* },
      ...
    ],
    "Tier Alpha": [
      { *Object A Decsription* },
      { *Object B Decsription* },
      ...
    ],
    ...
  },
  "A Different Collection Name": {
    "Tier Alpha": [
      { *Object A Decsription* },
      { *Object B Decsription* },
      ...
    ],
    "Tier Numbers": [
      { *Object 1 Decsription* },
      { *Object 2 Decsription* },
      ...
    ],
    ...
  }
}

and I have a data value passed through a function like this:

const json = require(*json_file_location*);
*functionName*(json['Collection Name']['Tier Alpha'][0]);

function *functionName*(input) {
  var inputCollection = ???; // name of collection
  var inputTier = ???; // name of the tier
}

How (if possible) can I retrieve the collection and tier information from the input variable?

For the tier at the very least I want to be able to be able to retrieve the name, so passing the position does not help as the same name can be in different positions for different collections.

I want to avoid simply passing the location info along with the object because I want to work this into a for loop and having set rules for each collection seems tedious (~80 collections).

I have considered simply making the first object of each collection/tier as an identifier, but if there is a better way without adding ~500 lines to the JSON file that would be greatly appreciated.

Thank you for reading this and thank you for any help you might give!

Animation Play State Fails to Pause CSS Animation when Users Switch between Tabs

In the website I am building, I would like to have some of my animations paused everytime users move to another tab and have them running again when users come back. The following code is a simple replication of what I want to achieve. What is want is for the red box to stop moving when users move to another tab and pick up where it stops when users return.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        @keyframes moving {
            from {
                transform: translateX(0);
            }
            to{
                transform: translate(1000px);
            }
        }
        .box{
            width: 50px;
            height: 50px;
            background-color: red;
            animation: moving 5000ms forwards;
        }
        
    </style>
</head>
<body>
    <div class="box"></div>
    <script>
        const box = document.querySelector(".box");
        window.addEventListener("blur",()=>{
            box.style.animationPlayState = "paused"
        })
        window.addEventListener("focus",()=>{
            box.style.animationPlayState = "running"
        }) 
    </script>
</body>
</html>

I have tried switching the animationPlayState to “paused” on the “blur” event and switch it back to “running” on the “focus” event. So far, I have been getting inconsistent results. While the animation sometimes behaved the way I want, there have also been times when it just cut to the end when users return to my tab. I have also tried the solutions suggested in this question but they didn’t work: https://stackoverflow.com/questions/52892889/pause-resume-css-animations-when-switching-tabs#:~:text=You%20need%20to%20set%20the,to%20blur%20and%20focus%20event.

I am trying to use puppeteer to type hello world in a discord web browser chatbox

The problem is with selecting the div it always times out when i try to select the div. Has anyone else It seems like it has several nested divs is there are way of finding out the exact div im looking for?


async function run() {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();

    try {
        // Navigate to the page with the target div
        await page.goto('https://discord.com/channels/1208249628953153547/1208245629469048914');

        // Wait for the div to be present
        const divSelector = 'class="placeholder_e68c63 slateTextArea__0661c fontSize16Padding__48818"';
        await page.waitForSelector(divSelector, { timeout: 5000 });

        // Click on the textbox within the span inside the div
        const inputSelector = `${divSelector} [data-slate-node="text"] input[type="text"]`; // Replace with the correct input type
        await page.click(inputSelector);

        // Type a message into the input field
        await page.type(inputSelector, 'Hello, this is my message!');

        // Press Enter to send the message (optional)
        await page.keyboard.press('Enter');

        // Wait for a while to see the result (you can adjust the duration)
        await page.waitForTimeout(2000);
    } catch (error) {
        console.error('Error:', error.message);
    } finally {
        await browser.close();
    }
}

run();

.includes doens’t work for some reason in my javascript code for a chess.com chrome extension

(() => {
    let move;
   
    function lastMove() {
        move = document.getElementsByClassName('white node');
        let previousMove = Array.from(move);
        console.log(previousMove.pop().textContent);
        return previousMove.pop().textContent;
    }
    
    chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
        let taken = lastMove();
        // lastMove(); returns the string b3
        if(taken.includes("b")) {
            console.log('it worked');
        }
        
    });

})();

I’m building a chrome extension for chess.com. The function lastMove(); returns “b3”. I thought that by using .includes(“b”), I could get the if statment to run but it is not. For some reason, the .includes function won’t work and I’m not sure why? Any help is appreciated.

Resizing and Rotating multiple selected elements / objects

I’m working on a project where I need to implement resizing and rotating functionality for multiple elements. Each element can be selected individually, and when multiple elements are selected, resizing should be done collectively, exactly like how Figma’s resize and rotate does it.

I have found this solution works well for resizing rotated single element: Resizing rotated elements while maintaining aspect ratio

enter image description here

Now I need to find out how to resize and rotate multiple selected elements. But I’m not sure where to start, can someone point me in the right direction? Even only the math theories/concepts that might help, would be appreciated. Thanks!

enter image description here

(P.S.) Using a library is out of my options so I need to do this manually

Why is the first “if” activated by itself when the second “else if” condition is met?

Basically, when the condition “event.target === checkbox && active” is met, the value of ‘active‘ becomes “false“. Therefore, the next click on the checkbox will satisfy the first condition “event.target === checkbox && !active“, and that’s what I want. However, what happens is that once the condition “event.target === checkbox && active” is met, and the code block is executed, the code block of the first “if” statement is also automatically executed. As a result, ‘active‘ acquires the value “false” and then immediately regains the value of “true” again. This essentially prevents unchecking the checkbox if you click on it, which is something I don’t want. Do you know how to prevent this from happening, and why does it happen in the first place?

There is the code:

function toggleSelectionMenu(checkbox, menu) {
  let active = false;
  document.addEventListener('click', function (event) {
    if (event.target === checkbox && !active) {
      checkbox.checked = true;
      menu.style.display = 'block';
      active = true;
      console.log(active);

    } else if (event.target !== checkbox && active || event.target === checkbox && active) {
      checkbox.checked = false;
      menu.style.display = 'none';
      active = false;
      console.log(active);
    }
  });
}

What I want is that the first click on the checkbox does what is described in the first “if” statement, and that the next click within the DOM executes what is stated in the following code block, regardless of whether the click is on the same checkbox or any other part of the DOM.

Why are my Supabase queries returning an inconsistent number of rows?

When I select by columns, it correctly returns the columns in all four rows of my table. If I select all columns and all rows, it only returns two of the four rows.

The number of rows returned depends on my query. For example, calling

let { data: shows, error } = await supabase.from('shows').select('');
console.log(shows);

returns

[
  {
    id: 1,
    created_at: '2024-02-14T16:20:20.259617+00:00',
    city: 'Denver',
    state: 'CO',
    date: '2024-03-14',
    time: '22:19:15-06',
    address: 'Theater',
    img_url: 'https://images.unsplash.com/photo-1598805291212-f1e476b437df?q=80&w=1000&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTZ8fHNob3d8ZW58MHx8MHx8fDA%3D',
    purchase_link: 'https://www.google.com/'
  },
  {
    id: 2,
    created_at: '2024-02-18T23:18:41.024218+00:00',
    city: 'Iowa City',
    state: 'IA',
    date: '2024-03-26',
    time: '22:00:00-06',
    address: 'Gabes',
    img_url: 'null',
    purchase_link: 'null'
  }
]

Calling let { data: shows, error } = await supabase.from('shows').select('');
Returns { state: 'CO' }, { state: 'IA' }, { state: 'CA' }, { state: 'CA' } .

Shouldn’t querying all rows and all columns return all items? If I query by city, it only returns one city. I don’t understand the inconsistency at all and would love some explanation.