Finding files responsible for heap out of memory

I got this error:

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory

I understand this is because I have some recursive types in typescript, but I don’t know the file they’re in. When I opened the files, they showed in VS code as errors and were marked. After I closed the file, there is no more error and I can’t find the file.

Running tsc watch doesn’t help, since this throws the memory error. Is there a way to run a full “scan project for problems” in VS code? I tried adding
"typescript.tsserver.experimental.enableProjectDiagnostics": true, to settings but no luck.

HTMX: Sending POST Requestbody

I have an HTML in which I want to call an endpoint via HTMX and pass a request body along with it. I don’t want to use explit FORM, but define a button in HTML as follows:

                    <button id="executeButton" class="..."
                            hx-post="/doSomething"
                            hx-vals='js:{
                                "type": "type",
                                "param1": "param1"
                                }'
                            hx-target="#result"
                            hx-swap="innerHTML">
                        
                        <span class="g-btn-text">Execute</span>
                    </button>

By default, HTMX does not seem to forward the request as ‘application/json’. I found the only variant that works like this in the following description
https://www.submitjson.com/blog/htmx-post-json

This means that if I define the button in the following way (enhancing it with hx-ext) and specify the corresponding script, the request body is forwarded correctly as JSON:

                    <button id="executeButton" class="..."
                            hx-post="/doSomething"
                            **hx-ext="postrequestbody"**  
                            hx-vals='js:{
                                "type": "type",
                                "param1": "param1"
                                }'
                            hx-target="#result"
                            hx-swap="innerHTML">
                        
                        <span class="g-btn-text">Execute</span>
                    </button>

... 
<script>
    htmx.defineExtension('postrequestbody', {
        onEvent: function (name, evt) {
        if (name === "htmx:configRequest") {
            evt.detail.headers['Content-Type'] = "application/json"
            evt.detail.headers['X-API-Key'] = 'sjk_xxx'
        }
        },
        encodeParameters: function(xhr, parameters, elt) {
            xhr.overrideMimeType('text/json') // override default mime type
            return (JSON.stringify(parameters))
        }
    });
</script>

But:
My problem now is that I want to execute the code not from HTML but dynamically in a Javascript file. HTMX offers htmx.ajax for this purpose, so I tried something like this:

       try {
            htmx.ajax('POST', url, {
                target: target,
                swap: 'innerHTML'
            });
        } catch (htmxError) {
            // Handle errors from HTMX
        
            console.error('HTMX error:', htmxError);
        }

But apparently not all atrributes (e.g. hx-ext) are supported.

Does anyone know what to do? I.e. how can I send the HTMX call via Javascript so that I can include the request body in the POST?

Cheers MR

Sentry config being overwritten

I have a react native application where I’m using @sentry/react-native(>3) package

I’m correctly initialising the sentry

Sentry.init({
  dsn: DSN,
  enabled: false
....
})

After introducing another package in the application let’s say react-native-xyz I started to see this error when starting the application

“DSN is required. Use empty string or set enabled to false in SentryOptions to disable SDK.”

After debugging I found out this file in sentry-java is throwing the error:
https://github.com/getsentry/sentry-java/blob/6259a9fdb9ec4b75001c93401e1d0b1c18541dfb/sentry/src/main/java/io/sentry/Sentry.java#L369

If you check the code present in this file there’s an if condition present if sentry is not enabled return. which in our case should’ve have been run, but it is going into the else block

Upon removing the third party package this error is resolved and the app is running successfully

I checked with the package managers and they are using the Sentry in the package for event and crash logging

I think they have enabled their sentry in debug mode for every env, Is it possible that their sentry config is clashing with my config and the conditions are failing?

If yes then what would the possible fix for this

PrimeNG component’s appearance differs when running in local environment

I was testing to check the look and feel of PrimeNG components (v17.18.11).

Followed the installation steps and then ran the app locally to check the UI components.

Taking an example of table component, below is the screenshot from the PrimeNG docs: enter image description here

And here’s the screenshot of my local app implementing the table: enter image description here

I can see that there’s a slight look difference in between both (probably the fonts). And this is with all other components also.

I have already added the core and theme styles in angular.json file:

"styles": [
              "node_modules/primeng/resources/themes/lara-light-blue/theme.css",
              "node_modules/primeng/resources/primeng.min.css",
              "src/styles.scss"
            ]

Can anyone kindly explain why is this happening? Do I need to set something else here?

Thanks.

How to make electron use chromium installed in my operating system

My chromium in my linux operating system has a set of patches that makes my javascript web application behave better on it. I use electron to build and pack my application. However, electron by default packs a minimal chromium within it (which does not have the set of chromium patches I need). Is there a way of making electron not bundle a chromium with it, and use the chromium which is already installed in my linux operating system under /usr/lib/chromium?

Best regards,

Samuel

slick.js carousel disappears my container, how to fix it?

I want to have a carousel of my reviews using slick.js (not need the style of slick so I don’t include it on html header.
When I try it the reviews-container disappears.
How to fix it? What I’m doing wrong?

I want the result be like the image
enter image description here

My HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>slick test</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <!-- Customer Reviews Section -->
        <section class="reviews" aria-labelledby="reviews-heading">
            <div class="reviews-header" >
                <h2 id="reviews-heading">Our Happy Customers</h2>
                <div class="arrows-container">
                    <button><img src="./assets/images/arrow-left.svg" alt="left arrow" class="slick-prev" /></button>
                    <button><img src="./assets/images/arrow-right.svg" alt="right arrow" class="slick-next"/></button>
                </div>
            </div>
            <div class="reviews-container">
                <div>
                    <article class="reviews-item">
                        <div class="rating">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                        </div>
                        <h3>Moora S. <span class="verified"><img src="./assets/images/verified.svg"></span></h3>
                        <p>"Shopping at Shop.co has been a game-changer for me. The fit and quality of the clothes are unmatched, and their customer service is always helpful!"</p>
                    </article>
                </div>
                <div>
                    <article class="reviews-item">
                        <div class="rating">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                        </div>
                        <h3>Sarah M. <span class="verified"><img src="./assets/images/verified.svg"></span></h3>
                        <p>"I'm blown away by the quality and style of the clothes I received from Shop.co. From casual wear to elegant dresses, every piece I've bought has exceeded my expectations."</p>
                    </article>
                </div>
                <div>
                    <article class="reviews-item">
                        <div class="rating">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                        </div>
                        <h3>Alex K. <span class="verified"><img src="./assets/images/verified.svg"></span></h3>
                        <p>"Finding clothes that align with my personal style used to be a challenge until I discovered Shop.co. The range of options they offer is truly remarkable, catering to a variety of tastes and occasions."</p>
                    </article>
                </div>
                <div>
                    <article class="reviews-item">
                        <div class="rating">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg"></div>
                        <h3>James L. <span class="verified"><img src="./assets/images/verified.svg"></span></h3>
                        <p>"As someone who's always on the lookout for unique fashion pieces, I'm thrilled to have stumbled upon Shop.co. The selection of clothes is not only diverse but also on-point with the latest trends."</p>
                    </article>
                </div>
                <div>
                    <article class="reviews-item">
                        <div class="rating">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg">
                            <img src="./assets/images/Star.svg"></div>
                        <h3>Moora S. <span class="verified"><img src="./assets/images/verified.svg"></span></h3>
                        <p>"Shopping at Shop.co has been a game-changer for me. The fit and quality of the clothes are unmatched, and their customer service is always helpful!"</p>
                    </article>
                </div>
            </div>
        </section>
<footer class="footer">
  <div class="newsletter">
    <h2>Stay up to date about our latest offers</h2>
    <form action="#" aria-label="Subscribe to Newsletter">
      <label for="email" class="sr-only">Enter your email address</label>
      <input type="email" id="email" placeholder="Enter your email address" required>
      <button type="submit">Subscribe to Newsletter</button>
    </form>
  </div>

  <div class="footer-content">
    <div class="brand">
      <h3>SHOP.CO</h3>
      <p>We have clothes that suit your style and which you're proud to wear. From women to men.</p>
      <div class="social">
        <a href="#" aria-label="Twitter"><i class="fab fa-twitter"></i></a>
        <a href="#" aria-label="Facebook"><i class="fab fa-facebook-f"></i></a>
        <a href="#" aria-label="Instagram"><i class="fab fa-instagram"></i></a>
        <a href="#" aria-label="GitHub"><i class="fab fa-github"></i></a>
      </div>
    </div>

    <div class="links">
      <div>
        <h4>Company</h4>
        <ul>
          <li><a href="#">About</a></li>
          <li><a href="#">Features</a></li>
          <li><a href="#">Works</a></li>
          <li><a href="#">Career</a></li>
        </ul>
      </div>

      <div>
        <h4>Help</h4>
        <ul>
          <li><a href="#">Customer Support</a></li>
          <li><a href="#">Delivery Details</a></li>
          <li><a href="#">Terms & Conditions</a></li>
          <li><a href="#">Privacy Policy</a></li>
        </ul>
      </div>

      <div>
        <h4>FAQ</h4>
        <ul>
          <li><a href="#">Account</a></li>
          <li><a href="#">Manage Deliveries</a></li>
          <li><a href="#">Orders</a></li>
          <li><a href="#">Payments</a></li>
        </ul>
      </div>

      <div>
        <h4>Resources</h4>
        <ul>
          <li><a href="#">Free eBooks</a></li>
          <li><a href="#">Development Tutorial</a></li>
          <li><a href="#">How to - Blog</a></li>
          <li><a href="#">YouTube Playlist</a></li>
        </ul>
      </div>
    </div>
  </div>

  <div class="footer-bottom">
    <p>&copy; Shop.co 2000-2023, All Rights Reserved</p>
    <div class="payment-options">
      <img src="visa-logo.png" alt="Visa">
      <img src="paypal-logo.png" alt="PayPal">
      <img src="apple-pay-logo.png" alt="Apple Pay">
      <img src="google-pay-logo.png" alt="Google Pay">
    </div>
  </div>
</footer>

<!-- Include jQuery (required for Slick.js) -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

    <!-- Include Slick JS -->
    <script type="text/javascript" src="https://cdn.jsdelivr.net/gh/kenwheeler/[email protected]/slick/slick.min.js"></script>
    <!-- Link to my External JavaScript -->
    
    <script src=".//reviews-slider.js"></script>
</body>
</html>

My CSS code

body {
    font-family: Arial, sans-serif;
    background-color: #f9f9f9;
    margin: 0;
    padding: 20px;
}
/* Customer Reviews Section */

.reviews {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.reviews-header{
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    width: 100%;
    padding: 0 6.25rem;
}

.reviews-container{
    display: flex;
    gap:20px;
}

.reviews-item{
    display: flex;
    flex-direction: column;
    /* Fixed width of 400px pixels */ ;
    width: 450px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 20px;
    padding: 28px 32px;
}

.reviews-item p {
    font-size: 1rem;
    line-height: 22px;
    color: rgba(0, 0, 0, 0.6);
}

.reviews-item h3 {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 22px;
}


.nav-btn {
    background-color: #000; /* Button color */
    color: #fff;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    margin: 0 5px;
    font-size: 16px;
}

.nav-btn:hover {
    background-color: #444; /* Darker color on hover */
}



/* General Reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: Arial, sans-serif;
  color: #333;
}

.footer {
  background-color: #f5f5f5;
  padding: 20px 0;
}

.newsletter {
  background-color: #000;
  color: #fff;
  padding: 30px 15px;
  text-align: center;
}

.newsletter h2 {
  font-size: 24px;
  margin-bottom: 15px;
}

.newsletter form {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.newsletter input[type="email"] {
  padding: 10px;
  width: 300px;
  border: none;
  border-radius: 5px;
  font-size: 16px;
}

.newsletter button {
  padding: 10px 20px;
  background-color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

.footer-content {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  padding: 30px 15px;
}

.footer-content .brand {
  flex: 1 1 250px;
  text-align: left;
}

.footer-content .brand h3 {
  font-size: 20px;
  margin-bottom: 10px;
}

.footer-content .brand p {
  font-size: 14px;
  margin-bottom: 15px;
}

.social {
  display: flex;
  gap: 10px;
}

.social a {
  font-size: 18px;
}

.links {
  display: flex;
  flex: 2 1 600px;
  justify-content: space-around;
}

.links div {
  text-align: left;
}

.links h4 {
  margin-bottom: 10px;
}

.links ul {
  list-style: none;
}

.links ul li {
  margin-bottom: 8px;
}

.links ul li a {
  color: #333;
  text-decoration: none;
}

.links ul li a:hover {
  text-decoration: underline;
}

.footer-bottom {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 20px 0;
  border-top: 1px solid #ddd;
  align-items: center;
  text-align: center;
}

.footer-bottom p {
  flex: 1;
}

.payment-options {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.payment-options img {
  width: 50px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .footer-content {
    flex-direction: column;
    align-items: center;
  }

  .links {
    flex-direction: column;
    align-items: center;
  }

  .newsletter form {
    flex-direction: column;
  }

  .newsletter input[type="email"] {
    width: 100%;
  }

  .footer-bottom {
    flex-direction: column;
  }

  .payment-options {
    margin-top: 10px;
  }
  .reviews-container {
        flex-direction: column; /* Stack reviews vertically on small screens */
    }

    .review {
        margin: 10px 0; /* Reduce margin for stacked layout */
    }
}

/* Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

my Javascript code

// reviews carousel
$(document).ready(function () {
  $(".reviews-container").slick({
    slidesToShow: 3, // Number of items visible at once
    slidesToScroll: 1, // Number of items scrolled per click
    arrows: true, // Enable navigation arrows
    prevArrow: $(".slick-prev"), // Use your custom prev arrow
    nextArrow: $(".slick-next"), // Use your custom next arrow
    responsive: [
      {
        breakpoint: 768, // Responsive breakpoint
        settings: {
          slidesToShow: 2, // Adjust slidesToShow on smaller screens
        },
      },
    ],
  });
});

Slider with horizontal layout and a vertical flip animation

Im new to react and next js and i am currently studiing so i started a project where I want to make a slider where I have 4 boxes in each box I need to show the logo. On every second I want all logos to flip in chronological order and move to the right. For example the Logo 1 flips vertically first moves to the right Logo 2 does the same this .. I want it to be smooth the flips and the movement I’ve tried using react slick caroseul but wasn’t able to create this.
I want animation like this https://codepen.io/xthecapx/pen/KzLEba
but to work automatically and not on hover. I want on every second the logo to flip and move to the right

const brands = [
    { id: 1, name: "nike", logo: "/path-to-logo1.png" },
    { id: 2, name: "johnson", logo: "/path-to-logo2.png" },
    { id: 3, name: "levis", logo: "/path-to-logo3.png" },
    { id: 4, name: "box", logo: "/path-to-logo4.png" },
    { id: 5, name: "nike", logo: "/path-to-logo1.png" },
    { id: 6, name: "johnson", logo: "/path-to-logo2.png" },
    { id: 7, name: "levis", logo: "/path-to-logo3.png" },
    { id: 8, name: "box", logo: "/path-to-logo4.png" },
];

export default function SwiperSlider({ locale }) {
    const [brandIndexes, setBrandIndexes] = useState([0, 1, 2, 3]);

    useEffect(() => {
        const interval = setInterval(() => {
            setBrandIndexes((prevIndexes) => {
                return prevIndexes.map((index) => (index + 1) % brands.length);
            });
        }, 1000); 

        return () => clearInterval(interval);
    }, []);

    const settings = {
        dots: true,
        autoplay: true,
        autoplaySpeed: 3000,
        infinite: true,
        speed: 500,
        slidesToShow: 4,
        slidesToScroll: 1,
        afterChange: (current) => handleFlipAnimation(current),
    };

    const handleFlipAnimation = (current) => {
        const slides = document.querySelectorAll('.slick-slide');
        slides.forEach((slide, index) => {
            const card = slide.querySelector('.flip-card');
            if (card) {
                card.style.transitionDelay = `${(index - current) * 0.2}s`;
                card.style.transform = 'rotateY(180deg)';
                setTimeout(() => {
                    card.style.transform = 'rotateY(0deg)';
                }, 500);
            }
        });
    };

    return (
        <div>
            <h1 className="text-center">slider</h1>
            <Slider {...settings} ref={sliderRef}>
                {brands.map((brand) => (
                    <div key={brand.id} className="mx-4">
                        <div className="slider-flip">
                            <div className="flip-card">
                                <div className="flip-card-inner">
                                    <div className="flip-card-front">
                                        <img
                                            className="w-56 h-40"
                                            src={image}
                                            alt={brand.name}
                                        />
                                    </div>
                                    <div className="flip-card-back">
                                        {/* You can add content for the back of the card here */}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                ))}
            </Slider>
        </div>
    );
}

Chrome Extension: Run custom JS with access to window before any other JS in webpage

I’m writing Chrome extension (manifest v3), the main aim is to override some of the Window native functions and replace them before any other webpages scripts can access them.

I have contentscript.js that has run_at = document_start. The contentscript.js successfully injects my script.js into the webpage DOM either into <html> or <head> tag (by mutation observer).But (!) i cannot force and guarantee my script.js will run first before any other website scripts.

When i debug contentscript.js, the DOM of the page does contain only <html> and my newly injected <script> element that loads script.js. The run_at thus works fine. But, when i step with debugger after last line, instead of stepping into script.js, i’m inside websites script (even though my script.js reference is the first in header above all other referenecs). All would be solved easily if contentscript.js could write directly into the webpages window, but it cannot.

I’ve tried to add mutator observer inside contentscript.js where i’m able to detect addition of tags into DOM and i’m able to edit/remove them without (?) letting them execute, but i need the page working.

What i’ve tried:

  1. add debugger; command into any <script> so i can see which script runs first
    — everytime it is the websites script, not mine.
  2. adding async=false, defer=false to all scripts — failed,
  3. disable any <script> by rewriting or smart-disabling them and then re-running them after my script.js registers as read. I’m re-enabling the scripts in order the scripts (a) were observed by observer or (b) by order in DOM from document.querySelectorAll. This approach works for some websites, but some sites throw errors on “not-existing object references” which are then all defined when i check them in console — for me this seems odd as i evaluate the original scripts in order and look like some race condition by authors of the website (?).

Edit: I’ve also tried to add a custom <script> with direct script.text = ... code ... but this is refused due to CSP needing either hash, nonce or unsafe-inline (however, i’ll try to edit the HTTP header to contain unsafe-inline now).

Is there any hope to have my script running first with a guarantee?
Thank you

Loop only works once regardless if the condition to run it is met

i have this loop that will happen each time a condition is met.
The first time the condition is met, it works.
The second time the loop does not run even as I have confirmed that the condition has been met.
The problem is between lines 54 to 70, in the Actualwork function.
just to make it easier, Some of the things I have already checked are

1.
that length of my folders stays the same and is not 0

2.
that the condition inside the loop gets meet

3.
that the condition outside the loop is meet

here is the code:

import {Plugin, TAbstractFile } from 'obsidian'
export default class Name extends Plugin {
    AllFiles: TFolder[]
    AllFolders: TFolder[]
    Ribbon: HTMLElement;
    onload() {
        this.AllFolders = this.app.vault.getAllFolders();
        this.AllFiles = this.app.vault.getFiles();
        this.Ribbon = this.addRibbonIcon('dice', 'Autolink', (evt: MouseEvent) => {
            console.log("You have pressed the button") //works
            this.Autolink()

        });
        
        this.app.workspace.on('editor-change', (editor) => { //Works
            this.AllFolders = this.app.vault.getAllFolders();
            this.AllFiles = this.app.vault.getFiles();
            console.log("The editor has been changed")
        });
    }

    private async Autolink() {
        const file = this.app.workspace.getActiveFile()
        if (file) {
            const content = await this.app.vault.read(file)
            this.Splitlines(content);
            console.log("found the activefile")
        }
    }

    private Splitlines(Filecontent?: string) {
        const count = Filecontent ? Filecontent.split(/rn|r|n/) : null;
        if (count) {
            this.TheActualWork(count)
            console.log("Splitting the file content")
        }
    }
    private TheActualWork(stringarray: string[]) { //warning
        
        const Check="#"
        let temp: string 
        let folder = ""
        let folderpath =""
        for (let i = 0; i < stringarray.length; i++) {

            temp = stringarray[i]; //string content for 1 line
            console.log("the text getting checked is "+temp)
            //Check if the first letter of the string matches the symbol #
            if (temp.startsWith(Check)) {
                folder=""
                const sliced = this.RemoveEmptySpacesAndChecks(temp);
                console.log("the value of sliced is => " + sliced)
                //if the letter matches, check if there is a folder that exists with that name get its path so that a note can be created in the folder
                for (let z = 0; i < this.AllFolders.length; z++) {
                    console.log("the folder getting checked is called " + this.AllFolders[z].name)
                    if (this.AllFolders[z].name == sliced) {
                        folder = sliced
                        folderpath = this.AllFolders[z].path
                        console.log("The path is " + folderpath)
                        break;
                    } 
                    //if no folder with that name is found the folder is set to a empty string
                    else {
                        folder = ""
                        console.log("the folder " + sliced + " does not exist and its lenght is " + sliced.length)
                        
                        
                    }
                    console.log("Loop is getting run")
                    
                }
                
            }
            //if this string does not start with the symbol #,check if there is a folder path
            else if (folder !== "") {
                console.log("the text does not start with #")
                let exist = false;
                //Remove the [[]]  
                temp = this.RemoveEmptySpacesAndChecks(temp);
                //check if there is a note with that name
                for (let z = 0; z < this.AllFiles.length; z++) {
                    if (temp == this.AllFiles[z].name) {
                        exist = true;
                        break;
                    }
                }
                if (exist == false) { 
                    console.log("This is the folderpath =>" + folderpath)
                    //const value = this.Createnote(folderpath + "/" + temp + ".md", temp)
                    //console.log("the file value is " + value)
                    
                    
                }
                //incase it doesnt exist create one and send it to the folder path found
                
            }
        }

    }
    private async Createnote(folderpath: string, Name: string) {
        try {
            const promisevalue = await this.app.vault.create(folderpath, Name);
            return promisevalue
        }
        catch (error) {
            console.error(error)
            return folderpath
        }
        
    }
    private RemoveEmptySpacesAndChecks(StringtobeAltered: string) {
        let temp = ""
        const chararray = StringtobeAltered.split('');
        for (let x = 0; x < chararray.length; x++) {
            if (chararray[x] == "#" || chararray[x]==" " || chararray[x] == "[" || chararray[x] == "]" || chararray[x] == ' ') {
                continue;
            }
            else {
                temp += chararray[x]
            }
        }
        return temp
    }
}
export class TFolder extends TAbstractFile {

}

How can I use JavaScript ECMAScript Modules (ESM) with Server Side Rendering (SSR) without bundling?

I am trying to use the latest ECMAScript Modules (ESM) with Server Side Rendering (SSR) without having to bundle my application. Currently to achieve SSR for my React app it seems like I have to go through a bundler like Webpack or a bundling framework like Vite or Vue, but then that defeats one of the purpose of native ES modules. So is there a way I can use native ESM but still have the benefits of SSR?

sending email and loading animation in contact form google sheet

tryed to acheive

  • send email to both receiver and sender email adress or atleast send email to receiver with all data entered in form(like: name,email,phone,message,file).
    here is image for email with all data submitted in form.

  • also show loading animation during timedelay between after submiting form and showing success message(i am using swal.fire()to show success message).

whats not working

  • i tryed to add feature like if user submit form the email send to emailaddress of receiver as well sender(copy of email) with all entered data in form(like: name,email,phone,message,file). but didnt worked, here is code:
MailApp.sendEmail({ to: [email protected], to: formObject.email,
 subject: "message submited",
 body: "name,email,phone,messsage,file" });
  • also i successfully wrote code for timedelay loading animation between, ‘after submiting form and showing success message’ (i am using swal.fire()to show success message)but unable to add this seperated css and codes in single html in google appscript.

here is what i tryed for timedelay loading animation

$(document).ready(function(){
  $("#myform").on("submit", function(){
    $("#preloder").fadeIn();
  });//submit
});//document ready
/* Preloder */

#preloder {
    display: none;
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 999999;
    /* background: #000; */
    background: #ffffff;
}

.loader {
    width: 50px;
    height: 50px;
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -20px;
    margin-left: -20px;
    border-radius: 60px;
    animation: loader 0.8s linear infinite;
    -webkit-animation: loader 0.8s linear infinite;
}

@keyframes loader {
    0% {
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
        border: 4px solid #056d4d;      
        /* border: 4px solid #f44336; */
        border-left-color: transparent;
    }
    50% {
        -webkit-transform: rotate(180deg);
        transform: rotate(180deg);
        border: 4px solid #056d4d;
        /* border: 4px solid #673ab7; */
        border-left-color: transparent;
    }
    100% {
        -webkit-transform: rotate(360deg);
        transform: rotate(360deg);
        border: 4px solid #056d4d;
        border-left-color: transparent;
    }
}

@-webkit-keyframes loader {
    0% {
        -webkit-transform: rotate(0deg);
        border: 4px solid #056d4d;
        border-left-color: transparent;
    }
    50% {
        -webkit-transform: rotate(180deg);
        border: 4px solid #056d4d;
        border-left-color: transparent;
    }
    100% {
        -webkit-transform: rotate(360deg);
        border: 4px solid #056d4d;
        border-left-color: transparent;
    }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Page Preloder -->
<div id="preloder">
    <div class="loader"></div>
</div>

<form id="myform">
  <input type="text" name="fname" id="fname" value="" />
  <input type="submit" value="Submit" />
</form>

Here is appscript i tryed to add email sending feature and timedelay loading animation feature. {files made in appscript: (code.gs and index.html and library id)}.

code.gs

function doGet() {
  return HtmlService.createTemplateFromFile('index').evaluate()
  .addMetaTag('viewport', 'width=device-width, initial-scale=1')
  .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
}

var url = '#'
var sh = 'file1'
var folderId = '#'

function processForm(formdata) {
  var superscript = SuperScript.initSuper(url, sh);
  var formObject = {};
  formdata.forEach(element => formObject[element.name] = element.value);
  formdata.forEach(element => formObject[element.message] = element.value);
  formdata.forEach(element => formObject[element.email] = element.value);
  formdata.forEach(element => formObject[element.phone] = element.value);

  var f = formdata.find(({ name }) => name == "myfile");
  var file = (f && f.value?.name && f.value?.data) ? superscript.uploadFile(folderId, formObject.myfile.data, formObject.myfilename) : "";
  var ss = SpreadsheetApp.openByUrl(url);
  var ws = ss.getSheets()[0];
  ws.appendRow([
    new Date(),
    formObject.name,
    "'" + formObject.message,
    formObject.email,
    formObject.phone,
    file && file.getUrl()
  ]);

}

index.html

<!DOCTYPE html>
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
        integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
        integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
  
  
</head>
<body>
    <div class="container py-5">
        <div class="row">
            <div class="col-lg-5 col-md-8 mx-auto shadow border bg-white p-4 rounded">
                <nav class="navbar navbar-dark bg-primary">
                    <a class="navbar-brand" href="#" fw-bold mb-3>WRITE YOUR QUERY / MESSAGE</a>
                </nav>
                <br>
                <form id="myForm" onsubmit="handleFormSubmit()">
                    <div id="form_alerts"></div>
                    <div class="form-group mb-3">
                        <label for="name">Name</label>
                        <input type="text" class="form-control" id="name" placeholder="Enter your Name here|" name="name"required>
            </div>

            <div class="form-group mb-3">
            <label for="email" >Email</label>
                        <input type="email"  class="form-control" id="email"
            placeholder="Enter your email address here|" name="email" required>
            </div>

            <div class="form-group mb-3">
           <label for="phone">phone number</label>
  <input type="tel" id="phone" class="form-control" name="phone" placeholder="Enter your phone number here with country code|" pattern="[+]{1}[0-9]{2}[0-9]{10}" required>
  <small>requested example Format: +919263943858</small>
            </div>

            <div class="form-group mb-3">
              <label for="message">Message</label>
    <textarea class="form-control" id="message" placeholder="Write your message here|" name="message" required ></textarea>
              </div>

                         <div class="form-group mb-3">
                            <label for="uploadFile">Upload File</label>
                            <input type="file" class="form-control" File="file" id="file">
              <small>For multiple/bigger file size please attach/share via google drive link in message section.</small>
                            </div>

                            <button type="submit" class= "btn btn-primary btn-block">SEND</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
  <script>
        function preventFormSubmit() {
                var forms = document.querySelectorAll('form');
                for (var i = 0; i < forms.length; i++) {
                    forms[i].addEventListener('submit',
                     function (event) {
                        event.preventDefault();
                    });
                }
            }
            window.addEventListener('load', preventFormSubmit);
            function handleFormSubmit() {
                var formdata = $('#myForm').serializeArray()
                formdata.push({
                  name: 'myfile',
                  value: myfile
                })
                google.script.run.withSuccessHandler(success).processForm(formdata);
            }
            function success(){
                 document.getElementById("myForm").reset()
                 Swal.fire({
                  position: 'center',
                  icon: 'success',
                  title: 'Sended successfully! Be ready we will contact you shortly',
                  showConfirmButton: true,
      
                })
            }
        var myfile ={},file, reader = new FileReader();
      reader.onloadend = function(e) {
          myfile.data = e.target.result
          myfile.name = file.name
          console.log(myfile)
      };
     $('#file').change(function(){
       file = $('#file')[0].files[0]
        reader.readAsDataURL(file);
     })
    </script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
    <script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
  <script src="sweetalert2.all.min.js"></script>
</body>
</html>

“Expanding Window Effect” scroll trigger, expanding div acting as transition into website Gsap? Js? React?

I am trying to make a scroll trigger transition similar to example below. A div acts like a portal/window where the user is able to look through into it and see the content behind it. As the user scrolls down the portal grows eventually covering the entire screen/viewport, and the website functions as usual after that.

https://www.playground.it/en (load in and scroll down you’ll see the effect)

1st “the user initially see’s a small window to the content behind”

2nd “as the user scrolls down the window expands, exposing more of the content below”

3rd “as the user continues to scroll down the window expands and covers the entire screen/viewport”

Methods I tried,

  • Initially i used normal divs, made them circle and used javascript to make it expand, however i realised i cant make a div transparent, and the area with content surrounding it to dissapear after the div grown and

  • I tried to make a div with a circular cut out assuming as it grows the cut out will eventually remove everything that was initially on that cutout div, however this didnt seem to work as i couldnt make a div with a circular center cut out.

  • Eventually i used svgs, along with clip path, this is where i got closest to the effect. i used a invisible svg and made it grow with gsap clip path by increasing the percentage, this had the desired effect however, the reason im here is the effect is not as smooth. When scrolling fast all the content is instantly exposed and the circle cut out dosent move in a sense “block by bloc” similar to the example instead it acts with a gsap duration hence it isnt smooth.

as a summary i have gotten the effect however, it is not smooth and i would like to know if they are any other methods i can try to make it animate block by block similar to the example.

Stop carousel spinning backwards when it reaches the last slide

So I have a carousel with 4 slides that change every few seconds or with a left/right button click, but after the last slide, it skips over the previous slides to get back to the first.

In the CSS instead of using transition: all 0.5s ease; I used animation: 5s infinite linear which fixed it but it meant I lost the original sliding effect/flow to the next slide.

So read up about cloning the first and last slide but wasn’t able to figure that out.

CSS for current implementation;

.banner {
  width: 100%;
  height: 310px;
  position: absolute;
  transition: all 0.5s ease;
  /* animation: 5s infinite linear */ 
} 

This is the current implementation.

 const bannersRef = useRef([]);
  const bannerButtonsRef = useRef([]);
  const bannerLen = banners.length;
  const maxBanner = bannerLen - 1;
  const delaySecs = 6;
  const ref = useRef({
    currentBanner: 0
  });

  useEffect(() => {
    let interval;
    translateBanner(bannersRef, ref);
    if (!isMouseOverBanner) {
      interval = setInterval(() => {
        ref.current.currentBanner = (ref.current.currentBanner + 1) % bannerLen;
        translateBanner(bannersRef, ref);
        updateBottomButtons();
      }, delaySecs * 1000);
    }
    return () => clearInterval(interval);
  }, [bannerLen, isMouseOverBanner]);

  if (bannersRef.current.length !== bannerLen) {
    bannersRef.current = Array(bannerLen)
      .fill()
      .map((_, i) => bannersRef.current[i] || React.createRef());
    bannerButtonsRef.current = Array(bannerLen)
      .fill()
      .map((_, i) => bannerButtonsRef.current[i] || React.createRef());
  }

  const updateBottomButtons = () => {
    bannerButtonsRef.current.forEach((buttonRef, ind) => {
      const banner = banners[ind];

      buttonRef.current.style.cursor =
        ind === ref.current.currentBanner ? "default" : "pointer";
      buttonRef.current.style.backgroundColor =
        ind === ref.current.currentBanner
          ? banner.activeDotColour
          : banner.dotColour;
    });
  };

  const translateBanner = (bannersRef, ref) => {
    bannersRef.current.forEach((bannerRef, ind) => {
      if (bannerRef && bannerRef.current) {
        const trnlt = 100 * (ind - ref.current.currentBanner);
        bannerRef.current.style.transform = `translateX(${trnlt}%)`;
      }
    });
  };

  const bannerSideButtonHandler = dir => {
    if (dir === "back") {
      if (ref.current.currentBanner === maxBanner) {
        ref.current.currentBanner = 0;
      } else {
        ref.current.currentBanner++;
      }
    } else {
      if (ref.current.currentBanner === 0) {
        ref.current.currentBanner = maxBanner;
      } else {
        ref.current.currentBanner--;
      }
    }
    translateBanner(bannersRef, ref);
    updateBottomButtons();
  };

  const CarouselBanner = props => {
    const { index, name, img, link, textColour, bgColour } = props;
    const trnlt = 100 * (index - ref?.current?.currentBanner || 0);
    const linkCls =
      textColour === "white"
        ? `${name}-banner-link-btn ${styles["banner-text"]} ${styles["banner-link"]} ${styles["link-animate-underline-white"]}`
        : `${name}-banner-link-btn ${styles["banner-text"]} ${styles["banner-link"]} ${styles["link-animate-underline-black"]}`;

    return (
      <div
        ref={bannersRef.current[index]}
        className={styles.banner}
        style={{
          transform: `translateX(${trnlt}%)`,
          backgroundColor: bgColour
        }}
      >
        {name === "long" ? (
          <span
            className={`${styles["banner-text-long"]} ${styles["banner-title-long"]}`}
            style={{ color: textColour }}
          >
            {context.getMessage(`hub.banner.${name}.title`)}
          </span>
        ) : (
          <span
            className={`${styles["banner-text"]} ${styles["banner-title"]}`}
            style={{ color: textColour }}
          >
            {context.getMessage(`hub.banner.${name}.title`)}
          </span>
        )}
        <span
          className={`${styles["banner-text"]} ${styles["banner-descr"]}`}
          style={{ color: textColour }}
        >
          {getBannerText(name, context)}
        </span>
        {name === "long" ? (
          <span
            className={`${styles["banner-text"]} ${styles["banner-descr-second"]}`}
            style={{ color: textColour }}
          >
            {context.getMessage(`hub.banner.${name}.text.second`)}
          </span>
        ) : null}
        <span
          className={linkCls}
          style={{ color: textColour }}
          onClick={() => window.open(link, "_blank")}
        >
          {context.getMessage(`hub.banner.${name}.linkText`)}
        </span>
        <img src={`/images/${img}`} alt={name} />
      </div>
    );
  };

Async upload of file using pure JS/AJAX and PHP

I want to asynchronously upload a file using our JavaScript/AJAX–no jQuery–and PHP without having to submit a form, which I thought was possible with JS/AJAX.

My code is:

<?php

$filename = $_FILES['fileToUpload']['name'];
$location = "../uploads/".$filename;

if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $location)) { echo 'Success'; }
else { echo 'Failure'; }

?>
<html>

<head>
    <script type="text/javascript" >

        async function uploadFile() 
        {
            let formData = new FormData(); 
            formData.append("file", fileToUpload.files[0]);
            await fetch('../php/upload.php', 
            {
                method: "POST", 
                body: formData
            }); // await fetch(
            alert('The file has been uploaded successfully.');
        }; // async function uploadFile()

    </script>
</head>

<body>

<form action="" method="post" enctype="multipart/form-data">
    Select file to upload:
    <input type="file" name="fileToUpload">
    <button onclick="uploadFile();">Upload File (async)</button>
</form>

</body>

</html>

If I click on the “Upload File (async)” button, the form submits and the file is uploaded.

However, if I add type="button" to the <button> tag, the form doesn’t submit (as expected), but the file is not uploaded.

I thought that the problem might be that the php and html were in the same file, so I separated the two to no effect–the upload works without the type="button" but doesn’t with it.

I’ve seen postings about using hidden <iframe>s, but haven’t tried implementing one as I don’t think this should be necessary.

Do I misunderstand what JS/AJAX and PHP can do, or is there a problem with my code?

Many thanks!