Im trying to create a webapp that utilize dictionary api + also save the data to a database after onsubmit, I’m having issues being able to do that

I’m trying to create a web app that utilizes dictionary API + also saves the data to a database using MySQL after submitting using javascript, I’m having issues displaying the result while asynchronously post to the datable I’ve created multiple methods options and I’m still having issues

METHOD 1 

<html>
<head>
    <title>Webapp</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <DOCTYPE html>




        <script>
            function getWord() {
                var word = document.getElementById("word").value;
                var url = "https://api.dictionaryapi.dev/api/v2/entries/en/" + word;
                var xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function() {
                    if (this.readyState == 4 && this.status == 200) {
                        var response = JSON.parse(this.responseText);
                        var output = "";
                        for (var i = 0; i < response.length; i++) {
                            output += "<h2>" + response[i].word + "</h2>";

                            output += "<p>" + response[i].phonetics[0].text + "</p>";

                            output += "<p>" + response[i].meanings[0].definitions[0].definition + "</p>";
                            output += "<p>" + response[i].meanings[0].definitions[0].example + "</p>";
                        }


                        document.getElementById("result").innerHTML = output;

                    }

        $output = $_POST['output'];
        $sql = "INSERT INTO `words` (`word`) VALUES ('$output')";

        if ($conn->query($sql) === TRUE) {
            echo "New record created successfully";
        } else {
            echo "Error: " . $sql . "<br>" . $conn->error;
        }


    $.ajax({
        url: "post.php" + word,
        type: "GET",
        headers: {
            "Accept": "application/json",
            "Webapp.html": "",
            "word": ""
        },
        success: function (response) {
            var output = "";
            for (var i in response.results) {
                output += "<h2>" + response.results[i].word + "</h2>";

                output += "<p>" + response.results[i].lexicalEntries[0].pronunciations[0].phoneticSpelling + "</p>";

                output += "<p>" + response.results[i].lexicalEntries[0].entries[0].senses[0].definitions[0] + "</p>";
                output += "<p>" + response.results[i].lexicalEntries[0].entries[0].senses[0].examples[0].text + "</p>";
            }


            document.getElementById("result").innerHTML = output;

        }
    });



                };

                xhttp.open("GET", url, true);
                xhttp.send();
            }
            function submitWordToDatabase() {
                var word = document.getElementById("word").value;
                var xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function() {
                    if (this.readyState == 4 && this.status == 200) {
                        document.getElementById("word").innerHTML = this.responseText;
                    }
                };
                xhttp.open("POST", "post.php", true);
                xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xhttp.send("word="+word);
            }




        </script>


        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <h1>Dictionary API</h1>
                    <form>
                        <div class="form-group">
                            <label for="word">Word Finder</label>
                            <input type="text" class="form-control" id="word" placeholder="Enter word">
                        </div>
                        <button type="button" class="btn btn-primary" onclick="getWord()">Submit</button>






                    </form>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div id="result"></div>
                </div>
            </div>



METHOD 2
<html>
<head>
<title>Webapp</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<DOCTYPE html>




    <script>
        function getWord() {
            var word = document.getElementById("word").value;
            var url = "https://api.dictionaryapi.dev/api/v2/entries/en/" + word;
            var xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    var response = JSON.parse(this.responseText);
                    var output = "";
                    for (var i = 0; i < response.length; i++) {
                        output += "<h2>" + response[i].word + "</h2>";

                        output += "<p>" + response[i].phonetics[0].text + "</p>";

                        output += "<p>" + response[i].meanings[0].definitions[0].definition + "</p>";
                        output += "<p>" + response[i].meanings[0].definitions[0].example + "</p>";
                    }
                    document.getElementById("result").innerHTML = output;

                    var word = response[i].word;

                    var sql = "INSERT INTO words (word) VALUES ('" + word + "')";
                    connection.query(sql, function(err, result) {
                        if (err) throw err;
                        console.log("1 record inserted");
                    });
                }
            };

                    <?php
                    $word = $_POST['word'];
                    $meaning = $_POST['meaning'];
                    $example = $_POST['example'];
                    $file = fopen("word.txt", "w");
                    fwrite($file, $word);
                    fwrite($file, $meaning);
                    fwrite($file, $example);
                    fclose($file);
                    ?>
                }
            };




                }
            };
            xhttp.open("GET", url, true);
            xhttp.send();
        </script>
        }
   =


    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <h1>Dictionary API</h1>
                <form>
                    <div class="form-group">
                        <label for="word">Word Finder</label>
                        <input type="text" class="form-control" id="word" placeholder="Enter word">
                    </div>
                    <button type="button" class="btn btn-primary" onclick="getWord()">Submit</button>
                </form>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div id="result"></div>
            </div>
        </div>







<?php
function OpenCon()
 {
 $dbhost = "localhost";
 $dbuser = "root";
 $dbpass = "root";
 $db = "Webapp.html";
 $conn = new mysqli($dbhost, $dbuser, $dbpass,$db) or die("Connect failed: %sn". $conn -> error);

 return $conn;
 }

function CloseCon($conn)
 {
 $conn -> close();
 }

?>
CREATE TABLE IF NOT EXISTS `Webapp.html`.`users` (
 `id` INT NOT NULL AUTO_INCREMENT,
`word` VARCHAR(45) NULL,
 PRIMARY KEY (`id`))
ENGINE = InnoDB;

I understand I need to have a text file open if I’d like to be able to write on the file, but I want to be able to still submit to the file please… help I don’t know if I can add two functions after the submission of the file, which would display to the console and post to my database

How to parse images posted by user in google reviews?

I am working on a scraping project to scrape google maps reviews, but I got struck when I have to parse images posted by users. I tried this method which only gives me the first image posted by user :

    $('.gws-localreviews__google-review').each((i,el) => {
    images[i] = $(el)
    .find(".EDblX .JrO5Xe").attr("style")
    })

I am scraping google reviews by this URL: https://www.google.com/async/reviewDialog?hl=en&async=feature_id:0x47e66e2964e34e2d:0x8ddca9ee380ef7e0,next_page_token:,sort_by:,start_index:,associated_topic:,_fmt:pc

Here is my response:

[
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipPgClEw3JwTLJOuf-DqC2xtZRodoavkpYVFBYqu=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipOs9TSNoyYmW1GL4SH9PlkAihvWsUbMTn-8O2Sj=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipMBRGdJb3zL1rME20osajG-bosdIV8U82VTYS1n=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipOBuGDXFDhJP69LNo6yI9cZWcjSVHpVfPBNoKyL=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipP7wBZt8Kilm8VF75T8amjMrZ7ZkOpmtb0nHChF=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipOixJabuSd4mSHnveU5JSQ1ZszHJ6Hn-pkeosiY=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipPyOXO1vnyTXVnlkPJNLlnoHYHEna36vYnrqwE=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipPReBboes7S7lNklRT21pwn096JUQVJbTX3VRRA=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipNPLvARJu1vDk03r_y4fp8f7aDDvzRX-7yJklW8=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipMW3jp20hjKwuvhogH9ZC8IeH8QhQTUESH_ycNX=w100-h100-p-n-k-no)'

]

But what I want an object containing one user images, then a second a object containing a second user images and so on.

Leaflet Map is not showing in browser when I am not passing Markers file as a components

Hii all, When I use leaflet marker file as a components it is displaying the map correctly but when I use directly in the main app.js file then it is showing nothing :

Here is my App.js file when I am not passing marker component :

import React from "react";
import { MapContainer, TileLayer } from "react-leaflet";
import AddMarkers from "./AddMarkers";
import  { useState } from "react";
import { Marker, Popup, useMapEvents } from "react-leaflet";
import StarIcon from '@mui/icons-material/Star';
import Rating from '@mui/material/Rating';
import * as L from "leaflet";
import "./app.css"


const App = () => {
  
  const LeafIcon = L.Icon.extend({
    options: {}
  });
  const blueIcon = new LeafIcon({
    iconUrl:
      "https://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|abcdef&chf=a,s,ee00FFFF"
  }),
  greenIcon = new LeafIcon({
    iconUrl:
      "https://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|2ecc71&chf=a,s,ee00FFFF"
  });
  const [icon, setIcon] = useState(greenIcon);

  const changeIconColor = (icon) => {
    if (icon.options.iconUrl === greenIcon.options.iconUrl) {
      setIcon((current) => (current = blueIcon));
    } else {
      setIcon((current) => (current = greenIcon));
    }
  };

  const [markers, setMarkers] = useState([
    {
      lat: 40,
      lng: -95.6268544
    }
  ]);
 
  const map = useMapEvents({
    click: (e) => {
      setMarkers([...markers, e.latlng]);
    }
  });
  return (
    <MapContainer
   style={{ height: '100vh', width: '100wh' }}
      doubleClickZoom={false}
      id="mapId"
      zoom={6}
      center={{
        lat: 28.6139,
        lng: 77.2090
      }}>

      <TileLayer
     
       attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
      url="https://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png"/>
      
     
      {markers.map((marker, i) => (
        <>
        <Marker key={`marker-${i}`} position={marker} icon={icon}
        >
         
          <Popup>
            
            <div className="card">
                  <label>Place</label>
                 <div className="place">title</div>
                  <label>Review</label>
                 <div className="desc">dwhyfvqwdhfvqwhdfvwqhfvwhd </div> 
                 <label>Rating</label>
                  <div >
                  <StarIcon className = "stars"/>
                  <StarIcon className = "stars"/>
                  <StarIcon className = "stars"/>
                  <StarIcon className = "stars"/>
                  <StarIcon className = "stars"/>
                </div>
                  <label>Information</label>
                 <div> <span className="username">
                    Created by <b>username</b>
                  </span> </div><div>
                  <span className="date">04-06-2022</span>
                  </div>
                </div>
            
          </Popup>
        </Marker>
        </>
      ))}
     
 

    </MapContainer>
  );
};

export default App;

And Here is my two files which is displaying the map correctly :

App.js (with marker components) :

import React from "react";
import { MapContainer, TileLayer } from "react-leaflet";
import AddMarkers from "./AddMarkers";

const App = () => {
  
  return (
    <MapContainer
   style={{ height: '100vh', width: '100wh' }}
      doubleClickZoom={false}
      id="mapId"
      zoom={6}
      center={{
        lat: 28.6139,
        lng: 77.2090
      }}>

      <TileLayer
     
       attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
      url="https://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png"/>
      
      <AddMarkers />
    </MapContainer>
  );
};

export default App;

And here is my AddMarker.js file :

import React, { useState } from "react";
import { Marker, Popup, useMapEvents } from "react-leaflet";
import StarIcon from '@mui/icons-material/Star';
import Rating from '@mui/material/Rating';
import * as L from "leaflet";
import "./app.css"
import axios from 'axios'; 

const AddMarkers = () => {
 

  const LeafIcon = L.Icon.extend({
    options: {}
  });
  const blueIcon = new LeafIcon({
    iconUrl:
      "https://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|abcdef&chf=a,s,ee00FFFF"
  }),
  greenIcon = new LeafIcon({
    iconUrl:
      "https://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|2ecc71&chf=a,s,ee00FFFF"
  });
  const [icon, setIcon] = useState(greenIcon);

  const changeIconColor = (icon) => {
    if (icon.options.iconUrl === greenIcon.options.iconUrl) {
      setIcon((current) => (current = blueIcon));
    } else {
      setIcon((current) => (current = greenIcon));
    }
  };

  const [markers, setMarkers] = useState([
    {
      lat: 40,
      lng: -95.6268544
    }
  ]);
 
  const map = useMapEvents({
    click: (e) => {
      setMarkers([...markers, e.latlng]);
    }
  });
  return (
    <>
      {markers.map((marker, i) => (
        <Marker key={`marker-${i}`} position={marker} icon={icon}
        >
         
          <Popup>
            
            <div className="card">
                  <label>Place</label>
                 <div className="place">title</div>
                  <label>Review</label>
                 <div className="desc">dwhyfvqwdhfvqwhdfvwqhfvwhd </div> 
                 <label>Rating</label>
                  <div >
                  <StarIcon className = "stars"/>
                  <StarIcon className = "stars"/>
                  <StarIcon className = "stars"/>
                  <StarIcon className = "stars"/>
                  <StarIcon className = "stars"/>
                </div>
                  <label>Information</label>
                 <div> <span className="username">
                    Created by <b>username</b>
                  </span> </div><div>
                  <span className="date">04-06-2022</span>
                  </div>
                </div>
            
          </Popup>
        </Marker>
      ))}
     
    </>
  );
};

export default AddMarkers;

I wonder if anyone could help me with this.

React Material UI Drawer — Sliding Transition not working

I have written a drawer for my react app

const Sidebar = () => {
    return (
      <Drawer
        open={burgerModalOpen}
        onClose={() => setBurgerModalOpen(false)}
      >
        <Box>
          <Navigator />
        </Box>
      </Drawer>
    );
  };
const [burgerModalOpen, setBurgerModalOpen] = React.useState(false);
return (
      <>
        <MobileSideBarContainer>
          <BurgerIconContainer onClick={_handleOpenMobileBurger}>
            <div>
              <BurgerIcon />
            </div>
          </BurgerIconContainer>
          <Sidebar />
        </MobileSideBarContainer>
      </>
    );
  }

The drawer just ‘appears’ and ‘disappears’ … it’s not sliding in like it does here

How do I fix this?

How I can use map() to display array values once in a table?

thanks in advance for any patience to read my issue. I’m trying to get displayed some data in a table in the browser. For now I want to take my object and console.log it, so that later I can put in the table.
I have this object as a first test :

CedentePrestatore: "GEA 2 s.r.l."
CessionarioCommittente: "RENATO"
DataDoc: "2019-12-21"
Importo: "30.71"
TipoDoc: "TD01"

Starting from it, I’m trying to fill headers and rows like this, so in the frontend I can grab these data:

const data ={
  headers: ["TipoDoc.","DataDoc.","Importo","CedentePrestatore","CessionarioCommittente"],
  rows: new Array(10).fill(undefined).map((Array) => {
    return [
        tempDati
    ];
  })
};

app.get("/data",(req,res)=>{
    res.json({
        headers:data.headers,
        rows:data.rows
    });
});

What I got so far are headers and rows which got displayed 10 times as the array length (which at the end should be also the table lenght). I’m wondering what method() or different procedure I could use to make it displayed properly once, and then replicate the fill for each array I would get.. In the table every array should correspond to a row. Any idea?

The actual result console.log():

{"headers": 
["TipoDoc.","DataDoc.","Importo","CedentePrestatore","CessionarioCommittente"],"rows": 
[[{"TipoDoc":"TD01","DataDoc":"2019-12-21","Importo":"30.71","CedentePrestatore":"GEA 2 
 s.r.l.","CessionarioCommittente":"RENATO"}],[{"TipoDoc":"TD01","DataDoc":"2019-12- 
21","Importo":"30.71","CedentePrestatore":"GEA 2 
 s.r.l.","CessionarioCommittente":"RENATO"}],[{"TipoDoc":"TD01","DataDoc":"2019-12- 
21","Importo":"30.71","CedentePrestatore":"GEA 2 
 s.r.l.","CessionarioCommittente":"RENATO"}],[{"TipoDoc":"TD01","DataDoc":"2019-12- 
21","Importo":"30.71","CedentePrestatore":"GEA 2 
 s.r.l.","CessionarioCommittente":"RENATO"}],[{"TipoDoc":"TD01","DataDoc":"2019-12- 
21","Importo":"30.71","CedentePrestatore":"GEA 2 
 s.r.l.","CessionarioCommittente":"RENATO"}],[{"TipoDoc":"TD01","DataDoc":"2019-12- 
21","Importo":"30.71","CedentePrestatore":"GEA 2 
 s.r.l.","CessionarioCommittente":"RENATO"}],[{"TipoDoc":"TD01","DataDoc":"2019-12- 
21","Importo":"30.71","CedentePrestatore":"GEA 2 
 s.r.l.","CessionarioCommittente":"RENATO"}],[{"TipoDoc":"TD01","DataDoc":"2019-12- 
21","Importo":"30.71","CedentePrestatore":"GEA 2 
 s.r.l.","CessionarioCommittente":"RENATO"}],[{"TipoDoc":"TD01","DataDoc":"2019-12- 
21","Importo":"30.71","CedentePrestatore":"GEA 2 
 s.r.l.","CessionarioCommittente":"RENATO"}],[{"TipoDoc":"TD01","DataDoc":"2019-12- 
21","Importo":"30.71","CedentePrestatore":"GEA 2 
 s.r.l.","CessionarioCommittente":"RENATO"}]]}

Javascript Fundamentals array

What will be outputted to the console in this instance?
let val = 100;
let message = (val > 100) ? ${val} was greater than 100 :
${val} was LESS or Equal to 100;
console.log(message);
let check = (val % 2) ? Odd : Even;
check = ${val} is ${check};
console.log(check);

Pass value to an other compoment via routerLink in Ionic

I would like to pass value to another compoment ex: a name of country, and use it on the other compoment

I make the link like that and i want to send the value “France” to another compoment (via dataHere) :

  <ion-card-header>
    <ion-img class="logo-flag-greece" alt="mylogo" ></ion-img>
    <span routerLink="/tabs/result" dataHere="France" class="text">France</span>

  </ion-card-header>

How can i do that ?

path/:1 Uncaught SyntaxError: Unexpected string in the console of my website

This is my first time hosting a website, so im really sorry if my question shouldnt be asked here.

So I have been getting this error in my console of the website “Uncaught SyntaxError: Unexpected string” while trying to host it in addition to some other “TO MANY DIRECERIONS” error, which honestly confused me and I couldnt find an answer for the first error since everyone was getting them in their IDE, unlike me (In my website’s console). This is the way I imported my files.

enter image description here
enter image description here

Here is a picture of my website console and the error that I have been getting.

enter image description here
enter image description here

I also added a homepage script to my react applicaition in the json file but im not sure if it has anything to do with all that.

    "homepage": "http://omar-fares.com/",
    "eslintConfig": {
    "extends": [
      "react-app"
    ]

Thank you so much for the help.

Express mongodb find() return nothing but get 200

I want to return all data in MongoDB, it returns 200, but I cannot get all the data properly.

I am using Express

I am learning to use MongoDB and doing homework for practice. The task just told me to set up the API for MongoDB, they gave me an HTML with a button to test the API, and the HTML will show the API success or not, I cannot check on the HTML.

The task that I fail is told me to get all data from MongoDB.

Here is the task which I fail

GET /api/products .
Returns all products in the database as { products: Product[] }

I success to post data to MongoDB, when I use ‘app.get()’ to get all my data from MongoDB it fail, but I got 200 for the return, and I can see some data in the log.

That is the app.get() that I write

app.get('/api/products', (req, res, next) => {
    Product.find().then(
      (product) => {
        res.status(200).json({product});
      }
    ).catch(
      (error) => {
        res.status(404).json({
          error: error
        });
      }
    );
  }); 

How to have different text colour for 2 different imports of a custom component in React Native

I am having an issue changing the text colour on a few specific imports of a custom component.

I am able to change the border colour and background colour for the button itself depending on its use when I import it by changing the value of the props where it is used. However I cant work out how to do the same for the text. I imagine its something trivial but any help would be appreciated.

The code below is the code for the button.

import React from 'react';
import { StyleSheet, Text, TouchableOpacity } from 'react-native';
import colors from '../config/colors';


function AppButton({title, onPress, color = "primary", borderColor}) {
    return (
        <TouchableOpacity style={[
            styles.button, 
            {backgroundColor: colors[color], borderColor: colors[borderColor] }]} 
            onPress={onPress}
        >
            <Text style={[styles.text]}>{title}</Text>
        </TouchableOpacity>
    );
}

const styles = StyleSheet.create({
    button:{
        backgroundColor: colors.primary,
        borderRadius:15,
        padding: 15,
        width: "100%",
        marginVertical: 10,
        justifiedContent: 'center',
        alignItems: 'center',
        borderWidth: 6,
    },
    text:{
        color: colors.white,
        fontSize: 18,
        textTransform: 'uppercase',
        fontWeight: 'bold',
    }
})

export default AppButton;

mongodb query array of dates between start and end date

I want to fetch records that exists in provide dates array.

This array of dates will be matching start & end dates of a document.

Example:

I have this schema:

[
    {
        "_id": "1",
        "course": "Maths",
        "startDate": "2022-06-07",
        "endDate": "2022-06-12"
    },
    {
        "_id": "2",
        "course": "Chemistry",
        "startDate": "2022-06-06",
        "endDate": "2022-06-09"
    },
    {
        "_id": "3",
        "course": "Physics",
        "startDate": "2022-06-08",
        "endDate": "2022-06-10"
    },
    {
        "_id": "4",
        "course": "Computer Science",
        "startDate": "2022-06-10",
        "endDate": "2022-06-18"
    },
    {
        "_id": "5",
        "course": "Computer Science",
        "startDate": "2022-06-10",
        "endDate": "2022-06-13"
    },
    {
        "_id": "6",
        "course": "Biology",
        "startDate": "2022-06-08",
        "endDate": "2022-06-10"
    }
]

Provided array:

["2022-06-06", "2022-06-17"]

The expected response is:

[
    {
        "_id": "2",
        "course": "Chemistry",
        "startDate": "2022-06-06",
        "endDate": "2022-06-09"
    },
    {
        "_id": "4",
        "course": "Computer Science",
        "startDate": "2022-06-10",
        "endDate": "2022-06-18"
    }
]

Can anyone help me with the query? Thanks

the hover effect does not work when resizing the window, how to fix it?

I need all menu items to be defaulted when resizing a window. I achieved my goal, but if the menu item was active and we resized the screen, I can no longer activate the hover effect for it. For that menu item, it will only work again when the hover effect occurs on another menu item.

Is it possible to fix it?

this bug can be noticed if you use devTools by activating the device
simulation

github link: https://plupiks.github.io/photographer2/

codeopen link: https://codepen.io/plupiks/pen/xxYzvmj

function header() {
  const headerLink = document.querySelectorAll('.nav__link');
  const headerWrapper = document.querySelector('.header__nav');
  const checkboxLink = document.querySelectorAll('.nav__checkbox');

  $(window).on('load resize', function () {
    const desktopDevice = $(window).width() > 992 ? true : false;

    function onResize() {
      $(window).on('resize', function () {
        $(checkboxLink).prop('checked', false);
        if ($(checkboxLink).prop('checked') === false) {
          $(headerLink).css('width', '56px');
        }
      });
    }
    onResize();

    if (desktopDevice) {
      headerWrapper.style.display = 'block';

      for (let i = 0; i < headerLink.length; i++) {
        headerLink[i].addEventListener('mouseover', function () {
          const linkTextWidth = $(headerLink[i]).children('span').width() + 12;
          const headerLinkWidth = linkTextWidth + 20 + 36 + 'px';
          $(checkboxLink[i]).prop('checked', true);

          if ($(checkboxLink[i]).prop('checked') === true) {
            $(headerLink[i]).css('width', headerLinkWidth);
          }
          console.log('click');
        });

        headerLink[i].addEventListener('mouseout', function () {
          $(checkboxLink[i]).prop('checked', false);
          if ($(checkboxLink[i]).prop('checked') === false) {
            $(headerLink[i]).css('width', '56px');
          }
        });
      }
    } else {
      headerWrapper.style.display = 'none';
    }

    console.log(desktopDevice);
  });
}

header();
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

a {
  text-decoration: none;
  padding: 0;
  margin: 0;
}

a:active {
  text-decoration: none;
}

a:visited {
  text-decoration: none;
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

body {
  font: 400 16px 'Open Sans', sans-serif;
  color: var(--mainTextColor);
}

html,
body {
  height: 100%;
}

.container {
  max-width: 1180px;
  padding: 0 20px;
  margin: 0 auto;
}

.wrapper {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  min-height: 100%;
}

main {
  overflow: hidden;
  -webkit-box-flex: 1;
  -ms-flex: 1 1 auto;
  flex: 1 1 auto;
  background: antiquewhite;
}

.header {
  position: fixed;
  padding: 15px 0;
}

.header__body {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  height: 100vh;
}

.nav__list:not(:last-child) {
  margin-bottom: 8px;
}

.nav__checkbox {
  display: none;
}

.nav__list a {
  font: 400 15px 'Open Sans', sans-serif;
  position: relative;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  color: var(--mainColor);
  padding: 10px 18px;
  border-radius: 50px;
  overflow: hidden;
  width: 56px;
  height: 56px;
  background: var(--elemSecondaryColor);
  -webkit-transition: width 0.3s ease-in-out;
  -o-transition: width 0.3s ease-in-out;
  transition: width 0.3s ease-in-out;
}

.nav__list a svg {
  display: inline;
  width: 20px;
  height: 20px;
  stroke: black;
  pointer-events: none;
}

.nav__list a span {
  position: absolute;
  padding: 0px 5px 0px 27px;
  pointer-events: none;
  display: block;
  white-space: nowrap;
  opacity: 0;
  -webkit-transition: width 0.3s ease-in-out;
  -o-transition: width 0.3s ease-in-out;
  transition: width 0.3s ease-in-out;
}

.nav__checkbox:checked ~ a {
  background: var(--elemColor) !important;
  width: 100%;
}

.nav__checkbox:checked ~ a svg {
  stroke: var(--mainColorHover) !important;
}

.nav__checkbox:checked ~ a span {
  opacity: 1;
  color: var(--mainColorHover) !important;
}

.link-active {
  background: var(--elemColor) !important;
}

.link-active svg {
  stroke: var(--mainColorHover) !important;
}

.link-active span {
  opacity: 1;
  position: relative;
  color: var(--mainColorHover) !important;
}

.burger-menu {
  display: none;
  position: fixed;
  right: 0px;
}

.burger-menu__checkbox {
  display: none;
}

.burger-menu__icon {
  display: block;
  width: 40px;
  height: auto;
  cursor: pointer;
}

.burger-menu__icon .burger-menu__icon_line {
  background: var(--burgerMenuLines);
  position: relative;
  top: 0;
  height: 4px;
  margin-bottom: 6px;
  -webkit-transition: 0.3s ease all, 0.3s ease top, 0.3s ease width, 0.3s ease right;
  -o-transition: 0.3s ease all, 0.3s ease top, 0.3s ease width, 0.3s ease right;
  transition: 0.3s ease all, 0.3s ease top, 0.3s ease width, 0.3s ease right;
  border-radius: 5px;
}

.burger-menu__icon .burger-menu__icon_line:first-child {
  -webkit-transform-origin: 0;
  -ms-transform-origin: 0;
  transform-origin: 0;
}

.burger-menu__icon .burger-menu__icon_line:last-child {
  margin-bottom: 0;
}

.burger-menu__icon .burger-menu__icon_line:nth-child(2) {
  right: 0;
  width: 40px;
}

.burger-menu__checkbox:checked + .burger-menu__icon .burger-menu__icon_line:first-child {
  width: 36px;
  top: -4px;
  left: 6px;
  -webkit-transform: rotateZ(45deg);
  -ms-transform: rotate(45deg);
  transform: rotateZ(45deg);
}

.burger-menu__checkbox:checked + .burger-menu__icon .burger-menu__icon_line:last-child {
  opacity: 0;
  width: 23px;
  top: -4px;
  left: 15px;
  -webkit-transform: rotateZ(45deg);
  -ms-transform: rotate(45deg);
  transform: rotateZ(45deg);
}

.burger-menu__checkbox:checked + .burger-menu__icon .burger-menu__icon_line:nth-child(2) {
  width: 36px;
  top: -2px;
  right: 0px;
  -webkit-transform: rotateZ(-45deg);
  -ms-transform: rotate(-45deg);
  transform: rotateZ(-45deg);
}

.burger-menu__content {
  display: block;
}

@media only screen and (max-width: 992px) {
  .burger-menu {
    display: block;
  }
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;500;600;700&amp;display=swap">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Open+Sans:ital@1&amp;family=Poppins:wght@600&amp;family=Raleway:wght@400;700&amp;display=swap">
    <link rel="stylesheet" href="fonts/fontello-standart-icons/css/fontello.css">
    <link rel="stylesheet" href="fonts/fontello-header/css/fontello.css">
    <link rel="stylesheet" href="libs/aos/aos.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css">
    <link rel="stylesheet" href="css/style.css">
    <style>
      :root {
        --mainColor: #45505b;
        --mainColorHover: #fff;
        --secondaryColor: #272829;
      
        --elemColor: #0563bb;
        --elemSecondaryColor: #f2f3f5;
        --lineColor: #ddd;
      
        --burgerMenuLines: #fff;
      
        --AboutTitleColor: #728394;
      }
    </style>
    <title>Document</title>
  </head>
  <body>
    <div class="wrapper">
      <header class="header">
        <div class="container">
          <div class="header__body">
            <ul class="header__nav nav">
              <li class="nav__list">
                <input class="nav__checkbox" id="navCheckbox" type="checkbox"><a class="nav__link" href="#">
                  <svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg" stroke-width="3">
                    <path d="M28.5 13.0968V31H3.5V13.0968M1 15.0323L16 1L31 15.0323M21.5 30.0323V19.3871H10.5V30.0323" stroke-linecap="round" stroke-linejoin="round"></path>
                  </svg><span>Menu 1 Lorem ipsum dolor sit amet.</span></a>
              </li>
              <li class="nav__list">
                <input class="nav__checkbox" id="navCheckbox" type="checkbox"><a class="nav__link" href="#">
                  <svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg" stroke-width="3">
                    <path d="M2 31.0001C2 23.9656 7.53086 21.1725 10.2963 20.6553H21.7037C24.4691 21.1725 30 23.9656 30 31.0001"></path>
                    <path d="M23.2782 8.75862C23.2782 12.7663 20.021 16.0172 16.0004 16.0172C11.9799 16.0172 8.72266 12.7663 8.72266 8.75862C8.72266 4.75096 11.9799 1.5 16.0004 1.5C20.021 1.5 23.2782 4.75096 23.2782 8.75862Z"></path>
                  </svg><span>Menu 2 Lorem, ipsum dolor.</span></a>
              </li>
              <li class="nav__list">
                <input class="nav__checkbox" id="navCheckbox" type="checkbox"><a class="nav__link" href="#">
                  <svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg" stroke-width="3">
                    <path d="M18 1H4V31H28V11.6452M18 1L28 11.6452M18 1V11.6452H28" stroke-linejoin="round"></path>
                  </svg><span>Menu 3</span></a>
              </li>
              <li class="nav__list">
                <input class="nav__checkbox" id="navCheckbox" type="checkbox"><a class="nav__link" href="#">
                  <svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg" stroke-width="3">
                    <path d="M16 29.931H31V2H16M16 29.931H1V2H16M16 29.931V2" stroke-linecap="round" stroke-linejoin="round"></path>
                    <path d="M22 7.93115H26V9.93115H22V7.93115Z" stroke-width="1.5"></path>
                    <path d="M22 11.9312H26V13.9312H22V11.9312Z" stroke-width="1.5"></path>
                  </svg><span>Menu 4</span></a>
              </li>
              <li class="nav__list">
                <input class="nav__checkbox" id="navCheckbox" type="checkbox"><a class="nav__link" href="#">
                  <svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg" stroke-width="2.5">
                    <path d="M1 3V2.5C0.723858 2.5 0.5 2.72386 0.5 3H1ZM31 3H31.5C31.5 2.72386 31.2761 2.5 31 2.5V3ZM31 13.5V14C31.2761 14 31.5 13.7761 31.5 13.5H31ZM1 13.5H0.5C0.5 13.7761 0.723858 14 1 14V13.5ZM1 19V18.5C0.723858 18.5 0.5 18.7239 0.5 19H1ZM31 19H31.5C31.5 18.7239 31.2761 18.5 31 18.5V19ZM31 29.5V30C31.2761 30 31.5 29.7761 31.5 29.5H31ZM1 29.5H0.5C0.5 29.7761 0.723858 30 1 30V29.5ZM1 3.5H31V2.5H1V3.5ZM30.5 3V13.5H31.5V3H30.5ZM31 13H1V14H31V13ZM1.5 13.5V3H0.5V13.5H1.5ZM1 19.5H31V18.5H1V19.5ZM30.5 19V29.5H31.5V19H30.5ZM31 29H1V30H31V29ZM1.5 29.5V19H0.5V29.5H1.5Z"></path>
                    <path d="M19.5 7H22.5V9H19.5V7Z" stroke-width="1.5"></path>
                    <path d="M27.5 7H24.5V9H27.5V7Z" stroke-width="1.5"></path>
                    <path d="M22.5 23.5H19.5V25.5H22.5V23.5Z" stroke-width="1.5"></path>
                    <path d="M27.5 23.5H24.5V25.5H27.5V23.5Z" stroke-width="1.5"></path>
                  </svg><span>Menu 5</span></a>
              </li>
              <li class="nav__list">
                <input class="nav__checkbox" id="navCheckbox" type="checkbox"><a class="nav__link" href="#">
                  <svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg" stroke-width="3">
                    <path d="M1 7.65217V4H31V7.65217M1 7.65217V28H31V7.65217M1 7.65217L16 19.1304L31 7.65217" stroke-linejoin="round"></path>
                  </svg><span>Menu 6</span></a>
              </li>
            </ul>
            <div class="burger-menu">
              <div class="burger-menu__body">
                <div class="burger-menu__wrapper" id="menuToggle">
                  <input class="burger-menu__checkbox" id="checkbox" type="checkbox">
                  <div class="burger-menu__icon">
                    <div class="burger-menu__icon_line"></div>
                    <div class="burger-menu__icon_line"></div>
                    <div class="burger-menu__icon_line"></div>
                  </div>
                  <div class="burger-menu__content"></div>
                  <div class="burger-menu__background"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </header>
      <main class="main"></main>
      <footer class="footer"></footer>
    </div>
  </body>
  <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
  <script src="js/main.js"> </script>
</html>

How to check current page url in javascript?

I want to check if I am in certain domain, like this (in manifest.json for chrome extensions):

"content_scripts": [
{
  "matches": ["*://certain.site/*"],
  "js": ["some.js"]
}

But it seems like there are only dirty ways in javascript, like .split(“/”) which I don’t want to use.
Is there a clean way to do it?

How do i continuously rotate a photo using Javascript function

I’m trying to figure out logic to continuously rotate an image in Javascript. So far I have came up to this code. img1 is the id of the image and so far it works but it rotates only once. How do I make it rotate every time I click on it? Im using onclick event.

function rotateProfilePic() {
            var image = document.getElementById('img1');
            image.style.transform = "rotate(180deg)";
        } 

Sorry if the question is too simple for someone, I’m beginner in Web Programming.