can’t get to run basic greeter in javascript

Create a greet function that takes name and partOfTheDay parameters and returns a greeting as a string, in English:

greet(‘Paul’, ‘night’); // ‘Good night, Paul!’
greet(‘Mike’, ‘morning’); // ‘Good morning, Mike!’

If only the name is given during the call, set the default value of the partOfTheDay parameter to ‘afternoon’.

greet(‘John’); // ‘Good afternoon, John!’

Call the greet function twice:

first time with arguments Mike and morning;
the second time only with the argument ‘John’.

How should I approach it? Should I use if?

I was trying to use IF but I can’t make it run.

Send a file to a printer to print when user click print button. But the user MUST NOT be able to Download PDF before Printing

Users request to print reports that are generated on the server side. These reports are sent back as PDF files. There is no need to open these files before printing them.
I am using asp.net mvc 5 with js/jq.

NOTE : I KNOW BROWSERS DOES NOT LET US TO DO THIS DUE TO SECURITY REASONS but in my case only people with access can print the report we just need to prevent them from changing the content.

I have already tried different methods but seems chrome and other popular browsers do not let websites send print requests to printer without going through the print popup(ctrl + p) on chrome.
I do not mind the print popup so the user can still initiate the print.

BUT THE PROBLEM IS THERE IS AN OPTION TO SAVE/DOWNLOAD THE FILE on the print popup(ctrl + p).
There are security issues because the user can use a PDF editor tool and change valuable information like prices, bank account details etc and print the Document.

I tried print.js (https://printjs.crabbly.com/) but it did not work as it also opens print popup and save the option to save.

Currently we send the files to a api send them to printers through api’s. But there are printers that does not support api requests.
Which makes us to make the user choose the printer from the browser and print.

I am pretty much open to any type of suggestions and solutions.
solution can be client side / server side / windows services etc anything pretty much.
Just the user should not be able to tamper with the file before printing.

display ‘no data’ message with icon in ngx-echart

I am trying to fetch ‘no data’ message with icon at the center of ngx-echart but I can only see ‘no data’ message popup with no icon.why?

component.html

 <div>
 <p-card header="Cost By Domain">
 <div echarts [options]="domainoptions" [ngStyle]="{width: '100%',height:'100%'}"> 
 </div>
 </p-card>
 </div>

component.ts

import { EChartsOption } from "echarts";
 echartOptions: EChartsOption = {
    title: {
      subtext: "Data not loaded yet",
      left: "center",
      top: "center",
      subtextStyle: {
        fontSize: 20,

      }
    },
    yAxis: [],
    series: [],
    graphic: [
      {
        type: 'image',
        left: 'center',
        top: 'middle',
        z: 100,
        bounding: 'raw',
        style: {
          image: '../assets/reset.png', 
          width: 150,
          height: 150
        }
      }
    ]
  };

and I have also tried like this,

 echartOptions: EChartsOption = {
      title: {
        text: `<div [innerHTML]="iconHtml"></div>`,
        subtext: "Data not loaded yet",
        left: "center",
        top: "center",
        subtextStyle: {
          fontSize: 20,

        }
      },
      yAxis: [],
      series: []
    }

o/p:
enter image description here

i have a problem in my project mini-blog in javascript [closed]

I have developed a mini blog and you can find the project here. My problem arises when trying to implement a feature where users can add pictures to their blog posts. Currently, I’m using the tag to allow users to upload images, but I’m unsure how to display these uploaded pictures when viewing the blog post.

Could someone please explain the method or provide an example of how I can achieve this task? I would greatly appreciate any guidance or assistance. Thank you!

url my blog for testing : https://adilradidi.github.io/MicroWrite/index.html

When approaching this problem, I first implemented the functionality to allow users to upload pictures using the tag. However, when attempting to display these uploaded pictures when viewing the blog post, I encountered difficulties. I was expecting to be able to simply retrieve the file path or URL of the uploaded picture and use it to display the image in the blog post, but I’m unsure of the exact method to achieve this.

How to scrape page content using fetch API and DOMParser [closed]

I’m looking for a way to scrape a web page using the fetch API. I’ve read Returning HTML With fetch() and the suggested solution seems working correctly, I’ve implemented this in my code

fetch('https://www.testpage.com/')
    .then( (res) => res.text() )
    .then( (html) => {
        const parser = new DOMParser();
        let content = parser.parseFromString(html, 'text/html');
        console.log(content);
    });

After I’ve parsed the HTML and get back the DOM content, how I can target the element inside the markup I want to get the content from? Can I use standard JavaScript methods or I will need to access them from the content variable that hold it inside with some method of the DOMParser?

Lightning chart UI components width and height

I have followed this instructions:

https://lightningchart.com/js-charts/docs/features/ui/

and got this box, I don’t need to put text in it so I just put an empty string ‘ ‘

enter image description here

is it possible to control the width and height of the TextBox?

for example to make the TextBox height to be from
20.0 to 16.0 ?

for example if I want to specify the TextBox dimensions as a rectangle for each point what to be located?

imports

export const CreateLeadChart = (
  dashboard: Dashboard,
  maxYChartBorder: number
) => {
  const BackgroundFill = new SolidFill({
    color: ColorHEX("#ffffff"),
  });

  const LeadChart = dashboard
    .createChartXY({
      columnIndex: 2,
      rowIndex: 0,
    })
    .setSeriesBackgroundFillStyle(BackgroundFill);


  const blacklineSeries = LeadChart.addLineSeries({}).setStrokeStyle(
    (stroke) =>
      new SolidLine({
        thickness: 7,
        fillStyle: new SolidFill({ color: ColorHEX("#212121") }),
      })
  );

  const tipLineSeries = LeadChart.addLineSeries({}).setStrokeStyle(
    (stroke) =>
      new SolidLine({
        thickness: 2,
        fillStyle: new SolidFill({ color: ColorHEX("#BDBDBD") }),
      })
  );

  const dataGray = [
    { x: 2.0, y: 10.52, z: 1 },
    { x: 2.0, y: maxYChartBorder, z: 12 },
  ];


  const dataTip = [
    { x: 2.0, y: 9.52, z: 1 },
    { x: 2.0, y: 8.52, z: 1 },
  ];

  graylineSeries.add(dataGray);
  blacklineSeries.add(dataBlack);
  tipLineSeries.add(dataTip);

  // display blue and red boxes https://lightningchart.com/js-charts/docs/features/ui/
  const axisX = LeadChart.getDefaultAxisX();
  const axisY = LeadChart.getDefaultAxisY();
  const textBox = LeadChart.addUIElement(UIElementBuilders.TextBox, {
    x: axisX,
    y: axisY,
  })
    .setPosition({ x: 2.2, y: 20 })
    .setOrigin(UIOrigins.LeftTop)
    .setVisible(true)
    .setText("      ");

  textBox.setMouseInteractions(false); // preventing from user to drag

  textBox.setBackground((background) =>
    background.setFillStyle(new SolidFill({ color: ColorHEX("#039BE5") }))
  );

  return LeadChart;
};

Document an inherited property dinamically created from parent class in JSDoc?

I’m extending a Controller class which (dynamically) adds a property named clearResultValue:

import { Controller } from '@hotwired/stimulus';

export default class extends Controller {}

I want to document clearResultValue so I can get a basic check of this.clearResultValue in my IDE.

Seems an easy task but it seems not working, at least without redefining the property itself:

/**
 * @property {boolean} clearResultValue
 */
export default class extends Controller {
}

Neither:

export default class extends Controller {
  /**
   * @property {boolean} clearResultValue
   */
}

hidden Answer checking in webassembly

I am trying to us a javascript function in my index.html ,but i keep getting “Uncaught ReferenceError: checkAnswer is not defined
at HTMLInputElement.onclick ((index):18:79)”

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CTF Steganography Challenge</title>
  <link rel="stylesheet" type="text/css" href="index.css">
  <link rel="preload" href="./index.js" as="script" />
  <script type="module" src="./index.js"></script>
</head>
<body>
<h1>Steganography Challenge</h1>
<p>Here is your challenge: [Description of the challenge goes here]</p>
<div class="input-container">
  <input type="text" id="answer" name="myInput" placeholder="Enter your text...">
</div>
<br><br>
<input type="button" value="Submit" id="submitButton" onclick="checkAnswer()">
<div id="result"></div>
</body>
</html>
document.addEventListener('DOMContentLoaded', function() {
    const answerInput = document.getElementById('answer');
    const resultDiv = document.getElementById('result');

    function checkAnswer() {
        const userInput = answerInput.value.trim().toLowerCase();
        if (userInput === "message chiffré") {
            resultDiv.textContent = "Bravo ! Vous avez réussi.";
        } else {
            resultDiv.textContent = "";
        }
    }

    document.getElementById('submitButton').addEventListener('click', checkAnswer);
});

Pass form data to a fetch request?

I’m trying to pass my form data through to the body of the fetch request but its not being received on my API end.

Using Svelte Kit.

export const actions = {
    login: async ({request }) => {
        const data = await request.formData();

        const response = await fetch('http://localhost:1234/auth/login', {
            method: "POST",
            body: data
        });
    }
};

Passing it like this works fine

body: {
    'username': 'test',
    'password': 'woop'
}

How to keep track user changes in database [closed]

So i am in the middle of creating a website. Currently my database sits in PgAdmin and i use postgreSQL. My backend is python oriented (Flask) and the fronted is a mix of AJAX and JS.
Now i came across a step that needs tracking of changes. So i have lets say a row in a table, the row is displayed in the frontend and the user lets say changes the second column and submits the results. The data is parsed and sent to the backend which is sent to the DB.
Is there any other way to keep track of lets say the date of the change (and extra the stuff the user changed) than to either create a new table or keep track of the changes in a private .txt file?
Thank you in advance.

Just a plain question, I am leaning towards the .txt option more and more.

Ask about chrome extensions. How to block file downloads

// background.js
chrome.webRequest.onBeforeRequest.addListener(
  blockDownloads,
  { urls: ["<all_urls>"], types: ["main_frame", "sub_frame"] },
  ["blocking"]
);

function blockDownloads(details) {
  
  if (isDownloadRequest(details)) {
    
    return { cancel: true };
  }
}
// manifest.json
{
  "manifest_version": 3,
  "name": "Block Downloads",
  "version": "1.0",
  "description": "Block all downloads on web pages",
  "permissions": ["webRequest", "webRequestBlocking", "activeTab"],
  "background": {
    "service_worker": "background.js"
  },
  "action": {
    "default_popup": "popup.html",
    "default_icon": {
      "16": "icon16.png",
      "48": "icon48.png",
      "128": "icon128.png"
    }
  },
  "icons": {
    "16": "icon16.png",
    "48": "icon48.png",
    "128": "icon128.png"
  },
  "host_permissions": ["<all_urls>"]
}

Error content

Unchecked runtime.lastError: You do not have permission to use blocking webRequest listeners. Be sure to declare the webRequestBlocking permission in your manifest.

Please help me correct them

I tried to edit them to look like this

{
  "name": "Download Blocker",
  "version": "1.1",
  "description": "Blocks file downloads (declarative approach)",
  "manifest_version": 3,
  "permissions": [
    "declarativeNetRequest",
    "webRequest" // Needed for observing requests
  ],
  "background": {
    "service_worker": "background.js"
  },
  "declarativeNetRequest": {
    "rules": [
      {
        "id": "blockDownloads",
        "priority": 1,
        "condition": {
          "url": {
            "pathSuffix": ".pdf" // Assuming you want to block PDFs
          },
          "types": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xhr", "ping", "other"] // Block all request types
        },
        "action": {
          "type": "cancel"
        }
      }
    ]
  }
}

however there was an error

Unrecognized manifest key ‘declarativeNetRequest’.

Please help me correct them

Convert big size nested array of objects to small chunks of 32kb

How to split big size nested array to small chunks of 32kb.

I tried following way,

const result =    [
  {                                  // This is sample data BUT there can be multiple objects
    "name": "object1",
    "id": "1",
    "timeseriesData": [
      [
        1548979200000,                // epoc timestamp
        325.3                         // value in number
      ],
      [
        1548979260000,
        325.8
      ],
      [
        1548979320000,
        324.2
      ],
      [
        1548979380000,
        323.7
      ],
      [
        1548979440000,
        322.3
      ],
      [
        1548979500000,
        322
      ]
    ]
  },
  {
    "name": "object2",
    "id": "2",
    "timeseriesData": [
      [
        1548989200000,
        625.3
      ],
      [
        1548989260000,
        625.8
      ],
      [
        1548989320000,
        624.2
      ],
      [
        1548989380000,
        623.7
      ],
      [
        1548989440000,
        622.3
      ],
      [
        1548989500000,
        622
      ]
    ]
  }
]

const splitInChunks = (sizeInBytes) =>   // Don't think this is helping to create proper chunks
    (buffer) => {
        console.log(buffer);
        const size = Buffer.byteLength(buffer.buffer);

        let start = 0;
        let end = sizeInBytes;

        const chunks = [];

        do {
            chunks.push(buffer.subarray(start, end));
            start += sizeInBytes;
            end += sizeInBytes;
        } while (start < size);

        return chunks;
    };



const chunks = splitInChunks(32)(Buffer.from(JSON.stringify(result)));

chunks.map(x=>console.log(JSON.parse(JSON.stringify(x))));

But it generates the following output,

I’m looking to build a query builder in React.js [closed]

enter image description here

I’m looking to build a query builder in React.js and I’m seeking recommendations for a suitable package or examples to help me accomplish this. I’ve already tried using react-awesome-query-builder, but I found that I had to make numerous modifications, and it didn’t quite meet my needs. Can anyone suggest a good example or recommend a reliable package for building a visually appealing query builder in React?