Webscraping data out of a table stored within different pages inside JS

**The Website: **
littlewargame.com/test

**Idea: **
Get the stats of the laddergames of my profile as csv.

**Problem: **
The data I get only shows the data of the first page. But I want the entirety of the games data.

Current halfworking Solution:

  1. Step: “Inspect” via Google Chrome to open devtools
  2. Paste Code into “Console”
  3. Change playerLadderResultsToCSV('DrEbs16') accordingly

Here is a video of how it currently works: https://drive.google.com/file/d/1JHiWIdBu6vydQ-iIN_VhjOoxMI4y2mQw/view?usp=sharing

The Code:

playerLadderResultsToCSV('DrEbs16');


function playerLadderResultsToCSV(playerNameToScrapeFor) {
  const playersWindowTextArea = document.getElementById('playersWindowTextArea')

  const player = Array.from(playersWindowTextArea.childNodes).find(childNode => {
    const playerName = childNode.querySelector('a.playerNameInList').innerText
    console.log('playerName', playerName);
    return playerName === playerNameToScrapeFor;
  });

  player.querySelector('a.playerNameInList').click();

  // wait 2 seconds
  setTimeout(() => {
    openLadderGamesProfile();
  }, 2000); // milliseconds to wait for profile to open (just to be safe)
}


function openLadderGamesProfile() {
  const ladderGamesBtn = Array.from(document.getElementById('riderDiv').childNodes).find(node => node.innerText === 'Laddergames')
  ladderGamesBtn.click();

  setTimeout(() => {
    const csvData = extractLadderGamesData();
    console.log(csvData)
  }, 2000); // milliseconds to wait for ladder contents to fill (just to be safe)
}


function extractLadderGamesData(trElem) {
  const trs = document.querySelectorAll('#addScrollableSubDivTextArea table tr')
  
  return Array.from(trs).map(trElem => {
    const tds = trElem.childNodes;
  
    const firstPlayer = tds[0].innerText.trim();
    const secondPlayer = tds[2].innerText.trim()
    const gameResult = tds[3].innerText.trim();
    const datePlayed = tds[4].innerText.trim();
    const mapName = tds[5].innerText.trim();
    let csvRow = `${firstPlayer},${secondPlayer},${gameResult},${datePlayed},${mapName}`;
    return csvRow;
  }).join('n').trim();
}

getting 500 internal server error for csrf token generation when url parameters has %40

For url if I want to create CSRF token it will give me 500 internal server error

https://abc/conf.tmpl?Email=ychandra-d%40dd.com&training=234

but if use @ instead of %40, csrf token will generate

https://abc/[email protected]&training=234

Can someone help me with this why changing in url pattern creates error? DO I need to added any other dependencies for special character?

Done some Implementation and add some file regarding csrf –

File added –

csrfguard.js

csrfguard.properties

Done some implementation-

In web.xml add csrfGuardServlet, Owasp.CsrfGuard.Config, Owasp.CsrfGuard.Config.Print, csrfGuardFilter(its filter-mapping), CsrfGuardServletContextListener,CsrfGuardHttpSessionListener

In apply.tmpl file added

<script src="https://weblibrary.cdn.getgo.com/web-library-2/scripts/web-library.js"></script>
    <script type="text/javascript" src="/public/csrfguard"></script>

as in web.xml file

<servlet-mapping>
        <servlet-name>csrfGuardServlet</servlet-name>
        <url-pattern>/public/csrfguard</url-pattern>
    </servlet-mapping>

I am developing a website using React Js and I want to know if user accessing it using AnyDesk, TeamViewer or any such platforms.How to achieve it?

I am developing a website for taking mock Interviews which contains questions which can be answered using typing or voice Recording. It is possible for users to answer the question by connecting through AnyDesk and other person will answer instead of the actual user.
I want to know if user is doing any such malpractices.

I tried all possibilities but couldn’t able to find the solution.

Export All Records, Ignoring Pagination

Currently I’m using Datatables with pagination. Now I recently added the Datatable.buttons library to use Export to Excel option. Now this functionality works fine but it only exports the first 10 rows of the page I’m currently in due to pagination. Now if I remove the limit in my model class, it will export all the entries which is what I want but it also gets rid of the pagination which decreases my site performance. The following is my current AJAX call code for getting Datatable data:

I’m excepting to download all the rows of data without pagination on excel button download , i tried using export option also but still downloading first page of data.

`

const table = new DataTable("#ajax-datatables-customers", {
                    processing: true,
                    serverSide: true,
                    dom: "Brt<'row'<'col-4 pt-2'l><'col-4 text-center'i><'col-4 text-center'p>>",
                    serverMethod: 'post',
                    buttons: [
                            {
                                extend: 'excel',
                                filename: 'hr_pivot_customers_' + new Date().toISOString().slice(0, 10),
                                exportOptions: {
                                    modifier: {
                                        page: 'all'
                                    },
                                    columns: [0, 1, 2, 3, 4]
                                }
                            },
                        ],
                   
                    ajax: {
                        url :'<?php echo $_SERVER['PHP_SELF']; ?>?datatables',                        
                    },
                    columns: [
                        { data: 'id'},
                        { data: null},
                        { data: 'email'},
                        { data: 'phone'},
                        { data: 'status'},
                        { data: 'status'}
                    ],
                     columnDefs : [
                    {
                        targets:1,
                        data: null,
                        
                        render: function (data, type, row) {
                            var firstname = row.firstname;
                            var lastname = row.lastname;
                            if (firstname && lastname) {
                                return firstname + ' ' + lastname;
                                } 
                            else if (firstname) {
                                return firstname;
                                } 
                            else if (lastname) {
                                return lastname;
                                } 
                            else {
                                return '';
                                }
                        }
                    },
 ],
                drawCallback : function( settings ) { }
                })

Can’t read properties in Ethers library

I try to connect from WSL to Ganache but somehow i get this error
TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider')

ChatGPT says it’s because you don’t correctyl add ethers library or wrong import

so that is my import code
const ethers = require("ethers"); i also try that one too
const { ethers } = require("ethers");

and there is my json

{
  "dependencies": {
    "ethers": "^6.9.2",
    "fs": "^0.0.1-security",
    "fs-extra": "11.2.0",
    "ganache": "^7.9.2",
    "solc": "^0.8.7-fixed"
  },
  "scripts": {
    "compile": "yarn solcjs --bin --abi --include-path node_modules/ --base-path . -o . SimpleStorage.sol"
  }
}

I try to add librarry but code can’t read it

Handling errors with vite dev server

When working with vite,
there an UI when code is incorrect and contains error.(see picture below)
vite error

Is there an api in vite to handle this modal and show in controlled manner ?
I would show my own modal for this error.

Thanks for your response

How to achieve wave effect in FabricJS text

I want to achieve a similar wave effect on fabric text objects. I don’t have any idea how I can achieve it.

<!DOCTYPE html>
<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/5.3.0/fabric.min.js"></script>
  </head>

  <body>
    <canvas id="canvas"></canvas>
    <script>
      var canvas = new fabric.Canvas("canvas");
      canvas.setWidth(900);
      canvas.setHeight(500);
      canvas.set({ backgroundColor: "#FFC0CC" });

      var text = new fabric.Textbox("Hello, Fabric.js!", {
        left: 50,
        top: 50,
        fontSize: 30,
        fill: "black",
      });

      canvas.add(text);

      canvas.renderAll();
    </script>
  </body>
</html>

Wave effect

How to log the test name to a log file for all tests in one place?

I tried the following:

  1. in support/index.js I added:

    beforeEach(() => {
      logEx('Executing: ' + Cypress.spec.name + ' - ' + Cypress.currentTest.title)
    });
    

    logEx is a utility I wrote which writes both to cypress log and to a log file.
    It works with no problems from each specific spec beforeEach().

  2. I added

    {
       "supportFile": "support/index.js"
    }
    

to cypress.env.json.

Still, it does nothing.

Validate two variables in Javascript function

I’m new to JavaScript and am trying to use it to validate a form before it is submitted. The first function, “validateYouTube” works and successfully checks if the YouTube code has been input, but the second function “validateSongandTitle” I am having issues with.

In order for the second function, validateSongandTitle, to be valid, I have the following condition:

  • If the user doesn’t select a song (as in they leave the drop-down as “No song selected”, they will need to then input a “title” for it to be valid.

Here’s what I have:

 <form action="add-video.php" method="post" onsubmit="return validateForm(event)" id="AddVid"> 
<select name="songid">
      <option value="">No song selected</option>
      <option value="1">Dr Jones</option>
      <option value="2">Spaceship</option>
      <option value="3">Fantasy</option>
</select>
<input type="text" id="ytcode" name="ytcode" />
<div id="formyoutubecode"></div>
<input type="text" name="title" size="50" />
<div id="formtitle"></div>
 
 <script>
 function validateForm(event) {
    event.preventDefault();
    var YouTubeValid = validateYouTube();
    var SongandTitleValid = validateSongandTitle();

    if (!YouTubeValid || !SongandTitleValid) {

        return;
    }

    event.target.submit();
}

function validateYouTube() {
    var a = document.forms["AddVid"]["ytcode"].value;
    if (a == null || a == "") {
        document.getElementById('formyoutubecode').innerHTML = "<small><font color='red'>YouTube Code Required</font></small>";
        return false;
    }

    return true;
}

function validateSongandTitle() {
    var b = document.forms["AddVid"]["songid"].value;
    var c = document.forms["AddVid"]["title"].value;
   if ((b == "No song selected" && c == "")) {
        document.getElementById('formtitle').innerHTML = "<small><font color='red'>Video title *Required</font></small>";
        return false;
    }

    return true;
}

 </script>

Please let me know why it won’t work? Thanks in advance.

Parallelize for in NodeJs

I’m a rookie of NodeJS/JS and I have a question about my code.

I’m writing a function to get elements from a DynamoDB table and my first version was this

Version 1

const params = {
  tableName: process.env.dynamoname
};
const result = await scanItems(params);
// Define conditions for getting free queues
let i = 0;
//
for (i; i < result.items.length; ++i) {
  const paramsCount = {
    tableName: process.env.dynamodt,
    data: {
      idTimeSlot: result.items[i].id
    },
    filterExpression: '#idTimeSlot = :idTimeSlot',
  };
  const res = await countItems(paramsCount);
  // Put available queues in items
  if (res.Count < result.items[i].maxQueueSize) {
    items.push(result.items[i].id);
  }
}
return items;

}
A very simple solution with an easy for loop, that got my results as expected

One of my colleague said to me to “Parallelize for loop”, so I have googled a lot and I have implemented this

Version 2

const params = {
   tableName: process.env.dynamoname
   };
  const result = await scanItems(params);
   // Define conditions for getting free queues

   const itemsPromises = result.items.map(async (item) => {
  const paramsCount = {
     tableName: process.env.dynamodt,
     data: {
      idTimeSlot: item.id
    },
    filterExpression: '#idTimeSlot = :idTimeSlot',
  };
  const res = await countItems(paramsCount);
  if (res.Count < item.maxQueueSize) {
     return item.id;
}
   return null;
});

 const items = await Promise.all(itemsPromises);
 return items.filter(id => id !== null);
 }

I have used Promise.all() to wait that all promises got with map() method are completed and return the elements with a filter condition. The results are the same of the first version, but I don’t understand properly the difference between the two versions.

So, my questions are:

  1. Is a good choice use Promise.all()? I can do better?
  2. Can you explain the difference between a simple sequentially for loop and the map method used in the Version2

I hope that my problems and questions are clear, thanks for the help!

Send JSON and file in array format with AJAX to a REST API [duplicate]

I have to make a call to an API with these characteristics:

This method is prepared to receive a multipart/form-data in which a part of the
content (the documents) comes in an array of bytes and another part (the buyer’s data and producer) comes in a JSON.

When calling the API I get error 400.

$.ajax({
  type: "POST",
  url: "https://integraob.es/wsregsaica/serweb/nuevato",
  headers: {
    "Authorization": "Bearer [TOKEN]"
  },
  data: {
    metadata: {
      "company_id": "A188",
      "producer_id": "230F"
    },
    files: {
      type: "file",
      path: "C:/Users/Agroc/Velneo/cacherun/127.0.0.1/1.pdf"
    }
  },
  responseType: "json",
  contentType: false,
  success: function(data, http_status) {
    alert(data);
  },
  error: function(data, http_status) {
    alert(http_status);
  }
})

Uncaught (in promise) Error: Target container is not a DOM element

I have a React app with below dependencies

"react": "~17.0.0",
"react-dom": "~17.0.0",

In my src/index.js, I have

import('./bootstrap');
export { };

In src/bootstrap.jsx, I have

import ReactDOM from 'react-dom';
import App from './components/App';

const container = document.getElementById('root');
const root = ReactDOM.render(container);

root.render(<App />);

In public/index.html, I already have a div with id “root” as below

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>

While build works and I am able to start the app, but I get the following error in the browser console.

**Uncaught (in promise) Error: Target container is not a DOM element.**

From what I read, it is mostly because of the DOM element missing in index.html, but in this case, I already have the DOM element with id=root

PS:
Actually, just as a side note, I have replaced this code from an upgraded project (on React v18), which has the code as below

import ReactDOM from 'react-dom';

const container = document.getElementById('root');
const root = ReactDOM.render(container);

root.render(<BootstrapApp />);

UPDATE

My public/index.html is as below

<!DOCTYPE html>
<html lang="en" class="dark">
<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <link rel="icon" type="image/png" href="%PUBLIC_URL%/logo64.png" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta http-equiv="cache-control" content="max-age=0" />
  <meta http-equiv="cache-control" content="no-cache" />
  <meta http-equiv="expires" content="0" />
  <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
  <meta http-equiv="pragma" content="no-cache" />
  <meta name="theme-color" content="#161616" />
  <meta
    name="description"
    content="my-host-ui"
  />
  <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
  <link rel="manifest" crossorigin="use-credentials" href="%PUBLIC_URL%/manifest.json" />
  <title>my-host-ui</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>

Dynamic Theme Toggle in Next.js App Using Ant Design v5

I am working on a Next.js application with Ant Design v5 and I’m trying to implement a dynamic theme toggle to switch between light and dark modes. I’ve encountered a issue: the theme settings work correctly on initial load, but subsequent changes to the isDarkMode state don’t seem to have any effect. Here’s the updated part of my code in the layout.tsx file:

"use client";

import React, { useState } from "react";
import { ConfigProvider, Layout, theme as antdTheme, Switch } from "antd";
import { Content } from "antd/es/layout/layout";
import { BulbFilled, CloudFilled } from "@ant-design/icons";

const PublicLayout = ({ children }) => {
  const { defaultAlgorithm, darkAlgorithm } = antdTheme;
  const [isDarkMode, setIsDarkMode] = useState(false);

  const handleClick = (checked) => {
    setIsDarkMode(prevValue => !prevValue);
  };

  return (
    <ConfigProvider
      theme={{
        algorithm: isDarkMode ? darkAlgorithm : defaultAlgorithm,
      }}
    >
      <Layout>
        <StyledHeader>
          <Switch
            checkedChildren={<BulbFilled />}
            unCheckedChildren={<CloudFilled />}
            onChange={handleClick}
          />
        </StyledHeader>
        <Content>{children}</Content>
      </Layout>
    </ConfigProvider>
  );
};

export default PublicLayout;

Initially, the theme is set based on the isDarkMode state, but when I toggle the switch, although the isDarkMode state changes (as I verified through console logs), the theme does not update as expected. I suspect the issue might be related to SSR and how I’m applying the theme in ConfigProvider, or maybe something else is missing in my approach to state management and theme application.

Has anyone faced a similar issue or can identify what I might be doing wrong? Any insights or suggestions to fix this issue would be immensely helpful!