Can I/do I need to skip function declarations when using the JavaScript for…in loop? [closed]

I’m rewriting some standalone functions that create and adjust the properties of several objects to now be properties of those objects themselves – mostly as an experiment as it’s not something I’ve really tried before.

One of these functions operates over the properties of the object with a for...in loop. How is this going to interact with the functions, including itself, that are now properties of the object?

I’m guessing it will try to perform the code in the loop on the functions as well, which is not written to handle functions. If that’s the case, what’s best way (if there is a “best way” of what I’m doing) of avoiding that problem?

I’m thinking that perhaps another object within the object to store the data generated at runtime would be reasonable – then I could just perform the for…in on that.

Thanks in advance.

The key section of code, simplified:

// An object to hold separate Inventory Adjustments by date
const inventoryAdjustments = { 
  adjustCorrespondingCodes: (adjustment) => {
    // Other function code
  },
  save: (user) => {
    try {
      for (const inventoryAdjustment in this) { // The for...in loop
        this[inventoryAdjustment].save();
      }
      return true;
    } catch (e) {
      // Error handling
      return false;
    }
  }
};

Trouble opening a popup with dynamic HTML

I am attempting to create a new page thru script. I made the following code to test the idea, but clicking my button does NOTHING!

<html>

<head></head>

<body>
  <input type="button" name="submit" id="chart" value="Chart" onclick="mchart()">
</body>

<script>
  function mchart() {
    var w = window.open("", "", "");
    w.document.writeln("<!doctype html><html><head></head><body>");
    w.document.writeln("<h1>Hello World</h1>");
    w.document.writeln("</body></html>");
  }
</script>

I expected a new page to pop up with the text ‘Hello World’, but instead, nothing happens. 馃檨

Javascript blazor not detecting delete or empty filter on filter table

I have a table in blazor.

I have a header filter like so

<input type="text" @oninput=>"filter" placeholder="filter" />

This triggers a function lets say

Public async task filter()
{
  JS.jsInvokejavascriptasync("filterTable");

}

This calls my filtertable function in javascript.

The code logic for filtering a table works perfectly

My only issue is that it does not pick up when ai clear my filter. Ie when I press delete to clear the 1 character in the filter the function to filter again does not get triggered

I have tried to add an eventlistener on javascript to detect a delete or backspace on input but it has not triggered the filter

Function jsfile()
{  

 //if textfilter==="" 
 //return all rows back again

 //otherwise filter for value
}

My logic inside for filtering works just the table does not reset when you clear the filter using the delete key.

Is there something that can be done to enable the filter function to trigger when you clear the filter by using delete
Any help would be appreciated thanks

DB design for a rating system with dynamic template

I work on a dynamic rating system that allows admins to design their own rating template for their products. The rating template structure is like this

rating > category > item

When an user rates items across categories the mean value is calculated per categories and the weighted mean (categories have weights) is calculated per rating.

I came up with something like this

> entity --> entity_ratings  <-- rating_template   (rating name from here)
>                |                         |
>                |                         |
>                V                         V
>       entity_rating_category <---  rating_category  (category name & weight from here)
>  (i keep the calculated score here)     |
>                |                        |
>                V                        V
>       entity_rating_item  <----   rating_item  (item name from here)
>  (i keep the user rated score here)

but i feel that this is too many redundant relations and there should be a better way

How to reuse full-featured Deno in my Rust project?

I’m trying to implement a JS plugin system for my project that uses Deno underground (for its comprehensive permission model). I expect it to provide Node.js-like JS runtime and Rust 鈫愨啋 JS communication.

I tried deno_core, but it doesn’t even support setTimeout. And deno is executable.


I don’t think this question is “seeking 3rd party libraries”. Deno is an open source JS runtime, I’m finding a way to reuse it in my project – that’s it, no “3rd party” libraries.

Issue with Azure Storage Account Creation Using JavaScript SDK

I’m trying to create an Azure Storage Account using the JavaScript Azure SDK. However, despite explicitly setting accessTier to Cool and configuring networkAcls to restrict access to a specific VNet, the storage account is being created with:

  1. Access tier: Hot (instead of Cool)
  2. Public network access: Enabled from all networks (instead of being restricted)
const vnetId = `/subscriptions/<your-subscription-id>/resourceGroups/<your-resource-group>/providers/Microsoft.Network/virtualNetworks/<your-vnet>/subnets/<your-subnet>`;

const accountParams = {
    sku: { name: "Standard_LRS" },
    kind: "StorageV2",
    location: location,
    properties: {
        supportsHttpsTrafficOnly: true,
        minimumTlsVersion: "TLS1_2",
        accessTier: "Cool",
        routingPreference: {
            publishInternetEndpoints: true,
            publishMicrosoftEndpoints: true,
            routingChoice: "MicrosoftRouting",
        },
        allowBlobPublicAccess: false,
        allowSharedKeyAccess: true,
        defaultToOAuthAuthentication: false,
        publicNetworkAccess: "Enabled",
        allowCrossTenantReplication: false,
        encryption: {
            keySource: "Microsoft.Storage",
            services: { blob: { enabled: true }, file: { enabled: true }, table: { enabled: true }, queue: { enabled: true } }
        },
        networkAcls: {
            bypass: "AzureServices",
            defaultAction: "Deny",
            ipRules: [],
            virtualNetworkRules: [{ id: vnetId }]
        }
    }
};

References:

  1. https://stackoverflow.com/a/77907105/13173270
  2. https://learn.microsoft.com/en-us/rest/api/storagerp/storage-accounts/create?view=rest-storagerp-2023-01-01&tabs=JavaScript#

Question:
Why is the accessTier defaulting to Hot instead of Cool, and why is publicNetworkAccess set to Enabled from all networks despite my networkAcls configuration? How can I fix this?

Thanks!

Script for sending checkbox results from Webflow into Mailchimp

I’m not a developer, so I find myself in too deep and needing your help. I’ve copied some Javascript code from a tutorial that provided a solution to my problem. https://www.youtube.com/watch?v=fODh4b-OtRw But it’s not working. Could be because I haven’t used all elements (radio buttons & dropdown too) from the tutorial and that’s messed it up, or perhaps just a little tweaking required as per the 6 errors listed in Debug. Wondered if anyone has any ideas?

Debug errors

2 pieces of code used in Webflow

<script>

// when the DOM is ready
$(document).ready(function() {

    // create variables for our form elements in designer

    // get the checkbox fields
    const formCheckboxes = $('.form-radio');

    // create variables for our hidden text fields that will be submitted
    
    // get the Blogs hidden input field
    const blogsInp = $('input[name=BLOGS]');
    // get the Webinars hidden input field
    const webinarsInp = $('input[name=WEBINARS]');
    // get the Newletters hidden input field
    const newsletersInp = $('input[name=NEWSLETERS]');
    // get the From our CFO hidden input field
    const cfoInp = $('input[name=CFO]');
    // get the FAQs hidden input field
    const faqsInp = $('input[name=FAQS]');
    // get the Events hidden input field
    const eventsInp = $('input[name=EVENTS]');

    // on submit button click
    $('.subscribe-button').click(function(e){
        //prevent default behaviour
        e.preventDefault();
        
    // CHECKBOXES
    // set the checkboxes hidden input fields values

    // make an array of the hidden inputs representing the checkboxes
    const checkboxHiddenFields = [blogsInp, webinarsInp, newsletersInp, cfoInp, faqsInp, eventsInp];

    //for each checkbox
    formCheckboxes.each(function(index, checkbox){
        // check if it's checked (true) nor not (false)
        let status = $(this).find('input').is(':checked');
        //set the value to the respective checkbox
        // in order from the first checkbox[0]
        checkboxHiddenFields[index].val(status);
    });


    // submit the form
    $('.form-radio').submit();
  });

});

</script>

Angular JS Angular 18 hybrid routing

I have an angular js/angular 18 hybrid application which is working, but what I am trying to do is migrate the routes of the customer users like this:

.state('customer', {
                url: "/customer",
                abstract: true,
                template: "<app-side-menu></app-side-menu>",
                data: {
                    role: 2
                }
            })

And this is how I have the routes defined in the app side menu component:

import { Routes } from '@angular/router';
import { SideMenuComponent } from './customer/side-menu/side-menu.component';
import { HomeComponent } from './customer/home/home.component';

export const customerRoutes: Routes = [
  {
    path: 'customer',
    component: SideMenuComponent,
    children: [
      { path: 'home', component: HomeComponent },
      { path: '', redirectTo: 'home', pathMatch: 'full' }
    ]
  }
];

And this is how I defined the app side menu component:

import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatSidenavModule } from '@angular/material/sidenav';
import { RouterModule } from '@angular/router';
//header
import { HeaderComponent } from '../../layout/header/header.component';
// menu
import { MenuComponent } from '../../layout/menu/menu.component';
// footer
import { FooterComponent } from '../../layout/footer/footer.component';
import { CustomerRoutingModule } from './customer.routing.module';



@Component({
  selector: 'app-side-menu',
  standalone: true,
  imports: [HeaderComponent, MenuComponent, FooterComponent, MatSidenavModule, RouterModule, CustomerRoutingModule, CommonModule],
  templateUrl: './side-menu.component.html',
  styleUrl: './side-menu.component.less'
})
export class SideMenuComponent {
  open: boolean = false;
}

But the problem is that no routes are being rendered for the customer, for example, if i navigate to customer/home, the home component should be rendered but it isn’t.

Disguise a php-produced link with JavaScript

I see bots accessing print pages in an SMF forum (bots not respecting robots.txt, the print link is the print icon, penultimate from the right), is there a way to stop them from doing that? For example changing the print link code from plain URL to a JavaScript produced one? This is how the print link is constructed (From theme’s Display.template.php file), I guess the ?action=printpage;topic= needs to be adapted somehow or the whole string?

// Build the normal button array.
.....
'print' => array('text' => 'print', 'image' => 'print.gif', 'lang' => true, 'custom' => 'rel="new_win nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'),
    );

How to make focus-within work in safari on mac IOS

I’ve created a css only dropdown filter (that opens on click instead of hover). I used :focus-within to accomplish this. I tought this was a crossbrowser-safe property, because Can I Use states that the support is exelent and there are no known issues (https://caniuse.com/css-focus-within).

But during testing an issue is found when using this property on mac IOS in safari, like iphone but also on desktop (even in the latest version, 18 on sequoia).

When the button is used, the focus-within on the parent is not triggered, so the list does not show.

I have found a ‘fix’: it does work when I add tabindex=”0″ to the button.

But I do not want to use tabindex as it breaks the natural tab order flow and will harm accessibility.

I’ve created an example on codepen:
https://codepen.io/marloesg/pen/MYWmJNY

The first button is without tabindex, the second one has the tabindex property (and works in safari).

<nav class="filter-switch-navigation filter-month-switch-navigation" role="navigation" aria-label="Choose month">
                    <button type="button" aria-expanded="false" aria-controls="activities-filter__types" class="btn-filter-toggle">

                            <span class="filter-text">Filter by month (does not work in safari)</span>

                    </button>
                    <ul class="overview-filters-list overview-museums-filters__types" id="activities-filter__types">
                            <li><a href="#april">April</a></li>
            <li><a href="#may">May</a></li>
            <li><a href="#june">June</a></li>
  </ul>
            </nav>

<nav class="filter-switch-navigation filter-month-switch-navigation" role="navigation" aria-label="Choose month">
                    <button tabindex="0" type="button" aria-expanded="false" aria-controls="activities-filter__types2" class="btn-filter-toggle">

                            <span class="filter-text">Filter by month (works in safari with tabindex)</span>

                    </button>
                    <ul class="overview-filters-list overview-museums-filters__types" id="activities-filter__types2">
                            <li><a href="#april">April</a></li>
            <li><a href="#may">May</a></li>
            <li><a href="#june">June</a></li>
  </ul>
            </nav>

.filter-switch-navigation  {
  position: relative;
  will-change: transform;
  transition-duration: 0.3s;
  transition-property: transform;
  transform: translateY(0);
  z-index: 10;
  display: inline-block;
  margin-right: 4px;
  margin-bottom: 14px;
  
  // show and hide language dropdown
  .overview-filters-list {
    list-style: none;
    margin: 0;
    padding: 0;
    background: #fff;
    visibility: hidden;
    opacity: 0;
    min-width: 7rem;
    margin-top: 8px;
    padding: 10px 14px;
    position: absolute;
    transition: all 0.5s ease;
    left: 0;
    border-radius: 4px;
    display: none;
    box-shadow: 1px 1px 6px rgba(#000, .3);
    li {
          margin-left: 0;
      padding-bottom: 7px;
      a {
        white-space: nowrap;
        font-size: 0.86em;
        color: green;
        &:hover {
          color: DarkRed;
        }
      }
    }
  }

  // &:hover .overview-filters-list ,
  &:focus-within .overview-filters-list,
  .btn-filter-toggle:focus + .overview-filters-list,
  .overview-filters-list:focus,
  .overview-filters-list:hover {
    visibility: visible;
    opacity: 1;
    display: block;
  }


// button styling
  .btn-filter-toggle {
    border: 1px solid orange;
    border-radius: 4px;
    background-color: #fff;
    box-shadow: none !important;
    color: orange;
    line-height: 20px;
    position: relative;
    top: 1px;
    margin-bottom: 0 !important;
    margin-right: 10px !important;
    outline: 1px solid transparent;
    // border: 1px solid;
    transition: .5s ease;
    transition-property: border-color, opacity, outline;

    &:hover,
    &:focus {
      outline: 1px solid #fff;
      color: purple;
    }
  }
  .filter-text {
    font-size: 0.96em;
    padding: 4px;
    display: block;
  }
}

**Is there anyone who has found an alternative solutution?
**
(I know I can create a javascript triggered dropdown, but I would rather use this lightweight css solution for all browsers, so I am looking for a solution to trigger the :focus-within on safari. Maybe I should just add javascript for safari? But the :focus-within property should work according to specs)

highcharts exporting pdf with Hebrew series

I am using highcharts in C# .net application with javascript.

The code that overrides the behavior of highchart call (for test):

var originalHighcharts = $.fn.highcharts;

$.fn.highcharts = function (options) {
    var additionalSettings = {
        series: [{
            name: `${'注讘专讬转'}`, // Hebrew series name
            dataLabels: {
                enabled: true,
                useHTML: true,
                style: {
                    direction: 'rtl',
                    unicodeBidi: 'bidi-override',
                    textAlign: 'right'
                }
            }
        }],
        plotOptions: {
            series: {
                shadow: false
            }
        },
        exporting: {
            fallbackToExportServer: false,
            pdfFont: {
                normal: '/Content/fonts/DavidLibre-Regular.ttf',
                bold: '/Content/fonts/DavidLibre-Bold.ttf',
                italic: '/Content/fonts/davidLibre-medium.ttf'
            },
            chartOptions: {
                chart: {
                    style: {
                        fontFamily: 'DavidLibre, Tahoma, sans-serif'
                    }
                },
                lang: {
                    decimalPoint: ',',
                    thousandsSep: '.',
                    rtl: true
                }
            }
        },
        lang: {
            decimalPoint: ',',
            thousandsSep: '.',
            rtl: true
        },
        chart: {
            styledMode: false,
            style: {
                fontFamily: 'DavidLibre, Tahoma, sans-serif',
                direction: 'rtl'
            }
        },
        title: {
            useHTML: true
        }
    };

    options.series = {};
    var newOptions = $.extend(true, {}, options, additionalSettings);

    // Call the original highcharts function with the merged options
    return originalHighcharts.call(this, newOptions);
};

The DavidLibre is for Hebrew font (ttf files).

The pdf is export fine, except that the word 注讘专讬转 is shown swapped when pdf is exported (转讬专讘注) in the pdf file.
When the word is a word in English, it is shown OK.

For png files – the export is also fine.

Why pdf show the Hebrew word in reverse order and how to fix that? (without reversing the string itself, since there are also words in English).

Global event handlers for HTMX

I can define inline event handlers for various htmx events like so:

<button hx-on:htmx:after-request="..."
        hx-on:htmx:response-error="..."
        class="foo"
        >Load</button>        

But is it possible to define “global” event handlers?

For example, when a user loses his network connection, I’d like to show a toast with “Please retry in a few moments” rather than degrading his UX. I could add handlers inline (e.g. hx-on:htmx:after-sendError="...") but I don’t want to do that for every HTMX-enabled element, I’d rather do that once, if possible.

Content script stops listen to background script after some time (Safari)

My extension is designed to control music playback on the music.yandex.by web-site. When user click buton in popup I am passing message from background to content script. While the music is playing, everything works as it should. However, if you stop the music and switch to another tab, after about 5 minutes the content script stops receiving messages, while the background script continues to receive messages.

Here is manifest

{
    "manifest_version": 2,
    "default_locale": "en",

    "name": "__MSG_extension_name__",
    "description": "__MSG_extension_description__",
    "version": "1.0",

    "content_scripts": [{
        "js": [ "content.js" ],
        "matches": [
            "*://music.yandex.by/*"
        ]
    }],
    
    "background": {
        "scripts": ["background.js"],
        "persistent": true
    },
    
    "web_accessible_resources": [
      "images/my-image.png"
    ],
    
    "action": {
        "default_icon": "toolbarItemIcon.pdf",
        "default_title": "袨褌泻褉褘褌褜 携薪写械泻褋 袦褍蟹褘泻褍"
    },
    
    "externally_connectable": {
        "matches": [
            "*://music.yandex.by/*"
        ]
    },

    "permissions": [
        "nativeMessaging",
        "*://music.yandex.by/*"
    ]
}

I use ports to communicate between the background script and the content script.

I believe that after a certain period of time, the inactive page goes into standby mode and disables the content script. Is there any way to bypass this limitation?

I would be very grateful for any advice.

OWASP ZAP and authentication with auth0

i want to automate ZAP logging in to my application with auth0

my application home page i.e. http://example.com redirects to auth0 where there is a login page.

i have setup a dummy script and session context using that script but the script fails to fire.
my auth0 login page is always a dynamic url because of the state querystring i.e.
https://dev-auth.example.co/u/login/identifier?state=hKFo2SBFVDZ3Y0RKMkZ0U0NqLTFOeDF6cjRkVHBWNFN2NDJMZaFur3VuaXZlcnNhbC1sb2dpbqN0aWTZIGVydG82Si1ET0ViNWlyMmFJSGwzMnI4NGNRZ3JxdWpro2NpZNkgeXZsRlFQNFNuUnY0dGhoNkI1RWI1N3QySDdENFRUTXo

any help would be appriciated…

thanks