Minify JS with VS code extension

I need: minify JS file with extension from the store, but I can’t find an option to remove whitespace between html tags in variables

I use: JS & CSS Minifier (Minify) – https://marketplace.visualstudio.com/items?itemName=olback.es6-css-minify (because I’m lazy to set up a Webpack)

So if input is:

html = `<li class="item">
      <div class="text">
        <p>${array[i]}</p>
      </div>
    </li>`;

Output is only:

s=`<li class="item">n      <div class="text">n        <p>${o[r]}</p>n      </div>n    </li>`;

The extension uses Terser to minify the code, but I couldn’t find any option to remove the whitespace. Thanks for help.

Getting rid of “before you continue to google” with jsoup

I’m trying to get google search engine results in this way:

    Document document = Jsoup.connect("https://www.google.com/search?q=example").userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11 Firefox/19.0").timeout(3000).get();
    Elements temp = document.select("div.rc");

but I’m getting the before you continue to google page, which doesn’t allow me to get the information i want.

I also tried this:

    try {
        Map<String, String> cookies = Jsoup.connect("https://www.google.com/search?q=example").execute().cookies();
        Document document = Jsoup.connect("https://www.google.com/search?q=example").userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11 Firefox/19.0").timeout(3000).cookies(cookies).get();
        Elements temp = document.select("div.rc");

    } catch (IOException e) {
        // error handling
    }

to connect with those cookies, but it doesn’t work too. Is there a way to get around that annoying page?

Thanks in advance

glide.js how to restart keyframe animation when the slide is changed

I have been trying for hours to achieve this, no clue if I should remove the animation classes or if glide has some sort of classes when the slide is changed..
Im new to javascript so I dont understand much

I have this code and this animation that plays but I cant get it work when the slide is changed

            <div class="glide__arrows" data-glide-el="controls">
            <button class="glide__arrow glide__arrow--left" data-glide-dir="<" onclick="stop_animation()"><</button>
            <button class="glide__arrow glide__arrow--right" data-glide-dir=">" onclick="stop_animation()">></button>
          </div>
        <div class="glide__track" data-glide-el="track">
            <ul class="glide__slides">
                <div class="glide_slide glide_slide info ratio3to2" style="position: relative;">
                        <img class="img" src="./foto_full/Baroknisal.jpg" alt="Kanál v Amsterodamu">
                        <p id="main__nadpis">VÍTEJTE U FARA JÍTRAVA</p>
                        <p id="main__podnadpis"> Rezervace jedním kliknutím</p>
                        <a id="main__rezervace" href="">Rezervace</a>
                </div>
                <div class="glide_slide glide_slide glide_slide info ratio3to2" style="position: relative;">
                        <img class="img" src="./foto_full/cesta.jpg" alt="Amsterodam (pobřeží)">
                        <p id="main__nadpis">VÍTEJTE U FARA
                            JÍTRAVA</p>
                            <p id="main__podnadpis">Rezervace jedním kliknutím</p>
                            <a id="main__rezervace" href="">Rezervace</a>
        </div>
        </ul>
    </div>
#main__nadpis {
  position: absolute;
  bottom: 4em;
  right: 9.5em;
  animation: slideright 8s infinite;
  animation-fill-mode: forwards;
  animation-delay: .45s;
}

#main__podnadpis {
position: absolute;
bottom: 6.75em;
right: 9.5em;
animation: slideleft 8s infinite;
animation-fill-mode: forwards;
animation-delay: .45s;
}

@keyframes slideright {
0% {
}

25% {
}

35% {
  transform: translate(2.5em);
  animation-fill-mode: forwards;
}

100% {
  transform: translate(2.5em);
  animation-fill-mode: forwards;
}
}

@keyframes slideleft {
0% {
}

25% {
}

35% {
  transform: translate(-4.5em);
  animation-fill-mode: forwards;
}

100% {
  transform: translate(-4.5em);
  animation-fill-mode: forwards;
}
}


#main__rezervace {
  position: absolute;
  bottom: 2.5em;
  right: 14em;
  animation: slideup 8s infinite;
  animation-fill-mode: forwards;
  animation-delay: .45s;
}


@keyframes slideup {
0% {
}

25% {
}

30% {
  transform: translateY(-2em);
  animation-fill-mode: forwards;
}

100% {
  transform: translateY(-2em);
  animation-fill-mode: forwards;
}
}

  }

How do I import values ​from MongoDB into a Discord embed?

I have all the data I need in the mongoDB Database, I just dont know how I can send parts of the data in an Discord embed.
for example the data:

new birthdaySchema({
  User: username.username,
  Birthday: birthdayString, 
  Month: showMonth,
  Day: showDay, 
  Year: showYear

Year, Month and Day are just there to sort the birthdays and birthdayString = Day of Month

I also use moment-timezone (UTC)

const dateTime = moment.utc().format(`DD MM YYYY, hh:mm:ss`);

My goal is with a slash commad like /next-birthdays the data in the embed should look like

${birthdayString} ${Year}n${User} (and this 10 times, so the the upcoming birthdays of 10 users)

And if the birthday and the actual date and time from moment-timezones (UTC) is matching.
Then the Bot should make a new embed with a title (Happy Birthday) and in the description (Today is ${User}'s Birthday, blah blah blah) and at last it should give that User the birthday role on this server.

Hope someone can help me 🙂

Routing not working with deployed create-react-app on github pages with react-router v6

I’m trying to get routing to work with a create-react-app I’ve deployed to github pages. None of the routes I have set up work, I just get the 404 screen for everything else except the homepage. I’ve tried following many other tutorials but none of them seem up to date. I’m using react-router v6 and I’ve tried using BrowserRouter and HashRouter but neither approach seems to be working.

My site: https://grantsuu.github.io/pages-routing/

My router in App.tsx file:

<HashRouter>
    <nav>
        <Link to="/">Home</Link>
        <Link to="page">Page</Link>
        <Link to="page/nested1">Nested 1</Link>
        <Link to="page/nested2">Nested 2</Link>
    </nav>
    <Routes>
        <Route path="/" element={<div>Home</div>} />
        <Route path="page" element={<div>Page</div>} />
        <Route path="page/nested1" element={<div>Nested 1</div>} />
        <Route path="page/nested2" element={<div>Nested 2</div>} />
    </Routes>
</HashRouter>

Package.json:

{
  "name": "pages-routing",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.3.0",
    "@testing-library/user-event": "^13.5.0",
    "@types/jest": "^27.5.1",
    "@types/node": "^16.11.36",
    "@types/react": "^18.0.9",
    "@types/react-dom": "^18.0.5",
    "react": "^18.1.0",
    "react-dom": "^18.1.0",
    "react-router": "^6.3.0",
    "react-router-dom": "^6.3.0",
    "react-scripts": "5.0.1",
    "typescript": "^4.7.2",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "predeploy": "npm run build src",
    "deploy": "gh-pages -d build"
  },
  "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"
    ]
  },
  "devDependencies": {
    "gh-pages": "^4.0.0"
  }
}

How to create a structure in Python?

I have the following structure in JS:

let obj = {"NUM": {"0": 10, "1": 20}} 

Where:

"0"    :    10
position    number of repetitions

"NUM" is key.

I need to do the following:

obj["NUM"][0]++ 

It returns:

let obj = {"NUM": {"0": 11, "1": 20}}

Is it correct?

t = {}
t["NUM"] = {
    1: 3
}

t["NUM"][1] += 1
t["NUM"][2] = 0

print(t)

Drawing Graticule behind a map in d3.geo

I am using d3 to design a bubble map chart. I am struggling to add the graticule behind the map. It is drawing the graticule object but it is empty. Can someone please help me?

On the specific, the code I am using to draw the graticule is the following

// Map and projection
var projection = d3.geoGringortenQuincuncial()
   .center([0,20])                // GPS of location to zoom on
   .scale(150)                       // This is like the zoom
   .translate([ width/2, height/2 ])

      // Create and configure a path generator
  var pathGenerator = d3.geoPath()
    .projection(projection);

  // Create and configure the graticule generator (one line every 20 degrees)
  var graticule = d3.geoGraticule()
  //.step([1, 1]);


  // Graticule lines (behind the land)
  var lines = svgmap.selectAll('path.graticule').data([graticule()]);
      lines.enter().append('path').classed('graticule', true);
      lines.attr('d', pathGenerator);
      lines.exit().remove();

Google Sheets and Appscript doesn’t update the function properly

I have ImportJson() function that doesn’t update its value unless I make changes to Appscript then reload the sheet again, I think it was running but suddenly stopped.

The function should be get the value of 'A2' if found go to the loop, if not just return the fixed API call data, but whatever I update the A2 cell it doesn;t recall the function with the other kinds of the API call but it runs normally in the app script editor

  function ImportData1() {


  var Final_result = [];
  var VenueId_results = [];

  var PageNumber_index = 0;
  var Page_number = [0, 1, 2, 3, 4];
  var New_URL = "";

  var url = "https://app.ticketmaster.com/discovery/v2/events?sort=venueName,asc&locale=*&size=199&" + "page=" + Page_number[PageNumber_index] + "&apikey=" + API_key + "&venueId=" + venueIds;
  // ImportJSON(url, "/","noInherit,noTruncate,rawHeaders");
  // console.log(ImportJSON(url, "/", "noInherit,noTruncate,rawHeaders"));

  //  console.log("Veuneid" + Veunue_id + Venue_Id_List.length);
  console.log("ImportData1();" + Venue_Id_List.length);

  var New_Venue = SpreadsheetApp.getActiveSheet().getRange('A2').getValue();
  console.log(New_Venue);
  if ( New_Venue != "") {



    var Venue_arr = New_Venue.split(",");



    VenueId_results = Add_new_VeunueId(Venue_arr);

    var Last_New_Id_Venue = "";

    for (var Index_venune = 2; Index_venune < (VenueId_results.length) - 2; Index_venune++) {

      console.log("Venuesid " + VenueId_results[Index_venune]);
      var New_Id_Venue = VenueId_results[Index_venune].toString() + ",";

      Last_New_Id_Venue += New_Id_Venue;
      console.log("New_Id_Venue " + New_Id_Venue);

    }
    console.log("Last_New_Id_Venue " + Last_New_Id_Venue);

    New_URL = url + Last_New_Id_Venue;

    New_Venue = "";
    VenueId_results = [];

    // return ImportJSON(New_URL, "/_embedded/events/name,/_embedded/events/url,/_embedded/events/_embedded/venues/name,/_embedded/events/dates/start/localDate,/_embedded/events/dates/start/dateTime,/_embedded/events/priceRanges/min,/_embedded/events/priceRanges/max,/_embedded/events/_embedded/venues/url,/_embedded/events/_embedded/venues/city/name", "noInherit,noTruncate,rawHeaders");
    for (; PageNumber_index < Page_number.length; PageNumber_index++) {

      console.log("looopsyes");

      Final_result = Final_result.concat(ImportJSON(New_URL, "/_embedded/events/name,/_embedded/events/url,/_embedded/events/_embedded/venues/name,/_embedded/events/dates/start/localDate,/_embedded/events/dates/start/dateTime,/_embedded/events/priceRanges/min,/_embedded/events/priceRanges/max,/_embedded/events/_embedded/venues/url,/_embedded/events/_embedded/venues/city/name", "noInherit,noTruncate,rawHeaders"));
      console.log("New_URL " + PageNumber_index + Page_number[PageNumber_index] + Final_result);

      Utilities.sleep(1000);
    }

    console.log("New_URL " + New_URL);
    console.log("Final_result " + Final_result);
    return Final_result;
    console.log("New_URL " + Page_number);




    return Final_result;
    //  url += New_Venue;

    var New_URL = url + New_Venue;
    console.log("hello" + New_URL);


  } else {
    console.log("hellono");
    New_Venue = "";
    VenueId_results = [];
    return ImportJSON(url, "/_embedded/events/name,/_embedded/events/url,/_embedded/events/_embedded/venues/name,/_embedded/events/dates/start/localDate,/_embedded/events/dates/start/dateTime,/_embedded/events/priceRanges/min,/_embedded/events/priceRanges/max,/_embedded/events/_embedded/venues/url,/_embedded/events/_embedded/venues/city/name", "noInherit,noTruncate,rawHeaders");

  }


  // /_embedded/events/name,/_embedded/events/url,/_embedded/events/dates/start/localDate,/_embedded/events/dates/start/dateTime,/_embedded/events/priceRanges/min,/_embedded/events/priceRanges/max,/_embedded/events/_embedded/venues/name,/_embedded/events/_embedded/venues/url,/_embedded/events/_embedded/venues/city/name






  // setTimeout(import_data, 5000);



}

External JavaScript does not work as “module”

i have problem with javascript which i just can’t seem to know why…

so here is my code:

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <script type="module" src="./script.js"></script>
  </body>
</html>

right now, anything i write on my javascript file does not work.. but as soon as i remove the type=”module” from my script tag, it works just fine… i would very appreciate if someone can tell me what is going on.

Detect which element flex-wrap affects

Typing Game

I’m making a type test app where I have a caret line “|” moving from left to right.

This is what the rough build of my game looks like:

.words_wrapper {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  width: 400px;
}

.word {
  padding: 0.2rem;
}

.game{
  position: relative;
}
.caret {
  position: absolute;
  top: 0;
  height: 22px;
  width: 2px;
  background-color: red;
}
<div class="game">
  <div class="caret" style="left: 10px;"></div>
  <div class="words_wrapper">
    <div class="word">bob</div>
    <div class="word">about</div>
    <div class="word">us</div>
    <div class="word">know</div>
    <div class="word">computer</div>
    <div class="word">again</div>
    <div class="word">fails</div>
    <div class="word">running</div>
    <div class="word">bob</div>
    <div class="word">about</div>
    <div class="word">us</div>
    <div class="word">know</div>
    <div class="word">computer</div>
    <div class="word">again</div>
    <div class="word">fails</div>
    <div class="word">running</div>
  </div>
</div>

I have a state variable to adjust the left attribute

const [caretPos,setCaretPos] = useState();

Then I modify this position based on other factors when typing and apply it in the div style.

<div className='caret' style={{left: `${caretPos}px`}>

Now, my question is, How can I detect that my caret is at the end of the line and make it go to the next line

Notice that the div has a flex-wrap property so it automatically makes the words go to the next line. Is there a way to detect which word is at the end of the line or at the beginning of the line?

Cookies not saved on mobile

I’m using next middleware to do protected routes and I’m using cookies to do the checking since you can use cookies on the server-side.

When a user logged in, I save the info on local storage(for all my frontend auth checks) and a cookie set to true if logged in(for server-side checking).

The issue is that when im on mobile, and a user logs in, the info is saved successfully. But if the user closes the browser(like safari) then opens it again and goes to the site, the user is still logged in but the Cookie doesnt seem to work(or is no longer there) but the localstorage still is there. Then this causes a case where the user is logged in but they cant access the logged in(protected) routes.

The following is my login in function

    let loginUser = async (e) => {
        e.preventDefault();
        let response = await fetch(URL, {
            method:'POST',
            headers:{
                'Content-Type': 'application/json'
            },
            body:JSON.stringify({'email':e.target.email.value, 'password':e.target.password.value})
        })
        if(response.ok){
            let data = await response.json();
            setAuthTokens(data);
            localStorage.setItem("authTokens", JSON.stringify(data));
            Cookies.set("auth", "true");
            setUser(true);
            setFailed(false);
            router.push("/dashboard");
        } else {
            setFailed(true)
        }
    }

The following is my middleware

export default function middleware(req, event) {
    let verify = req.cookies['auth']
    const url = req.url

    if (url.includes("/login") || url.includes("/signup")) {
      if (verify) {
        return NextResponse.redirect("some_url/dashboard");
      }
    }

    if (url == "some_url" && verify) {
      return NextResponse.redirect("some_url/dashboard");
    }

    if(url.includes("/dashboard")){
        if(!verify){
            return NextResponse.redirect("some_url/login");
        }
    }
}