how would i use dogpile images in discord.js?

i’m trying to make a discord bot that picks a random google result (from dogpile) and sends it but i cant seem to make it work

tried almost everything, but all the other code i found was old
heres the code that i used.
`client.on(“messageCreate”, (message) => {
if (message.mentions.has(client.user)) {

const image2 = message.content
var result = image2.substr(image2.indexOf(” “) + 1).replace(/s+/g, ‘-‘).toLowerCase()
console.log(‘http://results.dogpile.com/serp?qc=images&q=’ + result)
const image3 = ‘http://results.dogpile.com/serp?qc=images&q=’ + result

const exampleEmbed = new EmbedBuilder()
.setColor(0x0099FF)

.setTitle(‘See more’)
.setURL(image3)
.setThumbnail(image3)
.setImage(image3)
.setTimestamp()

message.channel.send({ embeds: [exampleEmbed] });

  }});

`

i want to make scroll in my aside without overflow because i have dropdown (translate to right )

my website height 100vh and i have an aside
in this aside i have list and every element in this list there is dropdown (dropright:when i hover in element dropdown translate from left to right )
image of my problem
problem is:
i need to make scroll for aside but when i make scroll with overflow , dropdown hide
i need to make scroll without overflow
any help guys!

i need to make scroll for aside but when i make scroll with overflow , dropdown hide

JS `scrollIntoView()` moves the entire container to the top and outside the viewport

This is my current styles:

  <style>
    html, body {
      height: 100vh;
      margin: 0;
      overflow: hidden;
    }

    body {
      display: flex;
      flex-direction: column;
    }

    #outlet {
      flex: 1;
      overflow-y: auto;
      scroll-behavior: smooth;
    }
  </style>

and HTML:

<body>
  <!-- This outlet div is where the views are rendered -->
  <div id="outlet"></div>
</body>

When I use the JS scrollIntoView() function on the very bottom element, in Google Chrome it moves the entire container (the outlet) to the top and pushes the top part outside the screen. It looks something like this:

enter image description here

Because this is the last element on the page, it moves the entire container (the outlet) to the top (and outside the viewport), even with its own scroll bar.

How to let the container know, to stay always in the visible browser part and don’t move outside it after scrollIntoView()?

After the scroll, I need something like this:

enter image description here

Graphql Hello World

I have two files index.js and index.html. index.js is the backend and index.html is the frontend and i am using graphql so that it will print hello world on a browser. Here are the files

const { graphql, buildSchema } = require('graphql');
const express = require('express');
const bodyParser = require('body-parser');

const app = express();

app.use(bodyParser.json());

const schema = buildSchema(`
    type Query {
      hello: String
    }
`);

const rootValue = {
    hello: () => {
        return "Hello World";
    }
};

app.use('/graphql', (req, res) => {
  graphql({
    schema,
    rootValue,
    source: req.body.query
  }).then(response => {
    res.json(response);
  });
});

app.use(express.static(__dirname));

const port = 3000;
app.listen(port, () => {
  console.log(`Server is running on http://localhost:${port}`);
});

<!DOCTYPE html>
<html>
<head>
  <title>Hello World</title>
</head>
<body>
  <div id="output"></div>

  <script>
    // Fetch the GraphQL query from the server
    fetch('/graphql', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ query: '{ hello }' })
    })
    .then(response => response.json())
    .then(data => {
      const outputElement = document.getElementById('output');
      outputElement.innerText = data.data.hello;
    })
    .catch(error => console.error(error));
  </script>
</body>
</html>

I am getting this error, [2023-06-09T19:36:05.916Z] “GET /” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36”
(node:63793) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
(Use node --trace-deprecation ... to show where the warning was created)
[2023-06-09T19:36:05.944Z] “POST /graphql” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36”
[2023-06-09T19:36:05.945Z] “POST /graphql” Error (404): “Not found”

How do I solve this, I am trying to print “Hello World” on the the localhost but it just shows a blank page

I ran node index.js and then npx http-server and opened the localhost link and it shows a blank page with that error

How to pass information from php to javascript using $.ajax and JSON?

I have this PHP code:

//This is to retrieve all the posts inside the database, which will then be displayed using Javascript.
    function retrieve_post($connection) {
        $sql2 = "SELECT * FROM tbl_user_posts";
        $result = mysqli_query($connection, $sql2);
        echo json_encode($result);
        //$data = array();
        //while ($row = mysqli_fetch_assoc($result)) {
        //    $data[] = $row;
        //    echo json_encode($data);
        //}
    }

which is used to retrieve information from a database with 3 columns, and I need to retrieve the information from these rows and display them onto a html page using javascript. Here is the javascript I tried:

function displayPosts(){
  $.ajax({
    type: "POST",
    url: "Main_Page.php",
    success: function(response) {
      JSON.stringify(response);
      var data = JSON.parse(response);
      for (var i = 0; i < data.length; i++) {
        var row = data[i];
        var name = row.name;
        var user_post = row.user_post;
        console.log(name, user_post);
      }
    }
  });
}

$(document).ready(function() {
  displayPosts();
});

However i get this error message in the console:

Unexpected end of JSON input
at JSON.parse ()
at Object.success (Main_Page.js:77:23)

with (Main_Page.js:77:23) being var data = JSON.parse(response).

Here is the HTML code that has all of the neccessary information inside of it for the form and where the information will need to go into (though right now my main priority is to display anything at all and will worry about the formating later):

<div class="user-post">
    Create post:<br>
    <form id="form" method="POST">
        <textarea id = "create_post" name="create_post" rows="10" cols = "50"></textarea>
        <input type="submit" class="post-button" value="PostButton" onclick = submit_post()>
    </form>
</div>
<div class="posts" id="posted">
    <div class="post">
        <h3 id="existing_posts"><img src="default-pic.png" class="profile-pic" alt="Default Picture" width="50" height="50">Posts</h3>
        <p>This is an example of a post. It will need to be boxed and made so that the name of the user goes above
            the name of the likes and dislikes of the posts are to the left of the post and that the reply and report
            functionalities are at the bottom right of the posts. It will also need a box around it to show where the post starts and ends.</p>
        <div class="options">
            <a href="">Like</a>
            <a href="">Comment</a>
            <a href="" class="report">Report</a>
        </div>
    </div>

WIX JSON Payload mapping/input into text input element

I’m working on an integration between Wix and PipeDrive API. My GET requests are successful and returning a payload – but I am trying to figure out how to process that payload and insert fields from the payload into a wix text input element.

Can anyone provide me an example of how to process data from the payload and insert it into a text input?

Below is an example of the payload I am getting in response:

Response Body

Here is an example of my backend code:
Backend Code

Here is an example of my successful GET code:
GET request page code

React: Issue with message item for chat UI

I’m working on a reac-native chat app, I want to add a samll image of the user to the left of each message, the image will appear only if:

  1. The previous message belongs to my user
  2. If the user sent multiple messages in a row, the image will only appear on the last received one.

To better understand what I’m trying to do check this image (look at the column on the left, the little image with user default image)

https://i.imgur.com/CaKltON.jpg

Each message object has a user_id value which is the id of the user that sent the message
I store messages in root.mapStore.activeChatMessages mobx value and pass each message and index as a prop to MessageCard

FlatList component

<FlatList 
            vertical={true} 
            data={root.mapStore.activeChatMessages} keyExtractor={item => item.provisionalId.toString()}
            renderItem={({ item, index }) => 
            <MessageCard1 item={item} index={index}></MessageCard1>
            
            }
            />

MessageCard

export default MessageCard= observer((props) => 
{
    
    const { item, index } = props;

    const showUserImage = () =>
    {
        //Put logic here
    };

    return (
    <View style={{ width:'60% , flexDirection:'row',alignItems:'center }}>
        { showUserImage() && (
            <Image></Image>
        )}
        <Text>{ item.messageBody }</Text>
    </View>

);

});
    

How to make a conditional based of span text?

I have my span like this:

<span class="lunch" id="foods"> My fruits </span>

And another span like this:

<span class="lunch" id="food"> apple </span>

How can I make it so when the “My fruits” text on the first span changes to for example, “My sweets”(this change occurs by changing the content on the same tab), the text on the other span changes from apple to “chocolate bar” or something like that?

I´ve tried this:

<script type="text/javascript">
 if(document.getElementById("foods").value=="My sweets")
 document.getELementById("food").textContent="chocolate";
</script>

But nothing happens.

Each span is inside a respective div with it’s respective id

Sorry for the stupid example but I don´t know how to explain it better right now. Does someone know how I could make this change?

Convert the script code to apply to Sheet1 only instead of all

Can someone please give me a hand?

I have the following two scripts that work properly, but they apply to all sheets. I need to apply them only to Sheet1 and I can’t do it.

SCRIPT ONE

function conditionalFormatting1() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = ss.getSheets();
  sheets.forEach(sheet => {
    sheet.clearConditionalFormatRules();
    //sheet.clearFormats();
    sheet.getRange('A3:P').clearFormat()
    sheet.getRange('A3:P').setHorizontalAlignment("left")
    var rules = [];
    rules.push(createRule(sheet, "$A$1:P1", "=$A1>0", "#86aba5"));
    rules.push(createRule(sheet, "$A$2:A2", "=$A2>0", "#76dffb"));
    rules.push(createRule(sheet, "$B$2:J2", "=$B2>0", "#e0ffff"));
    sheet.setConditionalFormatRules(rules);
  });
}

function createRule(sheet, rangeNotation, formula, color) {
  var range = sheet.getRange(rangeNotation);
  var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenFormulaSatisfied(formula)
    .setBackground(color)
    .setRanges([range])
    .build();
  return rule;
}

SCRIPT TWO

function headersTable1() {
  var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
  sheets.forEach(function (sheet) {
  sheet.setFrozenRows(2);
  var values = [
    ["Completed Date", "ID", "Last Name", "First Name", "Phone", "Personal Email"]
  ];
  var range = sheet.getRange("A2:F2");
  range.setValues(values);
  })
}

In advance, thanks so much.

I have tried the following but the code stops and gives error:

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");

Why does Mapbox GL’s draw_create function fire multiple times under different closures while creating a `LineString?

I am using mapbox-gl-draw in a React.js app to facilitate path creation on a Mapbox canvas. Since I’m in React, I have to declare the draw.create event handler within a useEffect() block. Since my draw.create handler depends on a state variable, I declare the variable in the dependency list at the end of the useEffect() block. Here is the essence of the useEffect() block, with two debugging statements added to try to understand the behavior:

useEffect(() => {
    console.dir("In useEffect to initialize draw_create...");
    /* POINT 1 */
    if (defineFeature === null) {
      console.dir("defineFeature is null");
    } else {
      console.dir("Value of defineFeature: " + defineFeature.holeNum + ", " + 
      defineFeature.featureType);
    }
           
      map.current.on('draw.create', ()=> {
        /* POINT 2 */
        if (defineFeature === null) {
          console.dir("defineFeature is null");
        } else {
          console.dir("Value of defineFeature: " + defineFeature.holeNum + ", " + 
          defineFeature.featureType);
        }
        /* Code to process the line is omitted */
  },[defineFeature]); 

When I execute this code, the value of defineFeature is as expected at POINT 1; it is the most recent value of defineFeature. However, the value of defineFeature at POINT 2, within draw_create, is a different matter. After a user double-clicks to terminate a line_string on the map canvas, the draw.create handler is fired multiple times under different closures! The first time draw.createfires, defineFeature is null, which is its value when the map first initializes. The last time draw.create fires, the value of defineFeature is correct. However, at that point, it’s too late; the function has already tried to process the line with an incorrect (stale) value of defineFeature.

The number of times that draw.create fires when the user double-clicks to terminate a LineString is not predictable. From what I can gather, it seems to depend on the number of previous closures of draw.create. Indeed, the value of defineFeature in each invocation seems to be different, aligning with its previous values.

Can anyone explain this behavior–and, more importantly, how to fix it? In draw.create, I need to be able to use the value of defineFeature under the most recent closure.

Why is my function returning undefined if the variable in the console log has a value? [duplicate]

My function is returning undefined even a console log of the variable i am returning has a value I can’t figure out why.

here is my code

function pencilSolution(puzzleString) {
  let newArr = pencilArr(puzzleString)
  let nakedSolution = solveNaked(newArr, puzzleString)
  let hiddenSolution = hiddenSolve(newArr, nakedSolution)

  let newArr2 = pencilArr(hiddenSolution)
  if (hiddenSolution == puzzleString) {
    console.log(hiddenSolution + ' hidden')

    return hiddenSolution
  }
  let puzzleStringCompare = hiddenSolution

  pencilSolution(hiddenSolution)

}

let pencilFinal = pencilSolution(puzzleString)
console.log(pencilFinal + 'final')

here is my console

"..526......1.3.6....847..9.8..62...9..9.4.5..1...93..2.7..148...84.5.3......869.. hidden"
"undefinedfinal"

my form is subbmitted to the server side even though my java checks return false I need them to be stopped before getting to the server side (asp.net)

I made sure the java page was properly connected and that the form had a onsubmit(return CheckRegister())
and yet I can still register with false input and I do get error messages from my java script to the page using innerHTML so I know it works but it still sends the form
here is my java code:

window.addEventListener('DOMContentLoaded', function () {
  var form = document.getElementById('registerForm');
  form.addEventListener('submit', function (event) {
    if (!checkRegister()) {
      event.preventDefault();
    }
  });
});


function checkBirthday() {
  //code here
}

function checkName() { 
//code here

}

function checkPassword1() {
  //code here
}

function checkPassword2() {
  //code here
}

function checkMail() {
  //code here
}

function validateEmail(email) {
  //code here
}

function checkRadio() {
 //code here
 
 
}

function checkCheckBox() {
 //code here
}

function checkSelect() {
 //code here
}

function checkRegister() {
    if (!checkName() || !checkPassword1() || !checkPassword2() || !checkMail() || !checkBirthday() || !checkRadio() || !checkCheckBox() || !checkSelect()) {
        return false;
    }
    return true;
   
}

I left out the code inside each check as I know they are fully working
here is my html code:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="register.aspx.cs" Inherits="AvivPr5.register" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="js/register_JavaScript.js"></script>
    <link href="StyleSheet1.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="title">
        <h1>Register</h1>
    </div>
    <div class="box1">
        <center>
            <h2>Registration</h2>
            <form id="registerForm" onsubmit="return checkRegister()">
                <div id="error" name="error">

                </div>
                <label>name:</label>
                <br />
                <input type="text" name="name" id="name" oninput="checkName()" />
                <div id="nameDiv"></div>
                <label>password:</label>
                <br />
                <input type="password" name="password1" id="password1" oninput="checkPassword1()" />
                <div id="password1Div"></div>
                <label>confirm password:</label>
                <br />
                <input type="password" name="password2" id="password2" oninput="checkPassword2()" />
                <div id="password2Div"></div>
                <label>email:</label>
                <br />
                <input type="text" name="mail" id="mail" oninput="checkMail()" />
                <div id="mailDiv"></div>
                <p>Choose one AI branch:</p>
                <br />
                <input type="radio" name="branch" value="Art" id="Art">
                <label>Art</label><br>
                <input type="radio" name="branch" value="Gaming" id="Gaming">
                <label>Gaming</label><br>
                <input type="radio" name="branch" value="Assistance" id="Assistance">
                <label>Assistance</label>
                <div id="radioDiv"></div>
                <p>What do you use?</p>
                <input type="checkbox" name="ChatGPT" value="ChatGPT" id="ChatGPT">
                <label>ChatGPT</label><br>
                <input type="checkbox" name="OpenArt" value="OpenArt" id="OpenArt">
                <label>OpenArt</label><br>
                <input type="checkbox" name="Siri" value="Siri" id="Siri">
                <label>Siri</label><br>
                <div id="checkBoxDiv"></div>
                <label>Birthday:</label>
                <input type="date" name="birthday" id="birthday" onchange="checkBirthday()">
                <div id="birthdayDiv"></div>
                <label>What do you think about the future of AI?</label>
                <select name="future" id="FutureHolds">
                    <option value="">-----</option>
                    <option value="Scary">Scary</option>
                    <option value="Interesting">Interesting</option>
                    <option value="Don't care">Don't care</option>
                    <option value="Bright">Bright</option>
                </select>
                <div id="selectDiv"></div>
                <br />
                <input type="reset" value="Delete" />
                <input type="submit" value="Send" />
            </form>
        </center>
    </div>
</asp:Content>

I tried including the onsubmit(return checkregister()) in the form and also adding the prevent default() in the even listener it all seems to be fine but it does not work no matter what I try. also
I fed the code to ChatGPT and other programs multiple times and they also found no error.
So if anyone has experienced the same thing or knows how to fix it please help me!!

Check innerHTML for a scraped table and modify variable based on that array entry

I am trying to check the table entry for a webscrape for the ‘color’ element in the innerhtml and then change the variable for “bonus” based on which of the table entries have this value.

I can post the innerHTML version and see it there but I can’t not seem to get the script to recognize it is there.

let checkCrimes = {
    "check": function() {
        if (user.stamina < 690) {
          let randomTimer = Math.floor(Math.random() * 300 + 900);
          checkCrimes.queue(randomTimer);
        } else if ($(gameDocument).find('#crimebubble').length) {
          let crimeCooldown = $(gameDocument).find("#crimebubble>.countdown").eq(0).text().split(":");
          crimeCooldown = crimeCooldown.map((x, i) => {
            if (i === 0) {
              return Number(x) * 60;
            } else {
              return Number(x);
            }
          });
          crimeCooldown = crimeCooldown.reduce((a, b) => a + b);
          checkCrimes.queue(crimeCooldown);
        } else if ($(gameDocument).find('#form_crimes').length) {
          let lastPostTime = localStorage.getItem('lastPostTime') || 0;
          if ($(gameDocument).find('#form_crimes input[type="radio"]').length > 10) {
            // Handle other cases or skip if necessary
          } else {
            let crimeList = [];
            $(gameDocument).find('#form_crimes tbody tr').each(function() {
              const crimeData = $(this).find('td').toArray().map(x => x.innerHTML);

              if (crimeData.includes('--')) {
                return; // Exclude entries with "--" from the list
              }
              const bonus = "testfailed";
              if (crime.Data[3].includes('color')) {
                bonus = "Stealth"
              }
              if (crime.Data[2].includes('color')) {
                bonus = "Defense"
              }
              if (crime.Data[1].includes('color')) {
                bonus = "Offense"
              }


              const trimmedCrimeData = [crimeData[1], crimeData[2], crimeData[3], crimeData[6], bonus];

              crimeList.push(trimmedCrimeData);

            });

I have also tried just checking the entire crimeData array for the entry just to check and it didn’t work either. But this is effectively what I want to do in this function: scrape the crime table, check which one has the bonus, push text only to the trimedCrimeData

here is the HTML I am working with if it helps

18%, 50%, <span style="color:#00B910;font-size:11px;">37%</span>, <span class="wartooltip" style="margin:0px;"><span style="color:lime;">strong</span><span class="wartooltiptext">Strength indicated how strong the crime is, strong is good and weak is bad!</span></span>, off
    66%, 9%, <span style="color:#00B910;font-size:11px;">30%</span>, <span class="wartooltip" style="margin:0px;"><span style="color:grey;">normal</span><span class="wartooltiptext">Strength indicated how strong the crime is, strong is good and weak is bad!</span></span>, off
    10%, 44%, <span style="color:#00B910;font-size:11px;">51%</span>, <span class="wartooltip" style="margin:0px;"><span style="color:lime;">strong</span><span class="wartooltiptext">Strength indicated how strong the crime is, strong is good and weak is bad!</span></span>, off

Svelte – hls.js : Changing the volume leads to frame drop

I am using and learning Svelte. So I am creating a video player with help of hls.js library (because I did not found any readymade video players which worked properly and had the functionality I wanted). When I try to change the volume of the video, frame drop occurs.

function handleVolume(event) {
    volume = event.target.value;
    if (volume === 0) { isMuted = true; }
   else { isMuted = false; }
}

function debounce(func, delay) {
    let timeoutId;
    return function (...args) {
        clearTimeout(timeoutId);
        timeoutId = setTimeout(() => {
            func.apply(this, args);
        }, delay);
    };
}

function updateVideoVolume() {
    video.volume = volume / maxVolume;
}

const updateVideoVolumeDebounced = debounce(updateVideoVolume, 200);

onMount(() => {
    if (Hls.isSupported()) {
        hls = new Hls();
        let src = 'http://localhost:3000/videos/video3';
        hls.loadSource(src);
        hls.attachMedia(video);
        hls.enableWorker = true;
        duration = video.duration;

        hls.on(Hls.Events.MEDIA_ATTACHED, function () {});
        hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
            console.log(data.levels);
            for (let i = 0; i < data.levels.length; i++) {
                resolutions = [...resolutions, [data.levels[i].height, data.levels[i].bitrate]];
            }
            console.log(resolutions);
        });
    }
});
</script>

<input
    type="range"
    on:input={handleVolume}
    on:change={updateVideoVolumeDebounced}
    id="volume"
    name="volume"
    min="0"
    max={maxVolume}
/>```


It happens with both on:change and on:input when using the range input element. I also tried to debounce the handleVolume but then the frame drop occurs after the delay. I have also tested it on different browsers. In Firefox, the frame drop is less. Meanwhile in Brave, it is similar. I guess this is because of Chromium. 

Giving format do date with javascrip

I’m using toLocaleDatestring to give format to my date. Te current function I’m using is the following:

var oDate = new Date().toLocaleDateString('en-US', { year: "numeric", day: "2-digit", month: "short"})

And it actualy works, it’s giving me “Jun 09, 2023” as result

My question is, is there any way to give to it a different format. I’m I want it like “Jun/09/2023”