C# How to continue running JavaScript code after a redirect or refresh by using CefSharp

I need programmatically make 3 actions on the website

  1. filling search input
  2. pressing search button

(after that, a request occurs and the page returns me the search result)

  1. clicking on the first link

if I put action 1 and 2 in button 1:

private void Button1_Click(object sender, EventArgs e)
{
string jsScript1 = "document.getElementById('story').value=" + ''' + textFind.Text + ''' + ";" 
+ "document.querySelector('body > div.wrapper > div.header > div.header44 > div.search_panel > span > form > button').click();";
var task1 = chrome.EvaluateScriptAsync(jsScript1);
task1.Wait();
}

And action 3 in button 2:

private void Button2_Click(object sender, EventArgs e)
{
   string jsScript3 = "document.getElementsByTagName('a')[1].click();";
   var task3 = chrome.EvaluateScriptAsync(jsScript3);
   task3.Wait();
}

Everything works perfectly. But I want to do all these actions inside one button.

I found the following solution:

private async void ButtonFind_Click(object sender, EventArgs e)
        {
//Action 1 & 2
string jsScript1 = "document.getElementById('story').value=" + ''' + textFind.Text + ''' + ";" 
+ "document.querySelector('body > div.wrapper > div.header > div.header44 > div.search_panel > span > form > button').click();";
await chrome.EvaluateScriptAsync(jsScript1);



            //Action3
            Thread.Sleep(1000); //it is necessary to set exactly 1 seconds
            string jsScript3 = "document.getElementsByTagName('a')[2].click();";
            await chrome.EvaluateScriptAsync(jsScript3);

        }

I have to use Thread.Sleep(1000); because in JavaScript redirect or clicking on search button destroying all scripts currently running in the browser.
But I think using Thread.Sleep or Task.Delay its not a good idea.
How else can I change my code without using Thread.Sleep/Task.Delay?

Js передача текста/символов в php [closed]

Js генерирует шифр из текста, после, через ajax отправляет в файл PHP который принимает сам шифр и после расшифровывает его

Проблема в том, что когда я отправляю текст с символамм (шифр) из js на php он не может быть расшифрован, думаю из за того что формат или еще что то меняется и шифр изменяестя.. (Ключи подходят и на php и на js спокойно расшифровывается если не передавать из js на php

(применяю RSA шифрование)

Пробовал в js:
JSON.stringify(encryptedText);
encodeURI(encryptedText);

В PHP пробовал:
json_decode($encryptedText);

Помогите пожалуйста :/

JavaScript Template Class

I’m doing my best to learn JS but I feel like I get stuck!

how can I toggle this kind of template class? I want to set the value {done} of “data-done” property to “true”. Here is my code:

document.addEventListener('click', function(e) {
  if (e.target.classList.contains('y row')) {
    e.classList.toggle(data-done = 'true');
  }
})
[data-done='true'] {
  color: red;
}
<span class="y row" data-id="{id}" data-done="{done}" data-priority="{priority}">
     {name} {priority}
</span>

How to put cpuUsage value in variable through os-utils provided by node js

var os  = require('os-utils');
os.cpuUsage(function(v){
    v = Math.round(v*100);
    console.log( `os-utils get CPU Usage : ${v}%`);
    return v
});
var cpuUsage = os.cpuUsage(v()); 
console.log('what is that '+ cpuUsage); console.log(v); // undefined

I want to put the value in a variable and declare it as a global variable.
I can’t understand the asynchronous way. Please help me how to set up the callback function

JavaScript cannot insert variable value

I’m trying to insert the value of the variable newData123 into the test attribute.

But it inserts the variable name newData123 instead of its value 456…

What am I doing wrong?

const elm = document.querySelector('.test'),
  data = '123',
  newData123 = '456';
  
elm.setAttribute('test', `newData${data}`);

const check = elm.getAttribute('test');

console.log(check);
<p class="test"></p>

Mapping Array Of Objects with Unknown Keys or Lengths

I’ve got some data that I’m trying to output to Excel. My normal functions which work correctly with “normal” data are giving me issues, specifically, I’m seeing undefined for returned arrays in my MappedArrays variable and seem to be losing one row of data.

I tried to simplify the problem to make an MCVE, this may not even be the issue, but it is something I’d like my main function to be able to handle correctly.

Lets say I’ve got a bunch of Objects with unknown number of keys and not each object will have each key.

I’ve currently got a function to make sure each Object has each key (this is needed to paste the data in excel, the value can be null).

I have another function to convert the array of objects to array of mapped arrays where all the values should be in position by index.

In my test data, I’ve got a "Header_E": "Test", line in one Object which is currently being output in what looks to be it’s index in the Object, it should be correlated to the Index of the header/column.

Header_A    Header_B    Header_C    Header_D    Header_E    Header_F
2AVal       2BVal               
3AVal       3BVal               
4AVal       4BVal       4DVal           
                        Test    

How can I ensure that all objects in an Array of Objects have all keys and then map that ArrOfObjs to an Array with the data indexed accordingly to Object Key

Here is my sample data:

async function CommandsFunc(event) {
    try {
        await Excel.run(async (context) => {
            //Start Func.

            var ws = context.workbook.worksheets.getActiveWorksheet();

            var Obj_One_A = {
                "Header_A": "2AVal",
                "Header_B": "2BVal",
            }

            var Obj_Two_A = {
                "Header_A": "3AVal",
                "Header_B": "3BVal",
            }

            var Obj_One_B = {
                "Header_A": "4AVal",
                "Header_B": "4BVal",
                "Header_D": "4DVal",
            }

            var Obj_Two_B = {
                "Header_A": "",
                "Header_C": "",
                "Header_E": "Test",
                "Header_F": "",
            }

            var Arr_Of_Items = [Obj_One_A, Obj_Two_A]

            //await Do_Arr_Of_Objs_Or_Arrs_To_Rng(context, ws, Arr_Of_Items)

            var HeaderArr = ["Header_A", "Header_B"]
            var MappedArrays = await Get_Mapped_Over_Array_Of_Objects(Arr_Of_Items, HeaderArr)
            MappedArrays.unshift(HeaderArr)

            var rng = ws.getRangeByIndexes(0, 0, MappedArrays.length, MappedArrays[0].length)

            rng.select()
            await context.sync();
            rng.values = MappedArrays
            await context.sync();       

            var Arr_Of_Items = [Obj_One_B, Obj_Two_B]
            var All_Headers_Arr = ["Header_A", "Header_B", "Header_C", "Header_D", "Header_E", "Header_F"]
            var MappedArrays = await Get_Mapped_Over_Array_Of_Objects(Arr_Of_Items, All_Headers_Arr)

            var Used_Rng = ws.getUsedRange(true)
            Used_Rng.load('rowCount')
            await context.sync()
            var rng = ws.getRangeByIndexes(Used_Rng.rowCount, 0, MappedArrays.length, All_Headers_Arr.length)

            //Set Headers
            for (let ai = 0; ai < All_Headers_Arr.length; ai++) {
                ws.getUsedRange(true).getRow(0).getCell(0, ai).values = All_Headers_Arr[ai]
            }

            rng.select()
            await context.sync();
            rng.values = MappedArrays
            await context.sync();

            //await Do_Arr_Of_Objs_Or_Arrs_To_Rng(context, ws, Arr_Of_Items)

            //End Func
            await context.sync();
        });
    } catch (error) {
        console.log(error)        
    }
    try { event.completed() } catch (error) { }
}   

Helper Funcs:

async function Get_Mapped_Over_Array_Of_Objects(ArrayOfObjs, MapArr) {
    ArrayOfObjs = await Do_All_Arr_Of_Objs_Same_Keys(ArrayOfObjs, MapArr)
    let MappedArrays = []
    for (let i = 0; i < ArrayOfObjs.length; i++) {
        var obj = ArrayOfObjs[i]
        var arr = Object.keys(obj).map((k) => obj[k])
        MappedArrays.push(arr)
    }
    return MappedArrays;
}

async function Do_All_Arr_Of_Objs_Same_Keys(Arr_Of_Objs, Keys_Arr) {
    for (let oi = 0; oi < Arr_Of_Objs.length; oi++) {
        var obj = Arr_Of_Objs[oi]
        var Obj_Keys = Object.keys(obj)
        if (Keys_Arr.length != Obj_Keys.length) {
            var temp_arr = []
            temp_arr = Keys_Arr
            for (let ki = 0; ki < Obj_Keys.length; ki++) {
                temp_arr = await Do_Remove_Arr_By_Val(temp_arr, Obj_Keys[ki])
            }
            for (let ai = 0; ai < temp_arr.length; ai++) {
                obj[temp_arr[ai]] = ""
            }
        }
    }
    return Arr_Of_Objs
}

function Do_Remove_Arr_By_Val(arr, val) {
    var filteredArray = arr.filter(function (e) { return e !== val })
    return filteredArray
}

How to Find a specific value in nested object

I am working on an app in which I want to render a component on the basis of the value I am getting from the API. The returned value is a string and can have space in between. So I have made an object (with demo data for simplicity) that has keys as strings and values as components like this

const conditions = {
    First: {"one" : <Component1 />, "two": <Component2 />},
    Second: {
        "var one": {"one": <Component3 />, "two": <Component5 />},
        "var two": {"one": <Component4 />, "two": <Component8 />},
        "var three": {"one": <Component7 />, "two": <Component5 />},
        "var four": {"one": <Component2 />, "two": <Component1 />}
    },
    Third: <Component6 />,
    Four: <Component7 />,
    Five: {
        "var six": <Component1 />
        "var seven": <Component5 />
        "var eight": <Component4 />
        "varr nine": <Component7 />
        "var ten": <Component8 />
        "var eleven": <Component1 />
    },
    Six: <Component4/>
}

So far I have tried using a recursive function containing a for-in loop to iterate the object and check if the value of the current key is an object or not but a component is also an object so it just keeps going instead of returning the value i.e component itself. And I have tried checking if the key of the value object is a string but then the returned component’s first key which is $$typeof is also a string.

const getValue = (obj) => {
  for (const key in obj) {
     if (key === 'apiVariablestring') {
        if (Object.keys(obj[key])[0] === 'string') {
                getValue(obj[key]);
        } else {
          //should return component here but else will never run
        }
     }
  }
}

I am not sure this is the best way to do it I have not done this before and I am new when it comes to dealing with API. If there’s a better way please tell me.

load texture in a class before proceeding

I have presented a simple example to illustrate what my problem is. in functions it’s easy to use await async to make sure textures are loaded before proceeding with the program. if I want to work with classes because of the cleanliness of the program, I have no idea how I can do this so that the constructor waits until the texture is loaded before the subsequent function is called.

class Environment{
  constructor(){

    this.sphereObject = new Sphere(100);
    this.sphere = this.sphereObject.sphere;
  }

}


class Sphere{
  constructor(radius){
 
    var loader = new THREE.TextureLoader();
    var texture = loader.load("grass.png");  //here is the problem! I need something like this "await loader.loadAsync("grass.png");" to make sure the texture is loaded first before continuing.
    var material = this.doSomething(texture);
    var geometry = new THREE.SphereGeometry( radius, 128, 64 );

    this.sphere = new THREE.Mesh( geometry, material); 

  }

  doSomething(texture){
    //further operations with the texture before the function returns a material

    return material;
  }

}

Q: HighChart view Table(fn: getTable) be behind in one’s columns

get the data from DB and spread the date(YYYY-MM) on xAxis.
And it can see the table just below the chart through the getTable() function,
there is a shape where one more data in the table is generated and pushed back.
For example, it starts from 2020-08, and as it starts from 2020-07 in the table, the data is pushed back one by one on a date basis.
In the chart, it was confirmed that it normally started at 2020-08.
What’s the problem?

Filtering Dates in Mapbox GL JS

I’m in need of a possible solution to filtering dates in my web application. This was a possible solution but, it still filters numerically. The rest of the code for filtering works just fine. Also, my dataset has the format “mm/dd/yyyy”. Any ideas guys? (Btw, I have the date filter portion commented out so I can use my filter without it)

    var crimeFilter=[
        "all",
        ["in", "ZIP", zipCode],
        //[">=", "Date", finishedFrom],
        //["<=", "Date", finishedTo],
        ["in", "Crime", arson, assault, criminalDamage, dui, motorVehicleTheft, murder, resistingArrest, robbery, sexualAssault, theft, weaponsCharges]

    ]

Should I learn React Native with Firebase or React Native with MERN for developing a small App?

I’m actually a VFX artist and I’ve always been passionate about coding but never felt the need to actually learn web or app development but Recently, I’ve started learning basic Web Design and Javascript as I’ve got an Idea about an App that I want to create.
Basically I want to clone a pre-existing social media kind of matrimony app targeting a different community in a different language living in a different region.
I’m about to finish my online course on Javascript. Next, I’m going to focus on ReactJS and React Native but I guess that only accounts for the frontend. I’ve heard Firebase is some sort of backend service for developers who want to create an app on small scale and is an alternative to MongoDB and Nodejs.
Is it possible for me to not learn any backend programming and directly learn firebase for my future react native app? Or do I have to completely master MERN stack.
I know can just pay people for development but I really wanna test myself first.