Detect if the position of a div crosses the center of the viewport

I am trying to observe and detect if the position of a div crosses the center of my viewport on the y-axis. If so a function should be fired.
I am not scrolling or dragging the element so I can’t use an event listener that listen to those events.
Does anyone know an approach that I could follow?
Please no jQuery solutions, I am using Vue3 so I would wan’t to use plain javascript.

moment js not showing local time it’s showing same in the Database

how to display createdAt field date according to the local timezone. i have tried it’s only working for localhost when I upload it on the server it’s showing createdAt field data UTC format.

here is my code

dateFormatwithSec(date_time) {

    const testDateUtc = moment.utc(date_time);
    const localDate = moment(testDateUtc).local();
    return localDate.format('YYYY-MM-DD HH:mm:ss');
},

why it’s not providing the right output on the server.

Blob file not open in Edge browser on Iphone IOS mobile

Hi All I am not able to dowonload PDF file on Iphone edge browser below is my code snippet in angular.

    const fileName = file.name + '.' + file.data_type;
      const dataType = res.type;
      const binaryData = [];
      binaryData.push(res);
      const blob = new Blob(binaryData, { type: 'application/pdf'});
      // IE
      if (window.navigator && window.navigator.msSaveOrOpenBlob) {
        window.navigator.msSaveOrOpenBlob(blob, fileName);
      } else {
        // other browser
        const downloadLink = document.createElement('a');
        const url = window.URL.createObjectURL(blob);
        document.body.appendChild(downloadLink);
        downloadLink.href = url;
        downloadLink.target = '_blank';
        downloadLink.download = fileName;
        downloadLink.click();
       
      }

It is working on all other browser and devic.Not only working on Edge browser of Iphone

How can I generate all the combos taking into account the weight of each item in Javascript? [duplicate]

I have been struggling for several days with the following algorithm I need.

What I need to generate are the totality of combos taking into account the weight in their generation.

// Generate composition depending on weight.
// The weight is a value from 1 to 100, representing the importance in the generation.
// ex.: A layer with 1% should only display 1% of the total generated.

const layers = [
    [
    { id: 1, weight: 1 },   // Shows 1 time
    { id: 2, weight: 9 },   // Shows 9 times
    { id: 3, weight: 15 },  // Shows 15 times
    { id: 4, weight: 25 },  // Shows 25 times
    { id: 5, weight: 50 },  // Shows 50 times
  ],
  [
    { id: "a", weight: 50 },    // Shows 50 times
    { id: "b", weight: 25 },    // Shows 25 times
    { id: "c", weight: 15 },    // Shows 15 times
    { id: "d", weight: 9 },     // Shows 9 times
    { id: "e", weight: 1 },     // Shows 1 times
  ], 
    [
    { id: "_", weight: 15 },    // Shows 15 times
    { id: "-", weight: 25 },    // Shows 25 times
    { id: ".", weight: 50 },    // Shows 50 times
    { id: ",", weight: 9 },     // Shows 9 times
  ]
  // ... There could be more collections
]

const combTotal = layers[0].length * layers[1].length * layers[2].length // => 100


// Expect result:
 
[ 
  [5, "d", "."], 
  [2, "a", "_"],
  [4, "a", ","],
  // ...
]

Generating the whole composition without weights is simple, but the calculation to take into account the weight is costing me more than it should.

If someone could show me some reference to unlock me, it would be great.

Best regards

IntelliSense not working for dynamically loaded JavaScript files

I have created number of models(separate files) in my NodeJS Project. I am exporting all the files dynamically in single index.js file. Now when I require models folder and try to load the Model Intellisense is not be able to load that Model.

  • Is there any solution to resolve this issue.
  • Expected intellisene Path is const {ModelController} = require('../models')

/models/index.js

'use strict';

const testFolder = './app/models';
const fs = require('fs');
const commons = require('../common');

const ExportsModel = {};
fs.readdirSync(testFolder).forEach((file) => {
  const fileName = file.split('.')[0];
  ExportsModel[commons.capitalizeFirstLetter(fileName) + 'Conrtroller'] = require(`./${fileName}`);
});

// console.info('ExportsModel', ExportsModel);
module.exports = ExportsModel;

/models/station.js

const mongoose = require('../configs/db.configs');
const Schema = mongoose.Schema;

const ModelSchema = new Schema(
  {
    name: { type: String, required: true },
    stationId: { type: Schema.Types.ObjectId, ref: 'station', required: true },
    description: { type: String, required: true },
  },
  { timestamps: true }
);

module.exports = mongoose.model('charger', ModelSchema);

Thank you in advance

VueJS disable outer div scroll and enable again after inner div reached its bottom

I’m doing a webpage with multiple div which placed vertically, and here’s my concept:

  1. When the scrollbar reached the first div bottom, the outer scrollbar will be disabled and enable the second scrollbar
  2. The user have to reach the inner scrollbar bottom in order to enable the outer scrollbar

I tried to found the name as wells as the sample from the Internet, but I can’t really found what I want. So I would like to request any volunteers to help me about my concept.

Opening new window on the latest version of Firefox miss browser tabs

I got a problem with my application, one of the features I have is open a window that has tabs, it works properly on an old version of Firefox 68 and older, the newest one like 91.x.x, it opens a new window but without the toolbar for opening new tabs, Here’s the code I’m using:

const openPage= window.open(Page, "OPP| App", 'location=1,status=1,scrollbars=1, resizable=1, directories=1, toolbar=1, titlebar=1,fullscreen=yes');

how to create view,property in google analytics and cointainer in tag manager on user signup

I am new to google analytics and tag manager

My problem is that i want to create view and property in google analytics when user’s sign up to my website and also i need to create cointainer in Tag manager when user’s sign up to my website

First thing :
i am creating view, property in google analytics using this link developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/profiles/insert#javascript and cointainer in Tag manager using this link developers.google.com/tag-platform/tag-manager/api/v2/reference/accounts/containers/create
but its only working with my gmail

What i want is :

I want to create View,property,cointainer for different users when they signup.

How can i achive that

Thanks for helping

Note: i am using javascript language

Avoid redirect loop in chrome extension

I’ve made a chrome extension that uses an allow list of urls that you can visit, defined in extension option, if not your are redirected to a defined page.

So let say I only allow the site example.com and when visting any other site it will send me back to example.com, BUT if example.com itself redirect to a login page that’s not on the list it will loop. Of course the best way is to add the login page to the allowed list but if I want to avoid this, are there a better approach to stop a redirect loop?

example of code in content script of the extension:

let homepage = "https://example.com";
let allowlist = "https://example.com";

function TriggerAllowSites() {
    let currentUrl = window.location.href;
    let match = currentUrl.match(allowlist);
    if (match && match.length > 0) {
        console.log("We are allowed here");
    } else {
        window.location.href = homepage;
    }
}

TriggerAllowSites()

Checking if multiple strings exist in multiple files

I have a translations file which is a JSON object, which may contain more JSON objects and I need to find missing translations. JSON file ex:

export const locale = {
    lang: 'en',
    data: {
        'NAV': {
            'APPLICATIONS': 'Applications',
            'DASHBOARDS'  : 'Dashboards',
            'CALENDAR'    : 'Calendar',
            'ECOMMERCE'   : 'E-Commerce',
            'ACADEMY'     : 'Academy',
            'MAIL'        : {
                'TITLE': 'Mail',
                'BADGE': '25'
            },
            'MAIL_NGRX'        : {
                'TITLE': 'Mail Ngrx',
                'BADGE': '13'
            },
            'CHAT'        : 'Chat',
            'FILE_MANAGER': 'File Manager',
            'CONTACTS'    : 'Contacts',
            'TODO'        : 'To-Do',
            'SCRUMBOARD'  : 'Scrumboard'
        }
    }
};

and I need to get each translation, which is the lowest level item (ex data.NAV.MAIL.BADGE or data.NAV.APPLICATIONS)and see if it exists in the files directory for my project.

Is it inefficient to open a ton of files, or is that difference negligible as compared to going translation by translation and opening each file (for potentially thousands of files)?

I was thinking of flattening the object recursively so I get one flat object with all keys, getting each file, and checking each string if it exists. If it does, I move it to a different object of found strings so it’s not checked again. Whatever is left in original object is not used. I will also add whatever is in the git ignore to be ignored here as it is not relevant. Is there anything to make this more efficient that I may be missing?

Error in file Handling in NodeJS : ‘MODULE_NOT_FOUND’

//load the module
let fs = require("fs");
let message = "Welcome to simple file handling program using Node JS";
fs.writeFile("demo1.txt",message,(err) =>{
    if(!err){
        console.log("Information stored in file successfully");
    }
    else{
        console.log(err);
    }
});

I am getting the following error in the above Node JS program:

C:UsersDellOneDriveDocumentsPhase – 3Node JS ProgramsFs Module Programs>node AsyncWriteOperations.js
node:internal/modules/cjs/loader:936
throw err;
^

Error: Cannot find module 'C:UsersDellOneDriveDocumentsPhase - 3Node JS ProgramsFs Module ProgramsAsyncWriteOperations.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Groovy (or Java): How to escape double quotes only within HTML inner text, not in attributes

I am using a HTML rendering engine based on Groovy within a WCM system.
I now have the use case, that the user enters rich text content within a TinyMCE-based form, which looks like this:

<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
    <span style="text-decoration: underline;"
        sed diam nonumy
    </span> eirmod "tempor" invidunt ut labore et...
</p>

Within my Groovy renderer, I now want to feed this HTML snippet into the HTML document’s content to client-side JavaScript processing.

What I need to do is:
Escape double quotes WITHIN content (see “tempor” token above), but not those encapsulating HTML attribute values (see “text-decoration” attribute above).

If I do

myHTML.replace(""", "&quot;")

I will in fact escape EVERY double quote.

Any suggestions how I can only escape the quotes WITHIN the real text?