Trim mobile numbers in textarea field

I have a textarea field in a form where I can copy paste mobile numbers. It will have one number per line, like this I can copy paste thousands of mobile numbers to submit in that form.
I want to trim that field, I only want 10 digit numbers to remain in that field after copy paste a lot of numbers from excel or any other file.
Only 10 digit numbers should remain and all other invalid numbers should automatically remove from that field.
Example:
IF I paste this numbers in this textarea field,
9848012345
9949123450
9949 123456
99491234
+1236547890
9848098765
From this only 10 digit numbers should remain in field, like this:
9848012345
9949123450
9848098765

<div class="form-group row">
     <label for="title" class="col-lg-2 col-form-label">Mobile Numbers </label>                         
   <div class="col-lg-10">
     <textarea onKeyUp="countline()" type="text" class="form-control required" required 
cols="10" rows="7" id="mobileno" name="mobileno"> </textarea>
 </div>
</div>

This is possible with Java script? Any help please. Thanks in advance.

specific text in prompt for pythonscript

In JavaScript, you can use prompt("This text is above the field in the prompt.", "This text is in the field of the prompt.") to get a customized window appearing.

In PythonScript you can trigger the prompt by using input(), but input(“Please enter your name”, “Harry Potter”) doesn’t work the way JS does.

So how can I trigger such behaviour?

Here is my simple code, although it isn’t necessarily relevant for the question:

HTML

<!DOCTYPE html>
<html lang="de">
    <head>
        <title>PyScript</title>
        <link rel="stylesheet"href="https://pyscript.net/alpha/pyscript.css"/>
        <script defer src="https://pyscript.net/alpha/pyscript.js"></script>
    </head>
    <body>
        <py-script src="script.py" />
    </body>
</html>

PYTHON

print("Enter the elements for comparison like this: Element1, Element2, Element3")

elements_list = input().split(", ")

def swap(list, i, j):
    temp = list[i]
    list[i] = list[j]
    list[j] = temp
    
for i in range (len(elements_list)-1):
    for i in range (len(elements_list)-1):
        if input (f"""{elements_list[i]} (type 1) or {elements_list[i+1]} (type 2)?""") == "2":
            swap (elements_list, i, i+1)


print("Your order ", elements_list)

Discard audio before certain time from Hls.js stream

I am using Hls.js to live stream an audio feed into an audio element in my HTML. In my custom audio controls I limit the user to only be able to scroll back to the most recent five minutes of audio in the stream. However the audio for any time beyond the most recent five minutes still exists.

Is there any way to discard/trim the audio source beyond the most recent five minutes? Given i only care about the most recent five minutes of audio and the livestream could be constantly playing for multiple hours on end, what is the best method discard any of the unneeded audio from the source?

Thanks!

How can I add a cover image to a Discord Scheduled Event?

I have created an event through the Discord JS Library, and would like to add a user option to add a cover image.

The code below is working fine, but the image isn’t being added to the event. Any help would be great, thank you.

const event = await interaction.guild.scheduledEvents.create({
        name: name,
        description: description,
        image: 'https://i.imgur.com/2nvP4Lm.jpeg',
        scheduledStartTime: new Date(`${eventDate} ${startTime}`),
        scheduledEndTime: new Date(`${eventDate} ${endTime}`),
        privacyLevel: 2,
        entityType: 'EXTERNAL',
        entityMetadata: {
            location: location
        }
    });

Why browser.downloads.dowload hits into “undefined is not an object” error for Safari extension?

While trying to port my extension to Safari (using xcrun safari-web-extension-converter), the browser.downloads.download implementation in my extension to download the user options stored hits into following error:

TypeError: undefined is not an object (evaluating
‘browser.downloads.download’)

Following lists my implementation for downloading the user options as .csv file:

var enableDebug = 1;
// Function to download CSV file
function downloadCSV(csv, file_name) {
  try {
    var blob = new Blob([csv], {
      type: "text/csv;charset=utf-8"
    });
    browser.downloads.download({
      url: URL.createObjectURL(blob),
      filename: file_name,
      saveAs: true
    });
  } catch (err) {
    if (enableDebug === 1) {
      console.log(err);
    }
  }
}

manifest.json permissions:

"permissions": ["menus", "storage", "unlimitedStorage", "downloads"]

The Safari version being used is 15.4. Looking around the web had given following links which seem relevant, but i’m quite not sure if the issues mentioned in these links are the ones which are causing failure in my case:

browser.downloads API for Safari Web Extensions

Safari error undefined is not an object

I did try with adding the following in entitlements file of XCode, but it didn’t help either:

com.apple.security.files.downloads.read-write

Any help to understand the cause and probable solution would be highly appreciated.

I would like to delet an specific bracket form an div on an website using javascript

so i have the following div where i just van to delete the first bracket using javascript.

**<**div class=”page-content” style=”user-select:none;filter:blur(4px)”>

I have very little to none javascript knowledge. (is this posible?)

So there is an website that blurs an part of the website content. i want to get rid of the blur, but just editing the blur to 0px does not work. So i need to delet the “<” in order for it to work. Now i have an plugin that can automate javascript so i was wondering if there is an javascript code that does delet this.

Password type toggle [duplicate]

For some reason the function changes only the class for “pass_icon” but not the type of x aswell. What could be the problem? Btw I have the script written in the head of the HTML if it’s usefull information.

Here’s the code:

<input type="password" name="password" placeholder="Introduceti parola:">
<input type="checkbox" onclick="visibility()" id="pass_visible">
<label for="pass_visible"><i style="color: #C0C0C0" id="pass_icon" class="bi bi-eye"></i></label>
function visibility() 
        {
          var x = document.getElementsByName("password");
          if (x.type === "password") 
          {
                x.type = "text";
                document.getElementById("pass_icon").className = "bi bi-eye-slash";
          } 
        else 
          {
                x.type = "password";
                document.getElementById("pass_icon").className = "bi bi-eye";
          }
        }

Array sorting: List top 3 only [duplicate]

What my code does:

My code reads data from a .json file with the following content:

{
"user1": "200",
"user2": "100",
"user3": "150",
"user4": "50"
}

and lists them in descending order (highest value on top, lowest on bottom)

Output:

1. <user1>: 200
2. <user3>: 150
3. <user2>: 100
4. <user4>: 50

What my code is supposed to do/What I want my code to do instead:

My code is supposed to list the top 3 only but I don’t know how to get it to do so. Please take a look at the expected/wanted Output.

Expected/Wanted Output:

1. <user1>: 200
2. <user3>: 150
3. <user2>: 100

My Code so far:

const fs = require('fs');

a = JSON.parse(fs.readFileSync("./data.json", "utf8"));

let arr = [];
for (var i in a) {
    arr.push([i, a[i]]);
}
arr.sort(function(first, second) {
    return second[1] - first[1];
});
console.log(arr.map((a, b, c) => `${(Number(b) + 1)}. <${a[0]}>: ${a[1]}`).join("n"))

I appreciate any help down below.

Radio button validation alert not showing – works on everything else

I’m creating a cfmail form for a nonprofit to allow potential vendors to request a spot at the next fundraiser. All fields are required but the radio buttons are not showing the validation alert if not selected.

I’m javascript illiterate so I had someone else write the JS but she had to move on to other obligations before getting the radio buttons working and I need this working before she’ll have time to get back to it. Any help would be greatly appreciated.

Here’s the Code:

// VERIFY reCAPTCHA HAS BEEN CHECKED 

var form = document.getElementById('Vendors');
form.addEventListener("submit", function(event) {
  if (grecaptcha.getResponse() === '') {
    event.preventDefault();
    alert('Please check the reCaptcha to submit your Vendor Request.');
  }
}, false);

// phone number

function phoneFormat(input) { //returns (###) ###-####
  input = input.replace(/D/g, '');
  var size = input.length;
  if (size > 0) {
    input = "(" + input
  }
  if (size > 3) {
    input = input.slice(0, 4) + ") " + input.slice(4, 11)
  }
  if (size > 6) {
    input = input.slice(0, 9) + "-" + input.slice(9)
  }
  return input;
}

$(document).ready(function() {
  $("#submitall").click(function() {

    if (oked) {
      $('#submitall').prop('disabled', true);
      $("#submitall").html("Sending...");
      $("#eblastMail").submit();

    }
  });

  $('#salesyes').click(function() {
    if ($('#salesyes').is(':checked')) {
      $("#statesales").css("display", "block");
      $("#StateTaxNumber").prop('required', true);
      $("#Details").prop('required', true);
    } else {
      $("#statesales").css("display", "none");
      $("#StateTaxNumber").prop('required', false);
      $("#Details").prop('required', false);
    }
  });
  $('#salesno').click(function() {
    if ($('#salesno').is(':checked')) {
      $("#statesales").css("display", "none");
      $("#StateTaxNumber").prop('required', false);
      $("#Details").prop('required', false);
    } else {
      $("#statesales").css("display", "block");
      $("#StateTaxNumber").prop('required', true);
      $("#Details").prop('required', true);
    }
  });

});

function countChecked() {
  //$("#validateSend").bind('change', function()  {
  console.log("validateSend clicked");

  var cBox = $("#validateSend");
  console.log(cBox);

  console.log(cBox.prop('checked'));

  if (cBox.prop('checked')) {

    $('#submitall').prop('disabled', false);
  } else {
    $('#submitall').prop('disabled', true);
  }
}; //end countchecked

// Example starter JavaScript for disabling form submissions if there are invalid fields
(function() {
  'use strict';
  window.addEventListener('load', function() {


    // Fetch all the forms we want to apply custom Bootstrap validation styles to
    var forms = document.getElementsByClassName('needs-validation');
    // Loop over them and prevent submission
    var validation = Array.prototype.filter.call(forms, function(form) {

      form.addEventListener('submit', function(event) {


        if (form.checkValidity() === false || $('input[name="Sales"]:checked').length == 0) {
          event.preventDefault();
          event.stopPropagation();
        }
        form.classList.add('was-validated');
      }, false);
    });
  }, false);
})();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
`
<!-- vendor app -->
<div class="container mt-2">
  <div class="row justify-content-center mt-5">
    <div class="col-sm-12 col-md-10 Sponsors text-center">
      <form class="needs-validation" action="/Vendors/index.cfm" id="Vendors" method="post" novalidate>
        <input type="hidden" name="Vendors_submit" value="yes">
        <!-- company name -->
        <div class="form-group row">
          <label for="Company" class="form-label text-right">Business/Organization:<sup class="text-danger">*</sup></label>
          <input id="Company" name="Company" placeholder="Business/Organization Name" type="text" class="form-control" style="text-transform: capitalize;" required>
          <div class="valid-feedback">
            Looks good!
          </div>
          <div class="invalid-feedback text-left">
            Please enter the name of the company or individual interested in the Vendor spot.
          </div>
        </div>
        <!-- address -->
        <div class="form-group row">
          <label for="Address" class="form-label text-right">Address:<sup class="text-danger">*</sup></label>
          <input id="Address" name="Address" placeholder="Address" type="text" required="required" class="form-control" style="text-transform: capitalize;">
          <div class="valid-feedback">
            Looks good!
          </div>
          <div class="invalid-feedback text-left">
            Please enter the address of the Company.
          </div>
        </div>
        <!-- city -->
        <div class="form-group row">
          <label for="City" class="form-label text-right">City:<sup class="text-danger">*</sup></label>
          <input id="City" name="City" placeholder="City" type="text" required="required" class="form-control" style="text-transform: capitalize;">
          <div class="valid-feedback">
            Looks good!
          </div>
          <div class="invalid-feedback text-left">
            Please enter the City.
          </div>
        </div>
        <!-- state -->
        <div class="form-group row">
          <label for="State" class="form-label text-right">State:<sup class="text-danger">*</sup></label>
          <input id="State" name="State" placeholder="State" type="text" required="required" class="form-control" style="text-transform: capitalize;">
          <div class="valid-feedback">
            Looks good!
          </div>
          <div class="invalid-feedback text-left">
            Please enter the State.
          </div>
        </div>
        <!-- zip -->
        <div class="form-group row">
          <label for="Zip" class="form-label text-right">Zip:<sup class="text-danger">*</sup></label>
          <input id="Zip" name="Zip" placeholder="Zip" type="text" required="required" class="form-control">
          <div class="valid-feedback">
            Looks good!
          </div>
          <div class="invalid-feedback text-left">
            Please enter the Zip Code.
          </div>
        </div>
        <!-- first name -->
        <div class="form-group row">
          <label for="FirstName" class="form-label text-right">Contact First Name:<sup class="text-danger">*</sup></label>
          <input id="FirstName" name="FirstName" placeholder="First" type="text" class="form-control" style="text-transform: capitalize;" required>
          <div class="valid-feedback">
            Looks good!
          </div>
          <div class="invalid-feedback text-left">
            Please enter your first name.
          </div>
        </div>
        <!-- last name -->
        <div class="form-group row">
          <label for="LastName" class="form-label text-right">Contact Last Name:<sup class="text-danger">*</sup></label>
          <input id="LastName" name="LastName" placeholder="Last" type="text" required="required" class="form-control" style="text-transform: capitalize;">
          <div class="valid-feedback">
            Looks good!
          </div>
          <div class="invalid-feedback text-left">
            Please enter your last name.
          </div>
        </div>
        <!-- email -->
        <div class="form-group row">
          <label for="Email" class="form-label text-right">Email:<sup class="text-danger">*</sup></label>
          <input id="Email" name="Email" placeholder="Email" type="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,}$" required="required" class="form-control">
          <div class="valid-feedback">
            Looks good!
          </div>
          <div class="invalid-feedback text-left">
            Please enter your email address in proper format. ([email protected])
          </div>
        </div>
        <!-- phone -->
        <div class="form-group row">
          <label for="Phone" class="form-label text-right">Phone:<sup class="text-danger">*</sup></label>
          <input id="phone" name="phone" type="tel" placeholder="(555) 555-5555" class="form-control input-md" onInput="this.value = phoneFormat(this.value)" />
          <div class="valid-feedback">
            Looks good!
          </div>
          <div class="invalid-feedback text-left">
            Please enter your phone number.
          </div>
        </div>
        <!-- Day of Event Phone -->
        <div class="form-group row">
          <label for="eventPhone" class="form-label text-right">Day of Event Phone:<sup class="text-danger">*</sup></label>
          <input id="eventphone" name="eventphone" type="tel" placeholder="(555) 555-5555" class="form-control input-md" onInput="this.value = phoneFormat(this.value)" />
          <div class="valid-feedback">
            Looks good!
          </div>
          <div class="invalid-feedback text-left">
            Please enter your day of event phone number.
          </div>
        </div>
        <!-- business function -->
        <div class="form-group row">
          <label for="Function" class="form-label text-right">Business Function:<sup class="text-danger">*</sup></label>
          <input id="Function" name="Function" placeholder="Business/Organization Function" type="text" class="form-control" style="text-transform: capitalize;" required>
          <div class="valid-feedback">
            Looks good!
          </div>
          <div class="invalid-feedback text-left">
            Please enter the Business/Organization Function.
          </div>
        </div>
        <!-- booth size -->
        <div class="form-group row mt-5">
          <div class="col-12 text-center">
            <strong>REQUESTED VENDOR AREA SIZE</strong><sup class="text-danger">*</sup>
          </div>
        </div>
        <div class="form-group row">
          <div class="col-12 text-center my-auto">
            <input class="align-center" type="radio" name="VendorSize" value="10" required> 10' x 10' - $25<sup>*</sup><br>
            <input class="align-center" type="radio" name="VendorSize" value="20"> 20' x 10' - $40<sup>*</sup><br>
            <input class="align-center" type="radio" name="VendorSize" value="30"> 30' x 10' - $50<sup>*</sup>
          </div>
          <div class="valid-feedback">
            Looks good!
          </div>
          <div class="invalid-feedback text-center">
            Please select your requested area size.
          </div>
        </div>
        <!-- is vendor selling? -->
        <div class="form-group row mt-5">
          <div class="col-12 text-center">
            <strong>Will vendor be selling at the event?<sup class="text-danger">*</sup></strong>
          </div>
        </div>
        <div class="form-group row">
          <div class="col-12 text-center my-auto">
            <input class="align-left" type="radio" name="Sales" id="salesyes" value="Yes" required> Yes
            <input class="align-left ml-5" type="radio" name="Sales" id="salesno" value="No"> No
          </div>
          <div class="valid-feedback">
            Looks good!
          </div>
          <div class="invalid-feedback text-center">
            Please select Yes or No.
          </div>
        </div>

        <!-- State Sales Tax certificate -->
        <div id="statesales" style="display:none">
          <div class="form-group row">
            <div class="col-12 text-left font-italic text-danger mb-4">
              Some notice stuff here.
            </div>
          </div>
          <div class="form-group row">
            <label for="StateTaxNumber" class="form-label text-left">State Sales Tax Number:<sup class="text-danger">*</sup></label>
            <input id="StateTaxNumber" name="StateTaxNumber" placeholder="State Sales Tax Number if applicable" type="text" class="form-control">
            <div class="valid-feedback">
              Looks good!
            </div>
            <div class="invalid-feedback text-left">
              Please enter State sales tax number.
            </div>
          </div>

          <!-- details -->
          <div class="form-group row">
            <label for="Details" class="form-label">Please describe product or service for sale:<sup class="text-danger">*</sup></label>
            <textarea id="Details" name="Details" cols="40" rows="5" class="form-control"></textarea>
            <div class="valid-feedback">
              Looks good!
            </div>
            <div class="invalid-feedback text-left">
              Please enter your details.
            </div>
          </div>
        </div>
        <!--./end display-none -->

        <!-- requirements & restrictions -->
        <div class="form-group row mt-5">
          <div class="col-12 text-center">
            <strong>REQUIREMENTS and RESTRIFCTIONS:</strong>
          </div>
        </div>
        <div class="form-group row mb-5">
          <div class="col-12 text-left">
            <ul><strong>
                                        <li> Vendors are required to be completely set up and show-ready no later that 11:30 AM
                                        <li> Vendors are responsible for all of their tables, chairs, tents, etc. We will not have these supplies available.
                                    </strong></ul>
          </div>
        </div>
        <!-- recaptcha -->
        <div class="form-group row justify-content-center">
          <div class="col-12 text-center">
            <div class="g-recaptcha d-inline-block" data-sitekey="1234" data-callback="recaptchaCallback" data-action='submit'></div>
            <input type="hidden" class="hiddenRecaptcha required" name="hiddenRecaptcha" id="hiddenRecaptcha">
          </div>
        </div>
        <!-- agree to regulations / restrictions -->
        <div class="form-group row justify-content-center">
          <div class="col-10 text-center my-auto text-danger">
            <input type="checkbox" name="validateSend" id="validateSend" value="1" onclick="countChecked();" /><sup class="text-danger">*</sup>
            <i>I have read and understand all the Park's rules and regulations as well as the Requirements and Restrictions listed above.<sup class="text-danger">*</sup>
                                    <div class="valid-feedback">
                                        Looks good!
                                    </div>
                                    <div class="invalid-feedback text-left">
                                        Please enter your details.
                                    </div>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-12">
                                    <button name="submitall" id="submitall" type="submit" class="btn btn-lg btn-danger  mt-4 ml-2 text-center" disabled="disabled">Send Request</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <script src="https://www.google.com/recaptcha/api.js"></script>

Typescript Library Working in Angular App, but not when Used With Webpack for Background Script: (TYPED_ARRAY_SUPPORT) Undefined

I am using the library https://github.com/ts-bitcoin/ts-bitcoin successfully in an angular application, however, when I try to use this in a background script (serviceworker.ts) for a chrome extension the script throws (TYPED_ARRAY_SUPPORT) undefined.

I am using webpack on the background script which is written in typescript (serviceworker.ts) to output into a javascript file (serviceworker.js). The background script only breaks when I try to call a function from this library. Otherwise, it works fine. I am wondering if I am missing something in my webpack file or if I need to rebuild the library in a different format or something. Any thoughts or comments would be helpful here.

webpack.config.js

const { CheckerPlugin } = require('awesome-typescript-loader');
const { join } = require('path');

module.exports = {
  mode: 'development',
  devtool: 'inline-source-map',
  entry: {
    contentPage: join(__dirname, 'src/contentPage.ts'),
    serviceWorker: join(__dirname, 'src/serviceWorker.ts')
  },
  module: {
    rules: [
      {
        test: /.ts?$/,
        use: 'ts-loader',
        exclude: join(__dirname, '/node_modules/')
      }
    ],
  },
  output: {
    path: join(__dirname, '../angular/dist'),
    filename: '[name].js',

  },
  plugins: [new CheckerPlugin()],
  resolve: {
    extensions: ['.ts', '.js']
  }
};

Reactivity on props Vue.js

I am in the beginning of learning Vue, and having a hard time understanding how to define props etc. using the composition API.

I have a component (ACE Editor), loaded like this:

<v-ace-editor
    v-model:value="currentRecord.text"
/>

The v-ace-editor needs to have the model and value loaded like this: v-model:value.

import {computed, ref} from 'vue';
import collect from "collect.js"

const props = defineProps({
    records: {
        type: Object,
    },
})

//Get all records.
let getRecords = () => {
    return collect(props.records)
}

//Filter the records using "collect.js"
const getUnlabeledRecords = () => {
    return getRecords()
        .where('skipped', false)
        .where('processed', false);
}

//Assign all unlabeled records on the first load.
let allRecords = ref(getUnlabeledRecords());

//In order to check if "text" is empty - and if not, set a default value, load the first record into a temp. variable.
let first = allRecords.value.first();
if(first){
    first.text ??= "";
}

//Load the current record into a ref.
let current = ref(first);

//Finally, compute it.
let currentRecord = computed(() => current.value)

Looking at this, and coming from a backend background, it feels very bloated.

I have tried the following:

let allRecords = ref(getUnlabeledRecords());
let currentRecord = computed(() => allRecords.value.first())

But doing this leads to me not being able to interact with the currentRecord – nor change the allRecords. This means that if for example currentRecord.text is null from the backend, my ace-editor component fails because it expects a value.

Is there another way to load in these variables?

Angular Error trying to diff ‘[object Object]’. Only arrays and iterables are allowed

I have issue with this “Error trying to diff ‘[object Object]’. Only arrays and iterables are allowed” when i want to get my products in html

Here is my product.ts

export interface Pizzas{
  _id:string;
  name: string;
  description: string;
  grade: number;
  price: number;
  discount: boolean;
  picture: string;
} 

Here is my service.ts

import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import {Pizzas} from './product';
import { catchError, Observable, throwError} from 'rxjs';
import {tap} from 'rxjs/operators';


@Injectable({
  providedIn: 'root'
})
export class ProductsService {

  private url ='http://localhost:3000/api/pizzas';

  constructor(private http:HttpClient) { }

  

  getProducts(): Observable<Pizzas[]>{
    return this.http.get<Pizzas[]>(this.url).pipe(tap(data => console.log('All ', JSON.stringify(data))),
    catchError(this.handleError)
    ); 
  }
}

In this console.log everything looks fine, it shows data from json file

Here is my component.ts

import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
import {Pizzas} from './product';
import {ProductsService} from './products.service'



@Component({
  selector: 'app-products',
  templateUrl: './products.component.html',
  styleUrls: ['./products.component.css']
})
export class ProductsComponent implements OnInit {
  errorMessage: string =' ';
  sub!: Subscription;

  
  products : Pizzas[] =[];

  constructor(private producstService: ProductsService){ }
     
  

  ngOnInit(): void {
    
    this.sub = this.producstService.getProducts().subscribe({
      next: products => {
        this.products = products;        
      },
      error: err => this.errorMessage =err
    });
  }

}

And here is my html

<div *ngFor="let product of products">
  <p> {{product.name}}</p>
</div>

discord.js check if user has permissions

I want a command that can only be used by people who have the ban permission
current code:

if(msg.member.guild.me.hasPermission('BAN_MEMBERS'))
    {
      msg.channel.send("hi")
    } else {
      msg.channel.send("You do not have permission to use this command")
    }

I get the error:
msg.member.guild.me.hasPermission is not a function

What am I doing wrong?