If I’m not receiving a notification through FCM, how can I debug where it’s failing?

I’m using the Firebase JS SDK to receive FCM notifications in a service worker. It works fine at first, but after I unregister and re-register the service worker, it stops receiving notifications in onBackgroundMessage. I could confirm that on the backend, firebaseAdmin.messaging().send() succeeded, but onBackgroundMessage in the service worker doesn’t get triggered.

How do I debug FCM? E.g. is it possible to check where in the backend -> Firebase servers -> service worker flow it’s failing?

Dice roll function non-functional

So, a code similar to this almost worked at one point. Then I asked AI for help and the code hasn’t worked since. This is where I’m at now:




var lockedDice = [false, false, false, false, false, false]; 

function lockdie1() {

    lockedDice[0] = true;

    img.setAttribute("class", "dicelocked");

    img.setAttribute("height", "50px");

    img.setAttribute("width", "50px");

    }

function lockdie2() {

    lockedDice[1] = true;

    img2.setAttribute("class", "dicelocked");

    img2.setAttribute("height", "50px");

    img2.setAttribute("width", "50px");

}

function lockdie3() {

    lockedDice[2] = true;

    img3.setAttribute("class", "dicelocked");

    img3.setAttribute("height", "50px");

    img3.setAttribute("width", "50px");

}

function lockdie4() {

    lockedDice[3] = true;

    img4.setAttribute("class", "dicelocked");

    img4.setAttribute("height", "50px");

    img4.setAttribute("width", "50px");

}

function lockdie5() {

    lockedDice[4] = true;

    img5.setAttribute("class", "dicelocked");

    img5.setAttribute("height", "50px");

    img5.setAttribute("width", "50px");

}

function lockdie6() {

    lockedDice[5] = true;

    img6.setAttribute("class", "dicelocked");

    img6.setAttribute("height", "50px");

    img6.setAttribute("width", "50px");

}

function rollDice() {

  var result1 = " ";

  var result2 = " ";

  var result3 = " ";

  var result4 = " ";

  var result5 = " ";

  var result6 = " ";

  if (!lockedDice[0]) {

     result1 === Math.floor(Math.random() * 6) + 1 ;

  }

  if (!lockedDice[1]) {

     result2 === Math.floor(Math.random() * 6) + 1 ;

  }

  if (!lockedDice[2]) {

     result3 === Math.floor(Math.random() * 6) + 1 ;

  }

  if (!lockedDice[3]) {

     result4 === Math.floor(Math.random() * 6) + 1 ;

  }

  if (!lockedDice[4]) {

     result5 === Math.floor(Math.random() * 6) + 1 ;

  }

  if (!lockedDice[5]) {

     result6 === Math.floor(Math.random() * 6) + 1 ;

  }

if (result1.value === 1) { 

  document.getElementById("img").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num1.png";  

}

else if (result1.value === 2) {

  document.getElementById("img").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num2.png";  

}

else if (result1.value === 3) {

  document.getElementById("img").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num3.png";  

}

else if (result1.value === 4) {

  document.getElementById("img").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num4.png";  

}

else if (result1.value === 5) {

  document.getElementById("img").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num5.png";  

}

else if (result1.value === 6) {

  document.getElementById("img").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num6.png";  

}

if (result2.value === 1) { 

  document.getElementById("img2").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num1.png";  

}

else if (result2.value === 2) {

  document.getElementById("img2").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num2.png";  

}

else if (result2.value === 3) {

  document.getElementById("img2").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num3.png";  

}

else if (result2.value === 4) {

  document.getElementById("img2").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num4.png";  

}

else if (result2.value === 5) {

  document.getElementById("img2").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num5.png";  

}

else if (result2.value === 6) {

  document.getElementById("img2").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num6.png";  

}

if (result3.value === 1) { 

  document.getElementById("img3").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num1.png";  

}

else if (result3.value === 2) {

  document.getElementById("img3").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num2.png";  

}

else if (result3.value === 3) {

  document.getElementById("img3").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num3.png";  

}

else if (result3.value === 4) {

  document.getElementById("img3").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num4.png";  

}

else if (result3.value === 5) {

  document.getElementById("img3").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num5.png";  

}

else if (result3.value === 6) {

  document.getElementById("img3").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num6.png";  

}

if (result4.value === 1) { 

  document.getElementById("img4").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num1.png";  

}

else if (result4.value === 2) {

  document.getElementById("img4").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num2.png";  

}

else if (result4.value === 3) {

  document.getElementById("img4").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num3.png";  

}

else if (result4.value === 4) {

  document.getElementById("img4").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num4.png";  

}

else if (result4.value === 5) {

  document.getElementById("img4").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num5.png";  

}

else if (result4.value === 6) {

  document.getElementById("img4").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num6.png";  

}

if (result5.value === 1) { 

  document.getElementById("img5").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num1.png";  

}

else if (result5.value === 2) {

  document.getElementById("img5").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num2.png";  

}

else if (result5.value === 3) {

  document.getElementById("img5").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num3.png";  

}

else if (result5.value === 4) {

  document.getElementById("img5").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num4.png";  

}

else if (result5.value === 5) {

  document.getElementById("img5").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num5.png";  

}

else if (result5.value === 6) {

  document.getElementById("img5").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num6.png";  

}

if (result6.value === 1) { 

  document.getElementById("img6").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num1.png";  

}

else if (result6.value === 2) {

  document.getElementById("img6").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num2.png";  

}

else if (result6.value === 3) {

  document.getElementById("img6").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num3.png";  

}

else if (result6.value === 4) {

  document.getElementById("img6").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num4.png";  

}

else if (result6.value === 5) {

  document.getElementById("img6").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num5.png";  

}

else if (result6.value === 6) {

  document.getElementById("img6").src = "file:///storage/emulated/0/Android/data/com.teejay.trebedit/files/TrebEdit user files/shipsandgaggles/img/d6num6.png";  

}

 

}


Can anyone please point me in the right direction? Because I’m still really new at this and now I’m lost.

I can’t remember what all I’ve tried. I’ve tried writing more things into arrays.

how do i click the second list item(li) inside the second unordered list(ul)?

this is the footer element of web that i want to test

<footer id="main-footer" class="section-footer mt-5 border-top">
   <div class="container py-5">
      <div class="row">
         <div class="col-12 col-md-6 col-lg-4">
            <h4>Solutions</h4>
            <ul class="footer-menu footer-menu-product list-unstyled">
               <li><a href="/solution/managed-services">Managed Services</a></li>
               <li><a href="/solution/adoption-migration">Adoption/Migration*</a></li>
               <li><a href="/solution/cloud-optimization">Cloud Optimization</a></li>
               <li><a href="/solution/cloud-strategy">Cloud Strategy</a></li>
               <li><a href="/solution/consulting">Consulting</a></li>
               <li><a href="/solution/backup">Backup</a></li>
               <li><a href="/solution/load-balancing">Load Balancing</a></li>
               <li><a href="/solution/disaster-recovery">Disaster Recovery</a></li>
               <li><a href="/solution/content-delivery-network-cdn">Content Delivery Network (CDN)</a></li>
               <li><a href="/solution/web-application-firewall-waf">Web Application Firewall (WAF)</a></li>
               <li><a href="/solution/data-replication">Data Replication*</a></li>
               <li><a href="/solution/document-management">Document Management</a></li>
               <li><a href="/solution/anti-virus">Anti Virus</a></li>
            </ul>
         </div>
         <div class="col-12 col-md-6 col-lg-4">
            <h4>Platforms</h4>
            <ul class="footer-menu footer-menu-product list-unstyled">
               <li><a href="/platform/amazon-web-service">Amazon Web Service</a></li>
               <li><a href="/platform/azure">Microsoft Azure</a></li>
               <li><a href="/platform/cloud">Cloud</a></li>
               <li><a href="/platform/odoo">Odoo</a></li>
               <li><a href="/platform/ave-point">AvePoint</a></li>
               <li><a href="/platform/microsoft-365">Microsoft 365</a></li>
               <li><a href="/platform/google-workspace">Google Workspace</a></li>
               <li><a href="/platform/acronis">Acronis</a></li>
               <li><a href="/platform/exchange">Microsoft Exchange</a></li>
               <li><a href="/platform/c-panel">cPanel</a></li>
               <li><a href="/platform/plesk">Plesk</a></li>
               <li><a href="/platform/share-point">Microsoft SharePoint</a></li>
               <li><a href="/platform/teams">Microsoft Teams</a></li>
               <li><a href="/platform/kemp-load-balancing-waf">KEMP</a></li>
            </ul>
         </div>
         <div class="col-12 col-md-12 col-lg-4">
            <div class="row">
               <div class="col-12 col-md-6 col-lg-12">
                  <h4>Resources &amp; Insight</h4>
                  <ul class="footer-menu list-unstyled">
                     <li><a href="/articles">Articles</a></li>
                     <li><a href="/videos">Videos</a></li>
                     <li><a href="/promos">Promos</a></li>
                  </ul>
               </div>
               <div class="col-12 col-md-6 col-lg-12">
                  <h4>Company</h4>
                  <ul class="footer-menu list-unstyled">
                     <li><a href="/about">About</a></li>
                     <li><a href="/sla">SLA</a></li>
                     <li><a href="/acceptable-usage-policy">Acceptable Usage Policy</a></li>
                  </ul>
               </div>
            </div>
         </div>
      </div>
      <div class="mt-4 w-100 d-flex flex-column flex-md-row flex-wrap flex-md-nowrap">
         <div class="footer-logo"><img src="/asset/logo/footer_logo.png" alt="Logo"></div>
         <div class="mt-3 mt-md-0 footer-company flex-shrink-1">
            <h1 class="mb-0">
               2009 - <!-- -->2023<!-- --> System Indonesia
            </h1>
            <p class="mb-0"> System Indonesia is a registered trademark</p>
         </div>
         <div class="mt-4 mt-md-0 ms-0 ms-md-auto text-start text-md-end">
            <ul class="footer-social list-unstyled mb-1">
               <li><a href="http://instagram.com/" target="_blank" rel="noreferrer"><i class="fa-brands fa-instagram"></i></a></li>
               <li><a href="http://facebook.com" target="_blank" rel="noreferrer"><i class="fa-brands fa-facebook"></i></a></li>
               <li><a href="http://twitter.com" target="_blank" rel="noreferrer"><i class="fa-brands fa-twitter"></i></a></li>
               <li><a href="https://open.spotify.com" target="_blank" rel="noreferrer"><i class="fa-brands fa-spotify"></i></a></li>
               <li><a href="https://www.youtube.com" target="_blank" rel="noreferrer"><i class="fa-brands fa-youtube"></i></a></li>
            </ul>
            <ul class="footer-link list-unstyled mb-0">
               <li><a href="/terms-of-service">Terms of Service</a></li>
               <li><a href="/privacy-policy">Privacy Policy</a></li>
            </ul>
         </div>
      </div>
   </div>
</footer>

the goals is just to click the first 3 li for each ul that appear one by one then expect the direct link,

but when i was trying to click the second li inside the second ul, i dont understand the error

the code:

 await page.waitForSelector(".footer-menu", {timeout: 10000})

  const unorderedList = await page.locator('.footer-menu:nth-child(1) li:nth-child(2)');

  unorderedList.click();

the error


Running 1 test using 1 worker
  1) [chromium] › footer-try.spec.ts:3:5 › has title ───────────────────────────────────────────────

    locator.click: Target closed
    =========================== logs ===========================
    waiting for locator('.footer-menu:nth-child(1) li:nth-child(2)')
    ============================================================

       9 |   const unorderedList = await page.locator('.footer-menu:nth-child(1) li:nth-child(2)');
      10 |
    > 11 |   unorderedList.click();
         |                 ^
      12 |
      13 |   // class=""
      14 |

        at D:PKLPlaywrightTest WebInterplaywright.web.idtestsfooter-try.spec.ts:11:17

    Test timeout of 0ms exceeded while tearing down "context".

  1 failed
    [chromium] › footer-try.spec.ts:3:5 › has title

can anyone show me how to write the right code for my cases?

Unable to download zip file after converting to string

Background: The server returns a zip file and Json data in a multipart response.

On the frontend, when I use just chunkBlob as the blob for downloading the zip file (response also contains Json data), it results in the error,
"Windows cannot open the folder. The Compressed (zipped) Folder '[root]' is invalid",
but when I use chunkBlob2 as the blob for downloading the zip file it opens correctly.

How can I use something like TextDecoder().decode() first, because I need to process the chunk first (separate the zip file from the Json data) before I make it a blob, or how can I make it work with TextDecoder().decode?

.then(response => {
...
    // Read the response as a multipart response
    const reader = response.body.getReader();
    reader.read().then(function processResult(result) {
    ...
        // Convert the received chunk to a string and create a blob 
        const chunkStr = new TextDecoder().decode(result.value); 
        const chunkBlob = new Blob([chunkStr], { type: "application/zip" }); console.log(chunkBlob); 
        
        // Convert the received chunk to a blob 
        const chunkBlob2 = new Blob([result.value], { type: "application/zip" }); console.log(chunkBlob2); 
        
        // Testing using blobs using either a string (chunkStr/chunkBlob) or a chunk (result.value/chunkBlob2) as it is, to see if TextDecoder is the issue 
        let url = window.URL.createObjectURL(chunkBlob); 
        let a = document.createElement('a'); a.href = url; 
        // a.download = "folderAuto.zip"; 
        a.click(); 
        window.URL.revokeObjectURL(url); 

I have also tired to .encode before creating the blob, with no luck.

// Convert to encoded string first and create a blob
const chunkStrEncode = new TextDecoder().decode(result.value);
const chunkUint8Array = new TextEncoder().encode(chunkStrEncode);
const chunkBlobEncode = new Blob([chunkUint8Array], { type: "application/zip" });
console.log(chunkBlobEncode);

Note: chunkBlob and chunkBlobEncode comes to size: 16057 and chunkBlob2 comes to size: 9468

Sever-side code:

def downloadfromserver(request, folderName, folderPath):
    # Multipart response 
    
    # Create the zip archive
    shutil.make_archive(folderName, 'zip', folderPath)
    
    # Generate a random dummy JSON response
    dummy_data = {"foo": "bar"}
    
    # Set a boundary string in the Json header to in turn spilt the response
    boundary_string = "MyBoundaryString"
    json_boundary = "--" + boundary_string
    
    # Add the zip file to the response
    with open(f'{folderName}.zip', 'rb') as f:
        response = HttpResponse(f.read(), content_type='application/zip')
        response['Content-Disposition'] = f'attachment; filename={folderName}.zip'
    
    # Add the dummy JSON to the response
    response.write(json_boundary + "rn")
    response.write("Content-Type: application/jsonrn")
    response.write(
    "Content-Disposition: attachment; filename=dummy.jsonrnrn")
    response.write(json.dumps(dummy_data))
    
    # Delete zip file and folder
    os.remove(f'{folderName}.zip')
    shutil.rmtree(folderPath)
    
    return response

Another question I have is, since the fetch request to the server ends up creating the zip file on the server (sent back in the response for the user to download), would it be better to break everything up into 2 fetches instead of having a multipart response for a zip file and Json data (though one fetch/response seems most efficient)?

The first request would send back the user details, any error messages (where certain files in the zip couldn’t be download) and a string of the zip file name on the server (the zip that was just created) where on the second automatic fetch after the first, the string of the zip file name is sent back to the server so that 1. the correct zip file can be sent to the frontend for the user to download and 2. so the zip file can be deleted/cleared off the server.

Thank you

Editing Omegle Bot script: How can I add line breaks to my message?

Just a heads up I am fairly new to js coding.

I am editing a omegle semi-bot userscript I found and I want to add multiple lines of text that will be sent. Currently this bot will automatically paste “options.g1” as “deez” and thats it.

Is there any way to implement a better function that can allow multiple line breaks without literally printing the command?

Code:

// ==UserScript==
// @name         Omegle semi-bot
// @namespace    https://openuserjs.org/user/burn
// @version      0.2.2
// @description  Write first message and auto-reconnect when disconnected.
// @author       Burn
// @copyright   2019, burn (https://openuserjs.org//users/burn)
// @license     MIT
// @match        https://www.omegle.com/*
// @grant        none
// ==/UserScript==



(function() {
    'use strict';
    var options = {
            g1 : "deez",
            g2 : "Timesaved.reezone.",
            disconnectOnIdle : {
                enabled: true,
                timeout: 300000,
                timeoutId : null
            }
        },
        BreakException = {},
        targetNode = document.querySelector('body'),
        observerConfig = { attributes: false, childList: true, subtree: true },
        tId = null,
        previousListLength = 0,
        getRndIntBetween = function(min, max) {
            return Math.floor(Math.random() * (max - min + 1)) + min;
        },
        callback = function(mutationsList, observer) {
        try {
            mutationsList.forEach(function (mutation) {
                var entry = {
                    mutation: mutation,
                    el: mutation.target,
                    value: mutation.target.textContent,
                    oldValue: mutation.oldValue
                };
                if (entry.el.classList.contains("statuslog")) {
                    if (targetNode.classList.contains("inconversation")) {
                        var btnSubmit = document.querySelector(".sendbtn");
                        var textarea = document.querySelector(".chatmsg");
                        textarea.innerText = options.g1;
                        tId === null && (tId = window.setTimeout(function() {
                            btnSubmit != null && btnSubmit.click();
                            textarea.innerText = options.g2;
                            tId == 100;
                            btnSubmit != null && btnSubmit.click();
                            }, getRndIntBetween(0.8*1000, 1.2*1000)) );
                    }
                }
                if (entry.el.firstChild && entry.el.firstChild.classList) {
                    tId = null;
                    if (entry.el.firstChild.classList.contains("logitem")) {
                        var logs = document.querySelectorAll('.logitem');
                        if (logs.length > previousListLength) {
                            console.log(logs[ logs.length - 1 ].innerText);
                            if (options.disconnectOnIdle.enabled) {
                                clearTimeout(options.disconnectOnIdle.timeoutId);
                                options.disconnectOnIdle.timeoutId = null;
                            }
                            if (options.disconnectOnIdle.enabled &&
                               options.disconnectOnIdle.timeoutId === null) {
                                   options.disconnectOnIdle.timeoutId = window.setTimeout(function() {
                                       console.log("*** ESCO ***");
                                       document.querySelector(".disconnectbtn").click();
                                       document.querySelector(".disconnectbtn").click();
                                   }, options.disconnectOnIdle.timeout);
                            }
                        }
                        if (document.querySelector(".newbtn .disconnectbtn")) {
                            previousListLength = 0;
                            window.setTimeout(function() {
                                document.querySelector(".newbtn .disconnectbtn")
                                && document.querySelector(".newbtn .disconnectbtn").click();
                            }, getRndIntBetween(1.2 * 1000, 1.8 * 1000));
                        }
                    }
                }
            });
        } catch(e) {
            if (e !== BreakException) throw e;
        }
    };

    var observer = new MutationObserver(callback);
    observer.observe(targetNode, observerConfig);
}
)();

I tried adding “n” and it quite literally pastes “deezn” in the messagebox. I have also tried br and br/, but considering its not innerHtml it doesn’t seem to work for that in this case.

Expected outcome:
Example text that I would want to paste – “deez(line break)nuts lmao”
Should be printed as –
Line1: deez
Line2: nuts lmao

Actual outcome:
Line1: deeznnuts lmao

NextJS Fast Refresh Freezing Page

FYI:

  • I’m using Next/Image with a locally imported image camera-hero.png and the placeholder: 'blur'
  • splt.js for text split
  • anime.js for text animation
  • IntersectionObserver for scroll-based animation
  • useEffect to add animations

I’ve never had a problem with npm run dev in NextJS and the fast refresh. When I make a code change in the JSX of the render function and the page fast refreshes, it freezes for some reason. I then get scared and ctrl+w or manually click the “x” icon to close the page at which it takes 5 seconds to actually do so. It seems as if I wrote an infinite while loop accidentally but that isn’t the case.

One interesting thing that happens – if I don’t close the tab, after 10+ seconds the page starts freaking out and spewing HTML and inline CSS as if it was document.write() ‘ing it on the page:

enter image description here

Here is my pages/index.js:

import Head from 'next/head';
import styles from '../styles/Home.module.css';

import Image from 'next/image';
import cameraHero from '../public/camera-hero.png';
import splt from 'spltjs';
import anime from 'animejs';

import { useEffect } from 'react';


export default function Home() {

  useEffect(() => {
    splt({});
    
    const observer = new IntersectionObserver((entries) => {
        entries.forEach((entry) => {
          if(entry.isIntersecting) {
            entry.target.classList.add(styles.animate);

            let textElements = entry.target.querySelectorAll(`.${styles.text}`)
            if (textElements) {
              textElements.forEach(text => {
                let customDelay = text.dataset?.delay || 100

                if (text.dataset.animationType == 'slideup') {
                  anime({
                    targets: text.querySelectorAll('.char'),
                    translateY: ['100%', 0],
                    opacity: [0, 1],
                    direction: 'normal',
                    duration: 1300,
                    loop: 1,
                    delay: anime.stagger(customDelay, {direction: 'reverse'}),
                    easing: 'easeOutSine'
                  });
                }
              })
            }
          } else {
            entry.target.classList.remove(styles.animate);
          }
        })
    })

    const elementsToAnimate = document.querySelectorAll(`.${styles.waiting}`);
    elementsToAnimate.forEach(el => observer.observe(el));
  })

  return (
    <div className={styles.container}>
      <Head>
        <title>ISAAC TSAI</title>
      </Head>

      <section className={styles.one}>
        <div className={`${styles['name-hero']} ${styles.waiting}`}>
          <h1 data-animation-type="slideup" data-delay={150} className={`${styles['name-text']} ${styles.text} splt`}>ISAAC</h1>
          <h1 data-animation-type="slideup" data-delay={150} className={`${styles['name-text']} ${styles.text} splt`}>TSAI</h1>
          <p 
            className={`${styles['name-caption']} ${styles.text} splt`} 
            data-delay={0}
            data-animation-type="slideup"
          >My own little museum</p>
        </div>

        <div className={`${styles['image-block']} ${styles['image-01']} ${styles.waiting}`}>
          <div data-image="01" className={`${styles['image-wrap']}`}>
            <Image
              src={cameraHero}
              fill
              sizes='
              (max-width: 768px) 100vw,
              55vw'
              priority
              placeholder='blur'
              alt={'Taking picture a of the Pantheon with an iPhone'}
            ></Image>
          </div>
          <figcaption data-animation-type="slideup" data-delay={0} className={`${styles.text} splt`}>
          01  —  PANTHEON
          </figcaption>
        </div>
      </section>

    </div>
  )
}

How to play new video on click

Currently i’m using vime.js as video plugin, i expected result was will upload new video when onclick inCar camera button, but it doesnt switch. Am i miss something? i’m new to angular and apologies for my broken english.

enter image description here

from HTML

<div class="video_player__container">
    <app-video-player [videoSrc]="videoSrc"></app-video-player>
    <div class="button__groups">
        <button myeg-button class="car_camera__button" [class.active]="videoType == 'carTop'" (click)="videoType = 'carTop'; getVideo('carTop')">
            <img [src]="videoType == 'carTop' ? '/assets/icons/icon-driving-camera-selected.svg' : '/assets/icons/icon-driving-camera.svg'" alt="car-top-icon">{{ 'assessment_results.score.car_top_camera' | translate }}
        </button>
        <button myeg-button class="car_camera__button" [class.active]="videoType == 'inCar'" (click)="videoType = 'inCar'; getVideo('inCar')">
            <img [src]="videoType == 'inCar' ? '/assets/icons/icon-cabin-camera-selected.svg' : '/assets/icons/icon-cabin-camera.svg'" alt="in-car-icon">{{ 'assessment_results.score.in_car_camera' | translate }}
        </button>
    </div>
</div
getVideo(type) {
    if (type == 'carTop') {
      this.videoSrc = '/assets/video/JPJB102723032000229_D05.mp4'
    } else {
      this.videoSrc = '/assets/video/JPJB102723032000229_D02.mp4'
    }
}
<vm-player #player playsinline>
  <vm-video cross-origin="true">
    <source [src]="videoUrl" type="video/mp4"/>
  </vm-video>
  <vm-default-ui no-settings>
    <vm-live-indicator></vm-live-indicator>
  </vm-default-ui>
</vm-player>
ngOnChanges(changes: SimpleChanges) {
    if (changes['videoSrc']) {
      this.videoUrl = changes.videoSrc.currentValue;
    }
}

i expected result was will upload new video when onclick button

Javascript – single line reduce statement not working becoz of push statement [duplicate]

// only have numbers in array till n times

function deleteNth(arr,n){
    // ...
    function count(arr1, num){
        console.log('arr1', arr1)
        return arr1.reduce((acc, val) => (val === num) ? ++acc : acc, 0);
    }
    // return arr.reduce((acc1, val1) => {
    //     if (count(acc1, val1) < n){
    //         acc1.push(val1);
    //     }
    //     else{
    //         acc1;
    //     }
    //     return acc1;
    // }, []);
    return arr.reduce((acc1, val1) => ((count(acc1, val1) < n) ? acc1.push(val1) : acc1), []);
  }

  
console.log(deleteNth([20,37,20,21], 1));    // [20,37,21]`

when i run with this code am getting error.
TypeError: arr1.reduce is not a function

however when i run with the commented code, its running fine.
with multiple lines of code in reduce function, its working fine.

in single line code, variable acc1 is having value 1 when first array element is processed. due to this am getting error.
can anyone advise what mistake am doing?

console.log(deleteNth([20,37,20,21], 1)); // [20,37,21]

sizingDrp inner content is not showing

In the below HTML it is not showing inner content when click the + drop down button as it supposed to

<div style="text-align: center; font-family: 'Chronicle-Display-Roman'; font-size: 16px;">For all sizing information please click on the links below:</div>
<p> </p>
<div class="sizingAcc" style="max-width: 910px; margin: auto; font-family: 'Century Gothic'; margin-bottom: 20px;">
<div class="sizingBtn toggle">Information <span class="plusSign">+</span></div>
<div class="sizingDrp inner">
<div><strong></strong></div>
<div><strong>*Please note that this guide is for reference only. </strong></div>
<div><br />We wish to create a stress-free shopping experience for your formal &amp; prom dress needs, which is why we have measured each individual garment in-house.</div>
<div>of each different fabric &amp; how it will fit your body.<br /><br />If you are in between sizes or not sure which size to purchase we understand, and are more than happy to assist you. </div>
<div><br /><b>Contact Us:</b></div>
<div>Talk to one of our stylists via or Live Chat below.</div>
<div>Providing us with your usual dress size and measurements (Bust, Waist &amp; Hips) can improve our sizing recommendations for you. <br /><br /><strong>Want to see more images of our gowns?</strong></div>
<div>Visit<span style="color: #b49d73;"> </span>on Instagram and see our gowns on real customers.<br /><br /></div>
</div>
<div class="sizingBtn toggle">How to Measure <span class="plusSign">+</span></div>
<div class="sizingDrp inner"><img src="" alt="How to measure" /></div>
<div class="sizingBtn toggle">Ready to Wear Size Chart <span class="plusSign">+</span></div>
<div class="sizingDrp inner"><img src="" alt="Ready to Wear Size Chart" /></div>
<div class="sizingBtn toggle">Beaded Couture Size Chart <span class="plusSign">+</span></div>
<div class="sizingDrp inner"><img src="" alt="Beaded Couture size chart" /></div>
<div class="sizingBtn toggle">Made to Order Size Chart <span class="plusSign">+</span></div>
<div class="sizingDrp inner"><img src="" alt="Made to Order Size Chart" /></div>
<div class="sizingBtn toggle">Shoes Size Chart <span class="plusSign">+</span></div>
<div class="sizingDrp inner"><img src="" alt="Shoes Size Chart" /></div>
<div class="sizingBtn toggle">Made to Order Fabric Guide <span class="plusSign">+</span></div>
<div class="sizingDrp inner"><img src="" alt="Made to Order Fabric Guide" /></div>
<div class="sizingBtn toggle">Our Models <span class="plusSign">+</span></div>
<div class="sizingDrp inner"><img src="" alt="" width="300" height="200" /></div>
</div>

<style>
.sizingAcc .sizingBtn{
        font-family: 'Chronicle-Display-Roman';
        font-size: 16px;
        letter-spacing: 1px;
    }

    
    .sizingDrp{
        display: none;
    }
   
    

    
    
    div.sizingBtn.toggle {
        padding: 20px 5px;
        margin: 0;
        border-top: 1px solid #dedede;
    }
    span.plusSign {
        float: right;
    }
    .sizingDrp.inner.show {
        border-top: none !important;
    }
</style>

I have tried to add the below code but then it’s showing all the inner content before clicking the drop down + button

  .sizingDrp.inner.show
{
    display: block;
}

Any suggestions how to make this code work to display the inner content? Any help would be greatly appreciated. Thanks heaps!

Edit:

I have added the below JS code but it is not working

    <script src="https://code.jquery.com/jquery-3.6.0.min.js">
 $(document).ready(function() {
  $('.sizingBtn.toggle').click(function() {
    $(this).next('.sizingDrp.inner').toggleClass('show');
    $(this).find('.plusSign').text(function(_, text) {
      return text === '+' ? '-' : '+';
    });
  });
});
    </script>

How to add additional css and js file in thymleaf

I use a layout for my page, in layout includes fragments which contains reusable code. But here’s a probem, my category html need a specific css and js file. I’ve try to add in header tag but nothing happpened.

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:fragment="head_html">
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
              integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N"
              crossorigin="anonymous">

        <link rel="preconnect" href="https://fonts.googleapis.com">
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link href="https://fonts.googleapis.com/css2?family=Lora:wght@400;500;600&display=swap" rel="stylesheet">
        <link rel="stylesheet" type="text/css" href="/css/coffee.css" th:href="@{css/coffee.css}">
        <script src="https://kit.fontawesome.com/bbe981fbfc.js" crossorigin="anonymous"></script>
    </th:block>
</head>
<body>
  <!-- other fragments-->
</body>

My layout

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" th:fragment="layout (content)">
<head>
    <div th:replace="~{fragment/user_fragment :: head_html}"></div>
</head>
<body>
<div th:replace="~{fragment/user_fragment :: navigation}"></div>

<div th:insert="${content}"></div>

<div th:replace="~{fragment/user_fragment :: footer}"></div>


<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"
        integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
        crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct"
        crossorigin="anonymous"></script>
<script src="/javascript/script.js" th:src="@{/javascript/script.js}"></script>
</body>
</html>

And my category

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      th:replace="~{layout/user_layout :: layout(~{::content})}">
<head>
    <link rel="stylesheet" href="/css/what.css" th:href="@{css/what.css}">
    <script src="/javascript/what.js" th:src="@{javascript/what.js}"></script>
</head>
<body>
    <!-- code -->
</body>

I did add in category header but it does not load any file. What should I do?

Creating new emtpy file with touch command in Node

I am taking an online course on Node.js..and it says to create new empty JS file using “touch” command –
touch script.js
But i am getting this error –

$ node
Welcome to Node.js v18.14.2.
Type ".help" for more information.

> touch dummy2.js
touch dummy2.js
      ^^^^^^

Uncaught SyntaxError: Unexpected identifier
>

Should i use different command to create a new file in the command line as i am using Windows?
I read through this But did not work for me –
Create file with command line in Node