Compare part of url with contents of div

One of the site i am using recently implanted suggestion search so currency showing so many unrelated trash.

​Trying to hide all div that not contain part of url.

sample url pattern

https://urll.com/lib/search/textquery

div part

    <a class="text-secondary group-hover:text-primary" href="https://urll.com/lib/F52dk" alt="F52dk">click here for F52dk link
</a>

Not very familiar with jquery and try to wrote two scripts but none of them worked.


    if ($("exampledivname").has(":contains('window.location.pathname.split("/").pop()')").length) {
    
    } else {
       hide();
    
        }
var lastpart = window.location.href.substr(window.location.href.lastIndexOf('/') + 1)
var alttt = $('a').attr("alt");
if (lastpart === alttt) {
  alert("it's there!!");
}

I can’t figure out how to configure “innerHTML” to print text under a contact card

I’m brand new at learning how to develop code, and I’m stuck.

We were provided HTML to copy/paste into our index.html file, and we need to write JavaScript in our script.js file to extract information entered into “Full Name, Email, and Message” and place them under “Contacts.” I’ve attached some screenshots (instructions/result) to add a visual.

I made it toward the bottom of the instructions (Part 2 – JavaScript, #2), and now I’m stuck. I tried different strings of code to print information under “Contacts” and nothing seems to be registering.

Instructions

Desired Result

I have attached different “function getInfo()” strings I’ve been trying. They could be completely off, or perhaps close to the answer; at this point, I’m unsure. Either way, nothing is printing.

Attempt #1

var btn = document.getElementById('btn');
btn.addEventListener ("click", function getName(event) {
    event.preventDefault();
})

function getInfo(){
var fullName1 = document.getElementById("name").innerHTML; alert (fullName1);
var email1 = document.getElementById("email").innerHTML; alert (email1);
var message1 = document.getElementById("message").innerHTML; alert (message1);
}

Attempt #2

var btn = document.getElementById('btn');
btn.addEventListener ("click", function getName(event) {
    event.preventDefault();
})

function getInfo(){
var fullName1 = document.getElementById("name");
    fullName1.innerHTML = ("contactCard");
var email1 = document.getElementById("email");
    email1.innerHTML = ("contactCard");
var message1 = document.getElementById("message");
    email1.innerHTML = ("contactCard");
}

If you need a visual of what is currently in my Index tab (and the information I’m trying to extract), I’ll provide the code for reference below.

Index File

<body>
    <div id="content">
        <h1>My Contact Form</h1>
        <form>
            <label for="fullName">Full Name</label>
            <input id="name" type="text" name="fullName"><br>
            <label for="email">Email</label>
            <input id="email" type="text" name="email"><br>
            <label for="message">Message</label>
            <input id="message" type="text" name="message"><br>
            <button id="btn" type="submit">Submit</button>
        </form>
    </div>
    <div id="contactCard">
        <h2>Contacts</h2>
        <p id="postFullName"></p>
        <p id="postEmail"></p>
        <p id="postMessage"></p>
    </div>
    <script src="script.js"></script>
</body>

Any help would be greatly appreciated. Thank you!

How to execute Node.JS package on Win 11

I’m trying to parse some public EPG XML files from this repo:
https://github.com/freearhey/epg-parser

They provide a test file, and three different XML example files in the test folder to help you understand how it works. I’ve never really worked in Node.JS extensively and have no idea where to go from here.

If someone could help me figure out how to use this, I’d greatly appreciate it!

I’ve installed Node.JS using scoop, and installed the package using the instructions:
‘npm install epg-parser’ and also by cloning the repo, cd into directory and execute ‘npm install’.

How to transfer JSON from webpage to desktop application extension [closed]

Ive create two webpage which are capable of transfer data using API between two different port (URL). It is a success and now I need to try it with desktop application extension.

I cant access to the extension source code i guess ? I cant open the .dll files. How can i make a consumer API at my desktop application extension. It is a big company software by the way. My boss asked me to develop a website that is capable of transfering the data from the website to the application’s extension which the extension is created by my senior while the software it self is another company’s

In Javascript string replace newline, carriage return chars with empty and replace literal sequences n and r with newline and carriage return chars

In Javascript, I want to do multiple replace in a string as listed below.

  1. Deelete all newlines and carriage returns
  2. Replace literals n with newline char
  3. Replace literals r with carriage return char

I want to achieve something like as below.

let str=
"line1rn
line2n
line3r";

//I want to modify in first step to
"line1rnline2nline3r";

//In second step I want to modify it to
"line1r
line2
line3r";

//In third step I want to modify it to
"line1

line2
line3
";

What is the best efficient way to do this?

@Input() not rendering/receiving the most recent passed value

I am developing an angular application, where I am trying to pass a value from a parent component to a child component using the @Input() decorator. however, the value still renders the old/initial value from the child component and not the updated/most recently passed value from the parent component. Does anyone understand why and how to fix this?

Code:

@Input('amt') amount:any =100;

parent component

<app-payment [amount]="100*2"></app-payment>

How to set up the main page using routing

“”App.js””

function App() {

  const [mainComponent, setMainComponent] = useState(`main1`);

   return (

    <div className="App">
      <header className="App-header">
        <Routes>
        <Route path="/" element={mainComponent === `main1` ? <Main1 /> : mainComponent ===   `main2` ? <Main2 /> : <Main3 />} />
           <Route path="/admin" element={<Admin />} />
          <Route path="/main1" element={<Main1 />} />
          <Route path="/main2" element={<Main2 />} />
          <Route path="/main3" element={<Main3 />} />
        </Routes>
       </header>
    </div>
  );
}

export default App;

“”Admin.js””

const Admin = () => {
     const navigateUrl = useNavigate();
    const [mainPage, setMainPage] = useState(`main1`);

    const handleButtonClick = (page) => {

        setMainPage(page);

        navigateUrl(`/`);
    };

    const memberId = sessionStorage.getItem("members_id");
    const isAdministrator = sessionStorage.getItem("members_id") === "1";
    const navigate = useNavigate();
    const [pages, setPages] = useState([]);

    if (memberId !== "1") {
        return navigate("/")
    }

    return (
        <div>
            <main className="mt-5 pt-5" />
            <div className="mypage-wrap">
                <Row className="justify-content-center">
                    <Col className="text-center">
                        <ButtonGroup aria-label="Basic example">
                            <button onClick={() => handleButtonClick(`main1`)}>to Main1</button>
                            <button onClick={() => handleButtonClick(`main2`)}>to Main2</button>
                            <button onClick={() => handleButtonClick(`main3`)}>to Main3</button>
                            
                        </ButtonGroup>
                    </Col>
                </Row>
                <br />     
            </div>
            <hr />
        </div>
    )
}

export default Admin

When I click a button in my component, I want to display the page corresponding to the clicked button whose name is in the “/” routing path in app.js.
For example, if you press 2 on the component, you want the page at “/” to show the main2.js screen, and if you press 3, you want the main3.js screen to be shown.

And I want the initial setting value to be displayed as main1.js.

And I want to set the main screen to “/” by pressing the button, and when I refresh localhost as the main path, I want the page I set to appear by pressing the button. Is it impossible because it is a react?

Browser visibilitychange event no longer fired on page navigation?

The MDN docs say that the visibilitychange event

fires with a visibilityState of hidden when a user navigates to a new page, switches tabs, closes the tab, minimizes or closes the browser, or, on mobile, switches from the browser to a different app.

While I recall having experience with this being true, it looks like it isn’t anymore (at least not on either Chrome or Firefox). I’m currently on desktop Chrome Version 121.0.6167.160

To reproduce, if I look at the end-of-session analytics example and basically copy-paste the function into the browser console like

document.onvisibilitychange = () => {
  console.log(document.visibilityState);
};

then I’ll see “hidden” and “visible” logged to the console as I switch between open tabs. However, if I then click a random link that takes me to another page, nothing is logged and so I’m left to assume that the visibilitychange event is not firing in this case (the preserve-log option is checked in the dev console).

And just as an ultra-sanity check, the same behavior happens if I replace the console log with an actual sendbeacon request.

It sounds unlikely that a browser bug was pushed since it’s happening in both chrome and firefox, so what am I missing / not understanding here?

Sanitizing HTML string in Angular removes formatting from attributes

I’m experimenting a little and making a function to dynamically build the fields of a form.
The thing is, at first the sanitizer in Angular removes <input> tags, so I found out that I can bypass that for the string that contains the HTML code.
The problem is, I need to bind an attribute to that <input> but after bypassing the santizer, the attribute is transformed to all lowercase. Here is all the code:

FormBuilder

import { FormItem } from "./formItem.interface"

export const FormFieldsBuilder = (fields: FormItem[]): string => {
    let htmlString: string = ''

    fields.forEach(field => {
        let attributes = field.htmlTagAttributes?.join(' ')
        let baseString = `

            <div class="${field.fieldContainerClass}">
                <div class="${field.fieldClass}">
                    <label for="${field.name}" >${field.label}</label>
                    <${field.htmlTag} ${attributes} 
                        class="${field.htmlTagClass}" 
                        formControlName="${field.name}">
                    </${field.htmlTag}>
                </div>
            </div>

        `

        htmlString += baseString
    });

    return htmlString
}

New product form component

import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ProductsService } from '../../../api/services/products.service';
import { FormItem } from '../../../shared/helpers/FormFieldsBuilder/formItem.interface';
import { FormFieldsBuilder } from '../../../shared/helpers/FormFieldsBuilder/formFieldsBuilder';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

@Component({
  selector: 'app-new-product',
  templateUrl: './new-product.component.html',
  styleUrl: './new-product.component.scss'
})
export class NewProductComponent {
  uploadedFiles: File[] = [];
  formData : FormData = new FormData()
  mainProductFields: FormItem[] = []
  fieldsString: string = ''

  constructor(private fb: FormBuilder, private productsService: ProductsService, private sanitizer: DomSanitizer) {
    this.mainProductFields = [
      { 
        label: 'Nombre', 
        name: 'name', 
        htmlTag: 'input', 
        htmlTagClass: 'w-full', 
        fieldContainerClass: 'col-12 lg:col-6 pb-0',
        fieldClass: 'field w-full flex flex-column gap-2',
        htmlTagAttributes: [
          'pInputText'
        ]
      }
    ]

    this.fieldsString = FormFieldsBuilder(this.mainProductFields)
  }

  
  public get formFields() : SafeHtml {
    return this.sanitizer.bypassSecurityTrustHtml(this.fieldsString)
  }

  // Other irrelevant code...
}

New form component html

<div class="grid" [innerHTML]="formFields">

So, the attribute should be pInputText but after sanitizing it gets transformed into pinputtext
Is there a way to solve this? Thank you!

Implementing QR codes into a solidity smart contract

im buiding a counterfeit product authentication DAPP that accepts product details from a user and let the user verify the authenticity of the product using QR, im having a hard time finding a way on how to go about the integration of the QR codes part how do i do it.

i have been looking for ways to do it but imnot having any luck

AJAX Post returning NULL in Controller (ASP.NET MVC)

I’ve got a Javascript function, and I want it to pass through data to my controller.

This is my Javascript code:

    $.ajax({
        type: "POST",
        url: "/Home/CreateUser",
        contentType: "application/json",
        dataType: "json",
        data: JSON.stringify({name: 'Dylan', email: '[email protected]', password: 'password'}),
        success: function (response) {
            window.location.href = 'dashboard';
        },
        error: function (error) {
            alert('Error while signing up: ' + error);
        }
        })

..and this is how I’ve got my Controller set up to receive the request:

    [HttpPost]
    public ActionResult CreateUser(string name, string email, string password)
    {
        Console.WriteLine("Data received successfully: Name - " + name + ", Email - " + email + ", Password - " + password);
        return Content("Data received successfully: Name - " + name + ", Email - " + email + ", Password - " + password);
    }

Currently each value is passed through as null and I can’t figure out why this isn’t working. The request in the browser network tab appears to be sending the Json so I think there is something wrong with how I have set up my controller. I’ve tried setting up a class and receiving that, but that still won’t work.

Thanks,
Dylan

Allowing a test to fail or passing an empty chainable element in Cypress

I have a Cypress Custom Command that attempts to find a particular row in a table based on one of its’ table datas containing some text. It first tries to get the first table on the page (unless you explicitly pass it one), then searches inside that table for a particular row.

If it’s unable to find the table or the row, I want it to just pass back an empty chainable element so that I can operate on it with something like should('not.exist').

The command:

Cypress.Commands.add('getTableRowContainingText', (text: string, $table?: Cypress.Chainable<JQuery<HTMLElement>>): Cypress.Chainable<JQuery<HTMLElement>> => {

  if (!$table)
    $table = cy.get('*[data-cy=Table]').first()

  /* If table doesn't exist, return empty chainable (what?) */

  return $table
    .find('tbody > tr > td')
    .filter(`:contains(${text})`)
    .first()
    /* If row doesn't exist, return empty chainable (what?) */
    .parent('tr')

})

Then I would be able to do something like this in a test:

cy.getTableRowContainingText('table data text that definitely exists').should('exist')
cy.getTableRowContainingText('table data text that definitely does not exists').should('not.exist')

/* Passes! */

In a Javascript class how do i set a callback in the constructor to a function in the same class? [closed]

Hello I have a setup where i assign the route “login” to call my login function like so:

export default class LoginController {

    constructor(server) {
        //Set(HTTPVerb::enum, route::string, callback::function)
        server.Set(Server.HTTPVerbs.POST, 'login', this.#Login);
    }

    #Login() {
        //todo implement login
    }
    #Logout(){
       //todo implement logout
    }

}

But i get the error:

TypeError: LoginController.Login is not a function

I am kind’ve confused why i get this error…What am i getting wrong here?

Configured Google Document AI to enable “computeStyleInfo”, but not receiving any textStyles in the response

The textStyles array from the Document AI response object is empty, despite having set everything up following google’s docAI documentation.

I enabled document AI’s font-style detection following google’s documentation here.

In my server, the request is built as follows

const request: google.cloud.documentai.v1.IProcessRequest | undefined = {
      name,
      rawDocument: {
        content,
        mimeType,
      },
      processOptions: {
        ocrConfig: {
          premiumFeatures: {
            enableMathOcr: true,
            computeStyleInfo: true,
          }
        }
      }
    };

And the OCR processor is set to v2.0 in the GCP / terminal for doc ai. Unfortunately, when sending images with clear styles (underlines, bolds, etc) the response object still contains no textStyles information (empty array).

response object with empty text styles array

Did I miss a step somewhere?

Default values for Vue prop type “Object”

Object or array defaults must be returned from a factory function (source).

Example:

foobar: {
  type: Object,
  default() {
    return {}
  }
}

// OR

foobar: {
  type: Object,
  default: () => ({})
}

foobar will return an empty object {} by default.

But if you want to know if it is defined, it will always return “true”. So you can do this instead:

foobar: {
  type: Object,
  default() {}
}

// OR

foobar: {
  type: Object,
  default: () => {}
}

foobar will return as undefined by default.

Is that last practice naughty?