Inserting an image in a table using HTML for a Chrome Extension on Manifest Version 3

My manifest is updated to allow all images in the web_accessible_resources

    {
    "name": "MH",
    "description": "Building an Extension!",
    "version": "2.0",
    "manifest_version": 3,
    "background": {
      "service_worker": "js/background.js"
    },
    "web_accessible_resources": [
      {
        "resources": ["*.html",
          "*.js",
          "*.css",
          "*.PNG",
          "*.png"],
        "matches": [ "<all_urls>" ]
      }
    ],
    "permissions": ["identity",
      "identity.email",
      "activeTab", 
      "scripting",
      "tabs"],
    "host_permissions": ["http://*/*", "https://*/*"],
    "content_scripts": [
      {
        "matches": ["*://*.google.com/*"],
        "js": ["js/xpaths.js"]
      }
    ]
  }

I then used the following code in my content script

        var act = `
        <table className = "usefullness">
          <tr>
            <th></th>
            <td style="text-align: right;font-size: 14px"><img src="happy.PNG"></img></td>
            ` + Usebar + `
          </tr>
        </table>
        <table className = "emotion">
          <tr>
            <th></th>
              ` + Emobar + `
          </tr>
        </table>
        <table className = "knowledge">
          <tr>
            <th></th>
              ` + Knowbar + `
          </tr>
        </table>`

        var Action = document.createElement("div");
        Action.innerHTML = act;
        finalDivs[i].appendChild(Action);

But the image does not show up. I even put the image files in the exact directory as the manifest file but it still does not load. Is there a size or permission requirement I am missing? Any help is very appreciated!

google sheet aps script custom function not working

This is matrix transpose function

function matrix_transpose(m){
  for(i=0;i<m.length;i++){
    for(j=0;j<i;j++){
      [m[i][j],m[j][i]] = [m[j][i],m[i][j]]
    }
  }
  return m
}

This is (stupid) matrix determinant function.

function matrix_determinant(m){
  if(!Array.isArray(m)) return m
  if(m.length==1) return m[0][0]
  if(m.length==2) return m[0][0] * m[1][1] - m[0][1] * m[1][0]
  if(m.length==3){
    ret = 0
    ret += m[0][0]*m[1][1]*m[2][2]
    ret += m[0][1]*m[1][2]*m[2][0]
    ret += m[0][2]*m[1][0]*m[2][1]
    ret -= m[0][0]*m[1][2]*m[2][1]
    ret -= m[0][1]*m[1][0]*m[2][2]
    ret -= m[0][2]*m[1][1]*m[2][0]
    return ret
  }
  if(m.length==4){
    ret = 0

    ret += m[0][0]*m[1][1]*m[2][2]*m[3][3]
    ret += m[0][2]*m[1][0]*m[2][1]*m[3][3]
    ret += m[0][1]*m[1][2]*m[2][0]*m[3][3]
    ret += m[0][1]*m[1][0]*m[2][3]*m[3][2]
    ret += m[0][0]*m[1][3]*m[2][1]*m[3][2]
    ret += m[0][3]*m[1][1]*m[2][0]*m[3][2]
    ret += m[0][0]*m[1][2]*m[2][3]*m[3][1]
    ret += m[0][3]*m[1][0]*m[2][2]*m[3][1]
    ret += m[0][2]*m[1][3]*m[2][0]*m[3][1]
    ret += m[0][2]*m[1][1]*m[2][3]*m[3][0]
    ret += m[0][1]*m[1][3]*m[2][2]*m[3][0]
    ret += m[0][3]*m[1][2]*m[2][1]*m[3][0]

    ret -= m[0][1]*m[1][0]*m[2][2]*m[3][3]
    ret -= m[0][0]*m[1][2]*m[2][1]*m[3][3]
    ret -= m[0][2]*m[1][1]*m[2][0]*m[3][3]
    ret -= m[0][0]*m[1][1]*m[2][3]*m[3][2]
    ret -= m[0][3]*m[1][0]*m[2][1]*m[3][2]
    ret -= m[0][1]*m[1][3]*m[2][0]*m[3][2]
    ret -= m[0][2]*m[1][0]*m[2][3]*m[3][1]
    ret -= m[0][0]*m[1][3]*m[2][2]*m[3][1]
    ret -= m[0][3]*m[1][2]*m[2][0]*m[3][1]
    ret -= m[0][1]*m[1][2]*m[2][3]*m[3][0]
    ret -= m[0][3]*m[1][1]*m[2][2]*m[3][0]
    ret -= m[0][2]*m[1][3]*m[2][1]*m[3][0]

    return ret
  }
}

This is sub matrix function.

function matrix_sub(m,r,c){
  ret = []
  for(i=0;i<m.length;i++){
    if(i==r) continue
    tmp = []
    for(j=0;j<m.length;j++){
      if(j==c) continue
      tmp.push(m[i][j])
    }
    ret.push(tmp)
  }
  return ret
}

This is matrix inverse function.

function matrix_inverse(m){
  if(!Array.isArray(m)) return 1/m
  if(m.length==1) return 1/m[0][0]
  a = matrix_determinant(m)
  ret = []
  for(i=0;i<m.length;i++){
    tmp = []
    for(j=0;j<m.length;j++){
      tmp.push(Math.pow(-1,i+j)*matrix_determinant(matrix_sub(m,i,j))/a)
    }
    ret.push(tmp)
  }
  return matrix_transpose(ret)
}

I tried to calculate matrix_inverse in the apps script. However, this didn’t work at all.(even the determinant code is stupid because recursion didn’t work..)
but when I tried these codes in the C++ framework, these worked well.
So I don’t understand the reason this doesn’t work especially in the googlesheet apps script framework.

Javascript return true if the data is equal to the data on database

how can I determine that the data is equal to the data in the database? and when they are equal

var valid = false;
var { startDate, assignedTo } = data
console.log(data)
var date = moment(startDate, 'DD/MM/YYYY hh:mm A').toDate()
var dd_startDate = ""
var assignes = ""
var dd_endDate = ""
APP_ENTRIES.map((res=>{
    assignes = res['assignee'];
    dd_startDate =  res['date'];
    dd_endDate = res['end'];
    const check = moment(date).isBetween(dd_startDate, dd_endDate)
    return valid = (assignedTo == assignes && !check)
}))
return valid;

the result of APP_ENTRIES

[
    {
        "date": "2022-04-12T00:32:00.000Z",
        "assignee": "441017201",
        "end": "2022-04-12T01:32:00.000Z",
    },
    {
        "date": "2022-04-14T00:23:00.000Z",
        "assignee": "441017201",
        "end": "2022-04-14T01:23:00.000Z",
    },
]

the result of var { startDate, assignedTo } = data
data

{
    "startDate": "12/04/2022 12:46 PM",
    "assignedTo": "441017201|441017210"
}

please dont read this comment please dont read this comment please
dont read this comment please dont read this comment please dont read
this comment please dont read this comment

Module.exports big object performance or overhead

I’m creating helpers for my mongoose (MongoDB) models.
I don’t know i should do exports.findById or module.exports is ok to go with, in terms of performance and overhead.

module.exports makes code cleaner but when i import the helper in another file i actually import all the methods at once not the ones i really need.

// user.helper.js
module.exports = {
    /**
     * Find user by id.
     * @param _id string
     * @returns Promise<User>
     */
    findById: (_id) => {
        return User.findById(_id).cache();
    },

    // many methods
};

React-Native Flatlist RenderItem doesn’t render

I don’t get any errors. I use flatlist in the home page of my code without any errors but it doesn’t render in the second page. It also doesn’t display console.log inside renderItem.

'const NamazTakibi = () => {

const [ayet, setAyet] = useState('');

const fetchAyet = async() => {
    try {
        const ayet = await axios.get('https://api.acikkuran.com/surah/6/verse/1?author=14');
        setAyet(ayet)
        
    }

    catch{
        console.log("error");
    }
}


useEffect(() => {
    fetchAyet();
},[]);


const renderItem = ({item}) => {
    return (
        
        <Cards item = {item} />)
}

return (
    
            <FlatList
            style = {styles.container}
            data = {ayet}
            renderItem={renderItem}/>

            
        )
    

};

export default NamazTakibi;`

React not rendering component with values passed from a DataTable

I’m trying to get in practice with GraphQL in React, consuming nHost backend service to retrieve and save data from/to a database. I succesfully made into log in and log out in the app, but now turns out a problem. Showing the data in a DataTable, works just fine, but the problem is: when I try to render a component passing data as props, the component does not render at all. In theory: the button showed at the end of the code (rendered only if a selection of the table is made), should trigger the handleView, which should render the component with the props passed by.
Note: console.log shows data. Also, React router dom is implemented in the app. Does it matter? Or just my code is not properly implemented?

Code below:

const [searchInput, setSearchInput] = useState('');
const [selectedclient, setSelectedclient] = useState(null)

const handleView = (e) => {
        e.preventDefault();
        console.log(selectedclient)
        if(selectedclient != null) 
            return <MainPanel data={selectedclient}/>
    }

return (
        <div>
            <form onSubmit={(e) => handleView(e)}>
                <input
                    className="input"
                    placeholder="insert the user you are looking for"
                    value={searchInput}
                    onChange={e => setSearchInput(e.value)}
                    ></input>
                <div className="card">
                    <DataTable value={filtered} selectionMode="single" selection={selectedclient} onSelectionChange={e => setSelectedclient(e.value)} dataKey="name" responsiveLayout="scroll">
                        <Column selectionMode="single" headerStyle={{width: '3em'}}></Column>
                        <Column field="name" header="Name"></Column>
                        <Column field="id" header="id"></Column>
                    </DataTable>
                </div>
                {filtered?.length != 0 && <button type="submit" >Select</button> }
            </form>
        </div>
    )

The component to be rendered:

const MainPanel = (data) => {
  const { name } = data

  return (
    <div>
        <div>MainPanel</div>
        <h3>{name}</h3>
    </div>
  )
}

Thanks in advance.

Chaining promises to display custom JS alert boxes one after the other

I’m building a game with vanilla JS/HTML/CSS and am trying to build a custom alert box to replicate the functionality of Javascript alert() while adding custom styling. There are several situations in my game where multiple alert boxes will need to be shown one after the other, but only when the user clicks on the “Continue” button in the box. From what I understand, the only way to do this is to use Promises that resolve on the “Continue” button clicks – however, I’m having some unexpected issues with my implementation.

Here’s the code that is responsible for showing the alert boxes i.e. modals (and setting the header + body of them) and handling button clicks:

// promise that waits for button click
let myPromise = new Promise(function(myResolve) {
    modal.style.display = "block";
    let modalButton = document.getElementById("continue-button");
        modalButton.addEventListener("click", () => {
            modal.style.display = "none";
            myResolve("OK");
        })
});
 


// function that shows the alert and sets content
var modal = document.getElementById("myModal");

const showAlert = (headerText, bodyText) => {
    console.log(headerText);
    let modalHeaderText = document.getElementById("modal-header-text"); 
    let modalBodyText = document.getElementById("modal-body-text"); 
    modalHeaderText.textContent = headerText;
    modalBodyText.textContent = bodyText;
    modal.style.display = "block";

    return myPromise;
}

I’m calling it like this:

showAlert("first header", "1").then(() => showAlert("second header", "2")).then(() => (showAlert("third header", "3")));

However, when I run my code, it shows me the first alert and then on clicking continue, skips to the third alert. Through console logging I see that the second showAlert() is also called but for some reason doesn’t wait for the promise to resolve i.e. the button to be clicked. I’ve tried rearranging the way .then is chained but it always shows the first and last alert boxes, skipping the ones in the middle. Any pointers on what I’m missing or how I could achieve this goal better would be incredibly useful!

Is there a way to do this in CSS?

So I’m making an HTML based game. In this game, 5 words are chosen at complete randomness. Everything’s fine, the code picks 5 words at random, and displays it on the screen, right?

Well I don’t like the way the words end up getting styled, and it pretty much looks like this:

enter image description here

So the goal is to end up making the text look like this.

pretty bad photoshopped goal

So far, I haven’t tried anything because I didn’t really know what to do, however the only one attempted using was inline-block, and it somewhat helped, but not to the full extent of how I want it. Here is the current source code:

<body>
  <div class="content" id="content">
    <div class="wordBank" id="wordBank">
    </div>
  </div>
  <script src="script.js"></script>
</body>
var wordBank = document.getElementById("wordBank")
// sparing you some of the unneeded stuff, this is just the word array
for (let i = 0; i < 5; i++) {
  wordBank.innerHTML += "<p>" + words[Math.floor(Math.random()*words.length)] + "</p>"
}
    body {
      margin: 0px;
    }
    .content {
      width: 512px;
      height: 512px;
      margin-left: auto;
      margin-right: auto;
      font-family: Arial;
    }
    .wordBank {
      border: 2.5px solid black;
      border-radius: 5px;
      font-size: 24px;
    }

How can I achieve my goal effectively? Any help is appreciated.

Please go easy. I’m at war with the internet. Aliens are in my house too, Who else is living in a simulation?

Where is the best playground for somehttps://stackoverflow.com/editing-help#comment-formattingone who just likes to tinker with all this cool stuff? Dealing with a broken heart too,italic and bold text,
inline code in backticks,
and [basic links](italic and bold text,
inline code in backticks,
and [basic links](https:italic and bold text,
inline code in backticks,
and basic links.

  1. List item

//example.com).https://example.com).

Creating an HTML table with JavaScript Results

var x = prompt(“Enter the width of the side of a Cube”)
x = parseFloat(x);

debugger;
document.write(“Volume of the cube = ” + (xxx) + “
“);
document.write(“Surface area of the cube = ” + (6xx) + “
“);
var r = x/2;
document.write(“Volume of largest sphere that could fit in the box = ” + (3.14rrr4/3) + “
“);
document.write(“Surface are of largest sphere that could fit in the box = ” + (3.14rr*4) + “
“);

method utakmicaToString() instead of returning string with values of vratiUtakmicu() it is setting result again and then returns

I have following code.

Method vratiUtakmicu() is returning object like this:

{
    nameOfFirstTeam: some string, 
    goalsFirstTeam: random number, 
    goalsSecoundTeam: random number, 
    nameOfSecoundTeam: some string
}

But when I call utakmicaToString() method it doesn’t take value of goalsFirstTeam,goalsSecoundTeam

Instead looks like it’s creating new random score and then print in console.

Copy my code and run so you will see the difference.

Can somebody explain to me why is this happening?

How can I fix this so method utakmicaToString() will take values
vratiUtakmicu(), and not creating random result again?

const arrEkipe = ["Srbija" , "Italija" , "Makedonija", "Bugarsk"]; 

class Utakmica{
constructor(ekipa1,ekipa2){
    this.ekipa1 = ekipa1;
    this.ekipa2 = ekipa2;
}
rezultat = () =>{
    return Math.ceil(Math.random() * 6 );
}
vratiUtakmicu = () => {
    return {domacin: this.ekipa1 , domaciGolovi: this.rezultat() ,
             gostGolovi: this.rezultat(), gost: this.ekipa2}
}
utakmicaToString = () => {
    
    return this.vratiUtakmicu().domacin + " " +
                        this.vratiUtakmicu().domaciGolovi +  " : " +
                        this.vratiUtakmicu().gostGolovi + " " +
                        this.vratiUtakmicu().gost + " " ;
    
}
}
var Kolo1 = {};
for(let i = 0; i < arrEkipe.length;i+=2){
Kolo1["Utakmica" + i] = new Utakmica(arrEkipe[i],arrEkipe[i+1]);
}

console.log("The result form this console has to be the same")
console.log(Kolo1.Utakmica0.vratiUtakmicu())
console.log("like result from this console but it looks like utakmicaToString() sets new 
random result")
console.log(Kolo1.Utakmica0.utakmicaToString())

How do I change the innerHTML when a fetch() is complete

I’m attempting to use a function to update a task status and then change that task status on the page using JS.

The javascript is in a separate file from the HTML. The HTML:
<a href="#" class="px-4 py-1 flex hover:bg-gray-100 no-underline hover:no-underline transition-colors duration-100" id="t_2" onclick="StatusUpdate(2,4) " @click.prevent="showContextMenu=false">In Progress</a>

The JavaScript Function:

async function StatusUpdate(task_id, status_id){
  let inno = document.getElementById('t_'+task_id);

   await fetch('/task_status/'+task_id+'/'+status_id, {
    method: 'get',
    headers: { 'Content-Type': 'application/json' },
  })
    .then(() => {
      this.message = 'Form successfully submitted!';
    })
    .then(()=>{
      console.log(inno);
      return inno.innerHTML = 'Complete';
    })
    .catch(() => {
      this.message = 'Ooops! Something went wrong!'
    })
  console.log(this.message)

 
}

The function works, as in it goes to the route, executes the code in the controller, updates the status but won’t change the HTML from ‘In Progress’ to ‘Complete’ on the page.

What am I missing here?