Count empty arrray

I need to count letters of string, I don’t know how to get empty array

    const regex = /[[]]/gi;
    const a = str.replaceAll(regex, ' ').trim().split(" ")
    const arr = []
    const arr2 = []
    let newArr
    for(let i = 0; i < a.length; i++) {
       if (a[i].length === 0) {
           arr2.push(0)
       } 
       if (a[i].length !== 0) {
           arr.push(a[i].length)
       } 
    }
    newArr = arr.concat(arr2)
    if (newArr.includes(0)) {
        newArr.pop()
    }
    return newArr.join(", ")

I must get:
[Tom][] -> 3, 0
But I get a 3 without ziro

Passing a JSON array to a Vis.js timeline DataSet or Item

I would like to pass a JSON array to a Vis.js timeline DataSet or Item but I can’t see how.

In Datatables for example, you could pass a php-generated Json array drawing data from a Google Sheet spreadsheet:

var table = $('#example').DataTable( {
        "ajax": "http://mywebsite.com/tabella/json.php",
        "pageLength": 1000,
        "lengthMenu": [200, 500, 2000, 5000],
        "columns": [
            {            
                "className":      'details-control',
                "orderable":      false,
                "data":           null,
                "defaultContent": ''                
            },
            
            { "data": "inizio", type: 'date', orderDataType: 'date', defaultContent: '' },
            { "data": "evento", defaultContent: ''  },
            { "data": "etichetta", defaultContent: ''  },
            { "data": "fine", type: 'date', defaultContent: '' },
            { "data": "dettagli", "visible": false, defaultContent: ''  }
        ],
        "order": [[1, 'asc']]
    } );
<?php
$json   = file_get_contents('https://sheets.googleapis.com/v4/spreadsheets/*MySpreadsheet*/values/base?key=*MyAPIKEY*');

$originalArray = json_decode($json, true);

$keys = ["id", "inizio", "evento", "etichetta", "dettagli", "fine"];
$rows = array_slice($originalArray['values'], 1);

$data = [];
foreach($rows as $i => $row) {
    array_unshift($row, (string)($i + 1));
    
    $data[] = array_combine($keys, $row);
}

$output = json_encode(["data" => $data]);
echo $output;
?>

Google Sheet structure

I would like to be able to do the same thing on Vis.js -i.e.: passing a Json array to the DataSet constructor– but I wasn’t able to find any command in the documentation to perform the task.

My JSFiddle

I want to transform the coordinates of a parallel projection in WebGL

Parallel projection in WebGL,

const orthoMatrix = mat4.create();
mat4.ortho(orthoMatrix, -1, 1, -1, 1, near, far);
    
    

Some of the parts that are done as


mat4.ortho(orthoMatrix, -0.5, 1, -0.5 1, near, far);


and display it on the screen. We want to convert the coordinates of the mouse on the screen to mat4.ortho(orthoMatrix, -0.5, 1, -0.5 1, near, far); from the coordinates obtained on mat4.ortho(orthoMatrix, -1, 1, -1, 1, near, far); before cropping. I would like to convert them to Is it possible to do so?


I would like to convert the screen size to





width = 600, height = 600


and then cut out by mat4.ortho(orthoMatrix, -0.5, 1, -0.5 1, near, far), with width = 600 and height = 600, scaled up.

It would be great if you could let me know.

Laravel Mix keeps compiling every second without stop with Tailwind v4

This is my first time using Tailwind v4, and as I understand it the installation has been dramatically simplified.

My typical workflow is to use PostCSS and Tailwind with Laravel Mix to compile the files.

When I run npx mix watch with Tailwind v4, it compiles constantly without waiting for changes to be made in the code. I don’t know if this is due to me missing something in the setup so I have listed my files below.

webpack.mix.js:

const mix = require("laravel-mix");

mix
 .js("src/js/app.js", "dist/js/app.js")
 .postCss("src/css/app.pcss", "dist/css/app.css", [
   require("@tailwindcss/postcss"),
  ]);

postcss.config.mjs:

  export default {
  plugins: {
    "@tailwindcss/postcss": {},
  },
};

My directory setup includes:

  • index.html
  • src/css/app.pcss
  • src/js/app.js
  • dist (where the compiled files go)

app.pcss:

@import "tailwindcss";

@theme {
  --color-dark-charcoal: #333;
}

I am not sure what Laravel Mix is detecting to keep recompiling the files, so any help would be appreciated.

Firefox extension: launchWebAuthFlow not able to use sendResponse

I’m creating a web extension on Firefox using React

When I click on a button, a callback is called:

browser.runtime.sendMessage({ type: "auth", url: "url" })
    .then((response) => {
      console.log("Response:", response);
    })
    .catch((error) => {
      console.error("Error:", error);
    });

And, the background script is listening and indeed receives the message:

browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
    if (message.type === "auth") {
      browser.identity.launchWebAuthFlow({ url: message.url, interactive:true })
        .then((responseUrl) => {
          console.log("callback!")
          sendResponse({ success: true, url: responseUrl });
        })
        .catch((error) => {
          sendResponse({ success: false, error: error.message });
        });
  
      return true;
    }
  });

The OAuth call is going fine, the callback is called and the log “callback!” can be seen. But the message is never received back on React side

Here is my manifest:

{
  "manifest_version": 2,
  "name": "Open Link Extension",
  "version": "1.0",
  "description": "An extension that opens a link when a button is clicked.",
  "permissions": [
    "tabs",
    "identity",
    "activeTab",
    "webRequest",
    "<all_urls>",
    "cookies"
  ],
  "browser_action": {
    "default_popup": "html/popup.html"
  },
  "background": {
    "scripts": [
      "src/background.js"
    ],
    "persistent": false
  },
  "icons": {
    "48": "icon.png"
  }
}

Thanks for your help!

Why is my a:link color not showing properly before a keyframe animation on the click that changes it to a:visited?

I’m new to CSS and have been playing around with keyframe animations. I currently am using both CSS and js in order to achieve the following:

apply a keyframe animation when a link is hovered over
apply a second animation when a link is no longer hovered over, but hasn’t been clicked
apply a third animation when a link is clicked (and js to delay the nav for a moment so the animation can play, but only the first time it’s clicked – after that it returns to normal link behavior)

My problem is that all my links are the a:visited color, even before they’re clicked. I’m sure this has to do with how I set up the keyframe animations, but I can’t figure out why – the hover-in and hover-out animations begin with the unvisited link color (hover in) and end with currentColor (hover out). If I change currentColor to the unvisited link color, the links ignore the a:visited color.

I don’t think the on-click animation is at fault, since it only applies after a:active has been used (I also tried a:focus but it didn’t seem to make a difference), but it does end on the visited link color.

(There are other issues, like the hover out animation playing on page load despite being paused, and the browser not remembering the visited state between page loads, but I can live with those if the link color behaves.)

Alternately, could it be the js doing this? I don’t understand js very well at all, I had a lot of help with it.

CSS:

    /* Base state for the link - initial color is reddish */



a:not(.sitenav a):not(.footer a) {
  animation-play-state: paused; /* Prevent any animation from starting initially */
  color: #660e0e;  /* Start as reddish */
  pointer-events: auto;
  position: relative; /* Ensure the link is positioned */
  text-decoration: none;
  display: inline-block;
}
 
   a:link {
       position: absolute;  /* Ensure the link is positioned */
        z-index: 1; /* Ensure the link is above other elements */
      color: #660e0e;  /* Start as reddish */
      pointer-events: auto;
      text-decoration: none;
      transition: color 0.4s ease;
    }



/* Ensuring the link remains clickable during the animation */
    a:hover {
      pointer-events: auto; /* Ensures pointer events remain enabled */
    }



 

/* Hover-out animation when the mouse leaves, but only if the link hasn't been clicked */
a:not(.sitenav a):not(.footer a):not(:active):not(:hover) {
    animation-play-state: paused; /* make animation not load on page load */
  animation: hover-out 4s forwards;
}


    /* visited link */
a:visited {
  color: black;
  text-shadow: 0 0 5px brown; /* text-shadow for visited links */
}



    
    /* selected link */
a:not(.sitenav a):not(.footer a):active {
  animation-play-state: running; /* make animation load */
  animation: active-animation 3s forwards;
} 

    /* Hover-in animation for normal hover effect (only when not clicked) */
    a:not(.sitenav a):not(.footer a):hover {
        animation-play-state: running; /* make animation load */
      animation: hover-in 3s forwards; /* Add hover animation */
    }


 

    /* Active link animation (brown -> red -> black) */
    @keyframes active-animation {
      0% {
        color: #b80909; /* Start as bright red */
        text-shadow: 0 0 20px darkred, text-shadow: 0 0 5px brown;
      }
      10% {
        font-size: 1.02em; /* embiggen */
        text-shadow: 0 0 20px darkred, text-shadow: 0 0 10px brown;
      }
      20% {
          color: black;
      }
      30% {
        font-size: 1.02em;
      }
      60% {
        text-shadow: 0 0 10px darkred, 0 0 5px brown;
        font-size: ''; /* shrink again */
      }
      100% {
        color: black; /* Fade back to black */
        text-shadow: 0 0 0px darkred, text-shadow: 0 0 5px brown;
      }
    }


    /* Hover-in animation (reddish to black with shadow) */
    @keyframes hover-in {
      0% {
        color: #660e0e; /* Start as dark red */
        text-shadow: none;
      }
      100% {
        color: black;
        text-shadow: 0 0 30px #850000, 0 0 10px #110402, 0 0 5px #110402;
      }
    }

    /* Hover-out animation (black to prev color with shadow fading) */
    @keyframes hover-out {
      0% {
        color: black;
        text-shadow: 0 0 30px #850000, 0 0 10px #110402, 0 0 5px #110402;
      }
      50% {
        color: black;
        text-shadow: 0 0 20px #850000, 0 0 5px #110402, 0 0 3px #110402;
      }
      100% {
        color: currentColor; /* return to prev state? */
      }
    }

js:

document.querySelectorAll('a:not(.sitenav a):not(.footer a)').forEach(function (link) {
  let isAnimating = false;  // Flag to track if animation is already happening
  const linkId = link.href; // Use the link's href as a unique identifier
  let hasAnimatedOnce = localStorage.getItem(linkId) === 'true'; // Retrieve the value from localStorage

  link.addEventListener('click', function (e) {
    // If the link has been clicked before (stored in localStorage), allow normal behavior
    if (hasAnimatedOnce) {
      return; // Normal navigation will happen
    }

    // If animation is already happening, ignore the click
    if (isAnimating) {
      return;  // Do nothing if animation is in progress
    }

    // Prevent default navigation behavior to wait for the animation
    e.preventDefault();

    // Mark that the animation is starting
    isAnimating = true;

    // Reset the animation by removing it first (so it can be reapplied)
    this.style.animation = '';  // Remove the animation to allow it to play again

    // Trigger the animation by adding the animation property again
    this.style.animation = 'active-animation 3s forwards';  // Adjust timing as necessary

    const linkElement = this;

    // Listen for the animationend event to trigger navigation after animation finishes
    linkElement.addEventListener('animationend', function () {
      // Now navigate to the link's href after the animation finishes
      window.location.href = linkElement.href;

      // Reset the animation flag so the link can be clicked again, and the animation can play
      isAnimating = false;

      // Mark that the link has been clicked and animated once
      hasAnimatedOnce = true;
      
      // Save the state to localStorage so the flag persists across sessions
      localStorage.setItem(linkId, 'true');
      
    });
  });
});

I created a Javascript a calendar that fetches events from an API. The problem is This events and this calendar should be in Pst

// Constants for API endpoints and configuration const API_CONFIG = { BASE_URL: ‘https://wocstgold.wpengine.com/wp-json’, TICKETS_ENDPOINT: ‘/tribe/tickets/v1/tickets/’, EVENTS_ENDPOINT: ‘/tribe/events/v1/events’, TIMEZONE: ‘America/Los_Angeles’ }; // DOM Element References const DOM_ELEMENTS = { daysContainer: document.getElementById(‘daysContainer’), weekRange: document.getElementById(‘weekRange’), eventsList: document.getElementById(‘eventsList’), prevWeek: document.getElementById(‘prevWeek’), nextWeek: document.getElementById(‘nextWeek’) }; // Application State class CalendarState { constructor() { this.currentDate = new Date(); this.events = {}; this.debounceTimer = null; } // Utility method to get local timezone date getLocalDate(date = new Date()) { return new Date(date.toLocaleString(‘en-US’, { timeZone: API_CONFIG.TIMEZONE })); } } // API Service for fetching events and tickets class EventAPIService { // Fetch all tickets from the API static async fetchAllTickets() { const baseUrl = ${API_CONFIG.BASE_URL}${API_CONFIG.TICKETS_ENDPOINT}; let allTickets = []; let currentPage = 1; let totalPages = 1; try { do { const response = await fetch(${baseUrl}?page=${currentPage}); const data = await response.json(); allTickets = allTickets.concat(data.tickets); if (currentPage === 1) { totalPages = data.total_pages; } currentPage++; } while (currentPage <= totalPages); return allTickets; } catch (error) { console.error(‘Error fetching tickets:’, error); return []; } } // Fetch events for a specific week static async fetchEventsForWeek(startDate, endDate) { const eventsUrl = ${API_CONFIG.BASE_URL}${API_CONFIG.EVENTS_ENDPOINT}?start_date=${startDate}&end_date=${endDate}; try { const [eventsResponse, allTickets] = await Promise.all([ fetch(eventsUrl), this.fetchAllTickets() ]); const eventsData = await eventsResponse.json(); return this._processEventsWithTickets(eventsData.events, allTickets); } catch (error) { console.error(‘Error fetching events:’, error); return {}; } } // Process events and map ticket information static _processEventsWithTickets(events, tickets) { const processedEvents = {}; const ticketDetails = this._createTicketDetailsMap(tickets); events.forEach((event) => { const eventDate = new Date(event.start_date).toISOString().split(‘T’)[0]; const eventTime = new Date(event.start_date).toLocaleTimeString(‘en-US’, { hour: ‘2-digit’, minute: ‘2-digit’ }); const ticketInfo = ticketDetails[event.id] || {}; if (!processedEvents[eventDate]) { processedEvents[eventDate] = []; } processedEvents[eventDate].push({ title: event.title, time: eventTime, description: event.description || ‘No description provided’, url: event.url, location: event.venue?.venue || ‘N/A’, organizer: event.organizer[0]?.organizer || ‘N/A’, fullDate: event.start_date, ticketName: ticketInfo.title || ‘No ticket information’, ticketSaleDate: ticketInfo.saleDate || ‘Ticket sale date not specified’, ticketCost: ticketInfo.cost || ‘Cost not available’ }); }); return processedEvents; } // Create a map of ticket details for efficient lookup static _createTicketDetailsMap(tickets) { return tickets.reduce((map, ticket) => { if (ticket.available_from) { map[ticket.post_id] = { saleDate: ticket.available_from, title: ticket.title, cost: ticket.cost }; } return map; }, {}); } } // Calendar Renderer class CalendarRenderer { constructor(state) { this.state = state; } // Update the week display and render days async updateWeek() { this._clearContainers(); const { startOfWeek, endOfWeek, today } = this._calculateWeekBoundaries(); this._updateWeekRangeDisplay(startOfWeek, endOfWeek); const startDate = startOfWeek.toISOString().split(‘T’)[0]; const endDate = endOfWeek.toISOString().split(‘T’)[0]; this.state.events = await EventAPIService.fetchEventsForWeek(startDate, endDate); this._renderDays(startOfWeek, today); this._displayEvents(); } // Calculate week boundaries in local timezone _calculateWeekBoundaries() { const localToday = this.state.getLocalDate(); console.log(‘Local Today:’, localToday); // Calculate start of the week (Sunday) based on the local today’s date const startOfWeek = new Date(localToday); startOfWeek.setDate(localToday.getDate() – localToday.getDay()); startOfWeek.setHours(0, 0, 0, 0); // Calculate end of the week (Saturday) const endOfWeek = new Date(startOfWeek); endOfWeek.setDate(startOfWeek.getDate() + 6); endOfWeek.setHours(23, 59, 59, 999); console.log(‘Start of Week:’, startOfWeek); console.log(‘End of Week:’, endOfWeek); return { startOfWeek, endOfWeek, today: localToday }; } // Get the start of the week (Sunday) _getWeekStart(date) { const start = new Date(date); start.setDate(start.getDate() – start.getDay()); start.setHours(0, 0, 0, 0); return start; } // Get the end of the week (Saturday) _getWeekEnd(date) { const end = new Date(date); end.setDate(end.getDate() + (6 – end.getDay())); end.setHours(23, 59, 59, 999); return end; } // Update week range display _updateWeekRangeDisplay(startOfWeek, endOfWeek) { DOM_ELEMENTS.weekRange.textContent = ${startOfWeek.toLocaleDateString('en-US', { month: 'long', day: 'numeric' })} – ${endOfWeek.toLocaleDateString('en-US', { month: 'long', day: 'numeric' })}; } // Render days of the week _renderDays(startOfWeek, today) { DOM_ELEMENTS.daysContainer.innerHTML = ”; for (let i = 0; i < 7; i++) { const dayDate = new Date(startOfWeek); dayDate.setDate(startOfWeek.getDate() + i); const dayDiv = this._createDayElement(dayDate, today); DOM_ELEMENTS.daysContainer.appendChild(dayDiv); } } // Create day element with appropriate styling and event listeners _createDayElement(dayDate, today) { const dayDiv = document.createElement(‘div’); dayDiv.className = ‘day-item’; dayDiv.textContent = dayDate.getDate(); if (dayDate.setHours(0, 0, 0, 0) < today.setHours(0, 0, 0, 0)) { this._stylePastDate(dayDiv); } else { this._addDayClickHandler(dayDiv, dayDate); } if (dayDate.toDateString() === today.toDateString()) { dayDiv.classList.add(‘current’); } return dayDiv; } // Style past dates _stylePastDate(dayDiv) { dayDiv.classList.add(‘disabled’); dayDiv.style.color = ‘#cccccc’; dayDiv.style.cursor = ‘not-allowed’; dayDiv.style.pointerEvents = ‘none’; } // Add click handler for future dates _addDayClickHandler(dayDiv, dayDate) { dayDiv.addEventListener(‘click’, () => { document.querySelectorAll(‘.day-item’).forEach(item => item.classList.remove(‘current’)); dayDiv.classList.add(‘current’); this._displayEvents(dayDate); }); } // Display events for the week or a specific date _displayEvents(selectedDate = null) { DOM_ELEMENTS.eventsList.innerHTML = ”; const { startOfWeek, endOfWeek } = this._calculateWeekBoundaries(); if (!selectedDate) { this._displayAllWeekEvents(startOfWeek, endOfWeek); } else { this._displaySingleDateEvents(selectedDate); } } // Display all events for the week _displayAllWeekEvents(weekStart, weekEnd) { let eventsDisplayed = false; for (const date in this.state.events) { const eventDate = new Date(date); if (eventDate >= weekStart && eventDate <= weekEnd) { this._createEventSection(date, this.state.events[date]); eventsDisplayed = true; } } if (!eventsDisplayed) { DOM_ELEMENTS.eventsList.innerHTML = ‘
No events scheduled for this week.

‘; } } // Display events for a single date _displaySingleDateEvents(selectedDate) { const isoDate = selectedDate.toISOString().split(‘T’)[0]; if (this.state.events[isoDate]) { this._createEventSection(isoDate, this.state.events[isoDate]); } else { DOM_ELEMENTS.eventsList.innerHTML = `
No events for ${selectedDate.toLocaleDateString()}.

; } } // Create event section for a specific date _createEventSection(date, eventsForDate) { const dateSection = document.createElement('div'); dateSection.className = 'event-date-section'; const eventStartDate = new Date(eventsForDate[0].fullDate); const formattedDate = eventStartDate.toLocaleDateString('en-US', { weekday: 'long', month: 'long', day: 'numeric' }); dateSection.innerHTML =
${formattedDate}
; eventsForDate.forEach(event => { const eventDiv = this._createEventElement(event); dateSection.appendChild(eventDiv); }); DOM_ELEMENTS.eventsList.appendChild(dateSection); } // Create individual event element _createEventElement(event) { const eventDiv = document.createElement('div'); eventDiv.className = 'event-item'; eventDiv.innerHTML =
${event.title}
Time: ${event.time}

Description: ${this._truncateText(event.description, 50)}

Instructor: ${event.organizer}

Location: ${event.location}

Ticket Name: ${event.ticketName}

Ticket Sale Date: ${event.ticketSaleDate}

Ticket Cost: ${event.ticketCost}

View Details `; return eventDiv; } // Truncate text utility method _truncateText(text, maxLength) { return text.length > maxLength ? text.substring(0, maxLength) + ‘…’ : text; } // Clear containers before rendering _clearContainers() { DOM_ELEMENTS.daysContainer.innerHTML = ”; DOM_ELEMENTS.eventsList.innerHTML = ”; } } // Utility function for debouncing function debounce(func, delay) { return (…args) => { clearTimeout(this.debounceTimer); this.debounceTimer = setTimeout(() => func(…args), delay); }; } // Main initialization function async function initializeCalendar() { const calendarState = new CalendarState(); const calendarRenderer = new CalendarRenderer(calendarState); // Week navigation event listeners DOM_ELEMENTS.prevWeek.addEventListener(‘click’, debounce(() => { calendarState.currentDate.setDate(calendarState.currentDate.getDate() – 7); calendarRenderer.updateWeek(); }, 300)); DOM_ELEMENTS.nextWeek.addEventListener(‘click’, debounce(() => { calendarState.currentDate.setDate(calendarState.currentDate.getDate() + 7); calendarRenderer.updateWeek(); }, 300)); // Initial week update await calendarRenderer.updateWeek(); } // Initialize the calendar when the page loads document.addEventListener(‘DOMContentLoaded’, initializeCalendar);

Default props in reactjs not showing on screen

I am trying to give a default title to the react js web application but it is not taking the default value.
This below is App.js where i was giving the value of title before adding a default prop and it was working fine. After i added the default prop, it is not updating on my screen in browser. showing blank for the title only.
App.js:

import './App.css';
import Footer from "./MyComponents/Footer";
import Header from "./MyComponents/Header";
import Todos from "./MyComponents/Todos";

function App() {
  
  return (
      <><Header searchbar = {true}/><Todos/><Footer /></>
  
  );
}

export default App;

This is header.js i have been using. I have used some demo bootstrap code and following a tutorial.

Header.js

import PropTypes from 'prop-types';
import React from 'react';

export default function Header(props) {
  return (
    <div>
      <nav className="navbar navbar-expand-lg bg-body-tertiary">
  <div className="container-fluid">
    <a className="navbar-brand" href="#">{props.title}</a>
    <button className="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span className="navbar-toggler-icon"></span>
    </button>
    <div className="collapse navbar-collapse" id="navbarSupportedContent">
      <ul className="navbar-nav me-auto mb-2 mb-lg-0">
        <li className="nav-item">
          <a className="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li className="nav-item">
          <a className="nav-link" href="#">About</a>
        </li>
      </ul>
      {props.searchbar?<form className="d-flex" role="search">
        <input className="form-control me-2" type="search" placeholder="Search" aria-label="Search"/>
        <button className="btn btn-outline-success" type="submit">Search</button>
      </form>: "No Search Bar"}
      {/* {props.searchbar?<form className="d-flex" role="search">
        <input className="form-control me-2" type="search" placeholder="Search" aria-label="Search"/>
        <button className="btn btn-outline-success" type="submit">Search</button>
      </form>: "NO Search Bar"} */}
    </div>
  </div>
</nav>
    </div>
  )
}

Header.defaultProps = {
  title: "Your Title is this"
}

Header.propTypes = {
  title: PropTypes.string
}

In this package.json i have react 19. I am following tutorial in which he have used an older version.

Package.json:

{
  "name": "todolist",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "bootstrap": "^5.3.3",
    "cra-template": "1.2.0",
    "react": "^19.0.0",
    "react-bootstrap": "^2.10.9",
    "react-dom": "^19.0.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^1.1.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

I have tried adding an undefined value but passing the title such as title: {undefined} but it did not work out

Javascript, open new tab after click, wrong site open

I have two buttons in two separate application page. If the user clicks them, I would like to open respectively two different google forms in a new browser tab. The click on ‘m’ produces the desired outcome, while the click on ‘c’ opens google homepage in a new tab and not the form. If I open manually the two links they both works.

What could be the reason of this different behavior?

HTML1

<button id="c" type="button" class="btn btn-default btn-block">C</button>

HTML2

<button id="m" type="button" class="btn btn-default btn-block">M</button>

JS

document.addEventListener("DOMContentLoaded", function () {
    const m = document.getElementById("m");
    if (m) {
        m.addEventListener("click", function () {
            window.open("https://forms.gle/abcdefghijk", "_blank");
        });
    }

    
    const c = document.getElementById("c");
    if (c) {
        c.addEventListener("click", function () {
            window.open("https://forms.gle/zxcvbnmasdf", "_blank");
        });
    }
});

JavaScript/TypeScript: Function to Determine Current School Grade from Graduation Year and Month Doesn’t Work as Expected

I am trying to create a function in TypeScript that determines the current school grade based on the graduation year and graduation month.

However, the function does not return the expected result for March graduations.
I would like to understand why it is not working correctly and how to fix it.

Here is my current implementation:

export const getGrade = (gradYear: number, gradMonth: number): string => {
  const today = new Date();
  const currentYear = today.getFullYear();

  // **March Graduation (School year changes on April 1st)**
  if (gradMonth === 3) {
    const graduationCutoff = new Date(gradYear + 1, 3, 1); // **Treated as graduated after April 1st**
    if (today < graduationCutoff) {
      const diff = gradYear - currentYear;
      return (
        [
          'High School Senior',
          'High School Junior',
          'High School Sophomore',
          'Middle School 3rd Year',
          'Middle School 2nd Year',
          'Middle School 1st Year',
        ][diff] ?? `${gradYear} Graduate`
      );
    }
    return `${gradYear} Graduate`;
  }

  // **June/September/December Graduations (School year changes on the 1st of the following month)**
  if ([6, 9, 12].includes(gradMonth)) {
    const graduationCutoff = new Date(gradYear, gradMonth, 1); // **Treated as graduated from the 1st of the following month**
    if (today < graduationCutoff) {
      const diff = gradYear - currentYear;
      return (
        [
          'High School Senior',
          'High School Junior',
          'High School Sophomore',
          'Middle School 3rd Year',
          'Middle School 2nd Year',
          'Middle School 1st Year',
        ][diff] ?? `${gradYear} Graduate`
      );
    }
    return `${gradYear} Graduate`;
  }
  return '';
};

Expected vs. Actual Output:
Today’s date: February 2, 2025 (new Date() output)


console.log('------------- March Graduations -------------');
console.log(getGrade(2023, 3)); // Expected: 2023 Graduate ✅
console.log(getGrade(2024, 3)); // Expected: High School Senior → Actual: 2024 Graduate ❌
console.log(getGrade(2025, 3)); // Expected: High School Junior → Actual: High School Senior ❌
console.log(getGrade(2026, 3)); // Expected: High School Sophomore → Actual: High School Junior ❌
console.log(getGrade(2027, 3)); // Expected: Middle School 3rd Year → Actual: High School Sophomore ❌
console.log(getGrade(2028, 3)); // Expected: Middle School 2nd Year → Actual: Middle School 3rd Year ❌
console.log(getGrade(2029, 3)); // Expected: Middle School 1st Year → Actual: Middle School 2nd Year ❌

On the other hand, the calculations for June, September, and December graduations work correctly and return the expected results.

Attempt to run PHP code inside JavaScript file fails (Laravel)

I am attempting to run an older Laravel application locally (PHP v. 5), but it fails when executing PHP code embedded in a JavaScript file (app.js):

<?php
// ...
if (Auth::check()){
    // Hier beginnt der HTML-Code, der nur angezeigt wird, wenn der Benutzer eingeloggt ist.

    // Benutzername des eingeloggten Benutzers abrufen
    $username = Auth::user()->username;

    // Navbar für eingeloggte Benutzer erstellen
    echo '
        <div class="navbar navbar-inverse" role="navigation">
            <!-- ... -->
        </div>

The browser throws this error:

Uncaught SyntaxError: Unexpected token ‘<‘ (at app.js:1:1)

The JavaScript files are located in the Laravel public folder, and I started the application with:

php artisan serve

I understand PHP is server-side and cannot be executed by the browser. However, the application works fine on my friend’s server. Does anyone know why it doesn’t work locally or how to fix this?

Why Is My SubMenu In Context Menu Not Appearing Vscode Extension

I wanted to show a submenu with menus inside it in the right click context menu and i had this setup:

"categories": [
    "Other"
  ],
  "activationEvents": [
    "onCommand:colorquick.helloWorld"
  ],
  "main": "./dist/extension.js",
  "contributes": {
    "commands": [
      {
        "command": "colorquick.helloWorld",
        "title": "Hello World"
      }
    ],
    "menus": {
      "editor/context": [
        {
          "submenu": "colorquick.submenu",
          "when": "editorTextFocus",
          "group": "navigation"
        }
      ],
      "editor/context/colorquick.submenu": [
        {
          "command": "colorquick.helloWorld",
          "group": "navigation"
        }
      ]
    },
    "submenus": [
      {
        "id": "colorquick.submenu",
        "label": "ColorQuick"
      }
    ]
  },

but it dosent come up, but if i dont use a submenu and i just put the command as a menu it comes up why is it not working;
enter image description here

Google Apps Script BatchUpdate appending single apostrophe to output

I’m using Google Apps Script batchupdate method to update cell values. My 2d array has a column of date values formatted as strings so they look like:

["4 October 2025", "6 January 2025"]

I’m setting the request as follows:

{
   updateCells: {
     range: 
     { 
       sheetId:          sheetID 
       startRowIndex:    startRow - 1,
       endRowIndex:      startRow + array.length,
       startColumnIndex: startColumn - 1,
       endColumnIndex:   startColumn - 1 + array[0].length
     },
     rows: _get_batch_update_type(array),
          fields: "userEnteredValue"
   }
}

function _get_batch_update_type(input) {
  //Dealing with array
  if (input.constructor === Array) {
    return input.map(row => ({ 
      values: row.map(element => ({ 
        userEnteredValue: (typeof element === "string" || Number.isNaN(element) ? { stringValue: element } : { numberValue: element }) 
      })) 
    }));
  }
  
  return [{ values: [{ 
    userEnteredValue: (typeof input === "string" || Number.isNaN(input) ? { stringValue: input } : { numberValue: input }) 
  }]}];
}

When I run the request, the values are set to my sheet with a leading apostrophe

+----------------+
|     A          | 
+----------------+
|'4 October 2025 | 
+----------------+
|'6 January 2025 | 
+----+-----------+

The column in the sheet is formatted as a date. How can I modify the request so that apostrophe is not pasted as part of the output?

Chart.js – Invalid scale configuration

Below is the code snippet for scale configuration, which shows error on browser console.

The Error shown in console as:
“Invalid scale configuration for scale: x”

Moreover, if I remove [ ] brackets for x, the chart does not load.
Help me understand the error and ways to solve the same.

options: {
                responsive: true,
                maintainAspectRatio: false,
                scales: {
                    x: [{
                        type: 'time',
                        time: {
                            unit: 'hour'
                        }
                    }],
                    y: {
                        beginAtZero: true
                    }
                }
            }