Get element in an HTML document within another HTML document

I am trying to write a Chrome extension that can read a url that is hidden in the html document of a specified webpage. Somewhere in the HTML is a ‘resizing-iframe’ with the tag ‘d2l-iframe-wrapper-for-react’, which has a ‘src’ attribute that I want to read (see bottom picture). However, using document.getElementsByTagName doesn’t work, and I suspect it is because somewhere in the HTML document, there is an iframe that itself contains an HTML document, and that one contains the element that I need (see top image). My question is: how do I get this element from this inner HTML document?

I need something like this:

var innerDocumentWrappingDiv = document.getElementsByClassName('d2l-fra-iframe')[0];
var innerDocument = innerDocumentWrappingDiv.firstChild; // the iframe containing the document
var elementThatIsNeeded = innerDocument.getElementsByTagName("d2l-iframe-wrapper-for-react")[0]; 

However this doesn’t work because innerDocument is not recognized as an actual document. Any help is much appreciated!

html doc

src

How to get DOM elements height and check if they will fit into PDF page?

I have a page with e.g. posts and I want to print them… but there is a problem. If I click print, some posts go outside the PDF page and some content have been lost. So maybe someone know how to avoid it? I have an idea that it can be possible to get every DOM elements height and check if they fit to page but I don’t really know how to achieve it… So maybe there is another solutions?

How can I inner join with two object arrays in JavaScript? [closed]

I need inner join with two array in javascript like this:

array1 = 
[
  {
    "id": 1,
    "name": "Tufan"
  },
  {
    "id": 2,
    "name": "Batuhan"
  },
  {
    "id": 3,
    "name": "Hasan"
  }
]

array2 = 
[
  {
    "name": "yyy",
    "externalid": "1",
    "value": "Asd"
  },
  {
    "name": "aaaa"
    "externalid": "2",
    "value": "Asd"
  }
]

expectedArray = 
[
  {
    "id": 1,
    "name": "Tufan",
    "externalid": "1",
    "value": "Asd"
  },
  {
    "id": 2,
    "name": "Batuhan",
    "externalid": "2",
    "value": "Asd"
  }
]

rules:

  1. on: array2.externalid = array1.id
  2. select: array1.id, array1.name, array2.externalid, array2.value

How can I make this?

Doesn’t matter information: I use ES5 and pure javascript

can we use another field in mongoose model to populate like email or somthing unique

// this is my model for city

const mongoose = require(‘mongoose’);

const Schema = mongoose.Schema;

let CitySchema = new Schema({

city_id: {
    type:Number,
    required:true
},
name: {
    type:String,
    required:true
},
state_id: {
    type:Number,
    ref:'state'
},
state_code: {
    type:String,
    required:true
},
country_id: {
    type:String,
    required:true
},
country_code: {
    type:String,
    required:true
},

})
module.exports = mongoose.model(‘city’,CitySchema);

// model for state

const mongoose = require(‘mongoose’);

const Schema = mongoose.Schema;

let StateSchema = new Schema({

state_id: {
    type:Number,
    required:true
},
name: {
    type:String,
    required:true
},
country_id: {
    type:Number,
    required:true
},
country_code: {
    type:String,
    required:true
},
iso2: {
    type:String,
    required:true
},
city: {
    type:[Schema.Types.ObjectId],
    ref:'city'
}

})

module.exports = mongoose.model(‘state’,StateSchema)

// controller

exports.getCity = async (req, res, next) => {

const city = await City.find().populate('state_id')

res.send(city)

}

Javascript – Add new object into array of objects

please. I have a cycle with fiance balances. It’s an array of objects like:

export const balances = [
type: types.outgoing,
    date: 20220410,
    amount: 282.12,
    category: categories.installments,
    source: 'Debit account',
    destination: 'Leasing company',
  },
  {
    type: types.income,
    date: 20220413,
    amount: 1385.3,
    category: categories.job,
    source: 'My employeer',
    destination: 'Debit account',
  },
  ...
]

etc…

As you can see, I have a categories there which means that I have in cycle every transaction in balances and I must create separate category for each of them with total amount for each category, count of items in category and with detailed transactions for each category. I’m using array.forEach() cycle:

balances.forEach((balance) => {

  // Checking if category already exists in my array of categories
  let categoryIndex = categories.findIndex((category) => category.category === balance.category)

  // Create details of transaction
  let transactionDetail = {
    date: balance.date,
    amount: balance.amount,
    source: balance.source,
    destination: balance.destination,
  }

  // If category already exists, just calculate total and add new object into array details
  if (categoryIndex !== -1) {
    console.log([categories[categoryIndex].details])
    categories[categoryIndex] = {
      type: balance.type,
      category: balance.category,
      amount: categories[categoryIndex].amount + balance.amount,
      count: (categories[categoryIndex].count += 1),

      // This row is wrong. I cannot use this
      details: [categories[categoryIndex].details].push(transactionDetail),
    }
  } else {
    // If category doesn't yet exists, we must create a first values in this category
    categories.push({
      type: balance.type,
      category: balance.category,
      amount: balance.amount,
      count: 1,
      details: [transactionDetail],
    })
  }
}

But the row

details: [categories[categoryIndex].details].push(transactionDetail)

doesn’t work properly. Probably the reason is, that I have sometimes Object as tyopeof result and sometimes undefined

Row console.log([categories[categoryIndex].details]) sometimes output:

// Output for
// console.log([categories[categoryIndex].details])
[Array(1)]0: Array(1)
0: {date: 20220414, amount: 410, source: 'xxx', destination: 'yyy'}
length: 1[[Prototype]]: 
Array(0)length: 1
[[Prototype]]: Array(0)

[2]
0: 2
length: 1
[[Prototype]]: Array(0)

Any hiths how can add object transactionDetail as a next in existing array? Thank you very much for any advice.

I don’t understand. I can concat string if category already exists, add numbers but I cannot add an next object into array of objects.

EDIT: Just changed transaction to trasactionDetail in explanation.

Get Firebase child value in JavaScript

I want to only get a specific child value from Firebase using JavaScript.
I always get the entire child values.

This is what it looks like:

Child a -
        |- fcmToken: 'abcdefg'

Child a -
        |- fcmToken: 'hijklmn'

I always get the entire thing. "Child a – fcmToken: 'abcdefg'"
But I only want to get the fcmToken value 'abcdefg' and 'hijklmn'

Ho can I do so?

I tried this:

return admin.database().ref('/fcmToken').once('value', snapshot => {

var uid = snapshot.val();

return admin.database().ref('/fcmToken/' + uid).once('value', snapshot => {

  var fcmToken = snapshot.val();
  console.log('FCMTOKEN:', fcmToken)

});

But it’s not working. Any ideas, how I can only get the desired values 'abcdefg' and 'hijklmn'

Is there any way to catch keypress events in mobile browser keyboard?

(my first question): I built a filter functionality for a list of banks. It works fine in desktop. User put anyname , keypress event occurs and later it call a FILTER function. But it doesnot work in mobile , since there is no keypress event exist. Exist??.
Goal is to whenever user put any letter in input filed it should call that FILTER function in mobile. Is there any way?
(this website is built on wix so it use its velo api)

let debounceTimer;

export function search_keyPress(event) { //enable onKeypress for input form , search is the id of input

$w("#clearSearch").show(); //show the cross mark to clear inputs

$w("#search").value; // value of input field

    if (debounceTimer) {
        clearTimeout(debounceTimer);
        debounceTimer = undefined;
    }
    debounceTimer = setTimeout(() => {
        filter($w("#search").value); //ID of input form
    }, 200);

}

let searchWord;

function filter(search) {
    if (searchWord !== search) {
        $w("#bankTableDataset").setFilter(wixData.filter().contains('bankName', search)); // ID of the dataset
        searchWord = search;
    }


}

Getting parse error while fetching text file content in JQuery

I am trying to fetch data from text file which resides on server. I have access of that location and able to see content when I put URL in browser tab.
I am trying to make AJAX call and get file content, but I am getting Error: Uncaught SyntaxError: Unexpected identifier

Code

    function logResults(json){
  console.log(json);
}

$.ajax({
  url: u,
  dataType: "jsonp",
  jsonpCallback: "logResults"
});

enter image description here

on console,
enter image description here

I tried below code too, but same result,

     $.ajax({
   type: 'GET',
   url: u,
   crossDomain: true,
   dataType: 'jsonp',
   async: false,
   headers: {
     "Access-Control-Allow-Origin": "*"
     },
   success: function(succ) {
     console.log("Success: ", succ)
   },
   error: function(err) {
     console.log("Error: ", err)
   }
 });

This code is always going into error block.

How to implement date range filter in DataTables Ajax in laravel

Using the DataTables Ajax script, I have implemented the select, print, export, and search methods using the following code. Now I want to implement the from and to date range filter inside the DataTables to filter out the data and to use print and export the data.

 $(function() {
  let copyButtonTrans = '{{ trans('global.datatables.copy') }}'
  let csvButtonTrans = '{{ trans('global.datatables.csv') }}'
  let excelButtonTrans = '{{ trans('global.datatables.excel') }}'
  let pdfButtonTrans = '{{ trans('global.datatables.pdf') }}'
  let printButtonTrans = '{{ trans('global.datatables.print') }}'
  let colvisButtonTrans = '{{ trans('global.datatables.colvis') }}'
  let selectAllButtonTrans = '{{ trans('global.select_all') }}'
  let selectNoneButtonTrans = '{{ trans('global.deselect_all') }}'
 
  let languages = {
    'en': 'https://cdn.datatables.net/plug-ins/1.10.19/i18n/English.json'
  };

  $.extend(true, $.fn.dataTable.Buttons.defaults.dom.button, { className: 'btn' })
  $.extend(true, $.fn.dataTable.defaults, {
    language: {
      url: languages['{{ app()->getLocale() }}']
    },
    columnDefs: [{
        orderable: false,
        className: 'select-checkbox',
        targets: 0
    }, {
        orderable: false,
        searchable: false,
        targets: -1
    }],
    select: {
      style:    'multi+shift',
      selector: 'td:first-child'
    },
    order: [],
    scrollX: true,
    pageLength: 100,
    dom: 'lBfrtip<"actions">',
    buttons: [
      {
        extend: 'selectAll',
        className: 'btn-primary',
        text: selectAllButtonTrans,
        exportOptions: {
          columns: ':visible'
        },
        action: function(e, dt) {
          e.preventDefault()
          dt.rows().deselect();
          dt.rows({ search: 'applied' }).select();
        }
      },
      {
        extend: 'selectNone',
        className: 'btn-primary',
        text: selectNoneButtonTrans,
        exportOptions: {
          columns: ':visible'
        }
      },
      {
        extend: 'copy',
        className: 'btn-default',
        text: copyButtonTrans,
        exportOptions: {
          columns: ':visible'
        }
      },
      {
        extend: 'csv',
        className: 'btn-default',
        text: csvButtonTrans,
        exportOptions: {
          columns: ':visible'
        }
      },
      {
        extend: 'excel',
        className: 'btn-default',
        text: excelButtonTrans,
        exportOptions: {
          columns: ':visible'
        }
      },
      {
        extend: 'pdf',
        className: 'btn-default',
        text: pdfButtonTrans,
        exportOptions: {
          columns: ':visible'
        }
      },
      {
        extend: 'print',
        className: 'btn-default',
        text: printButtonTrans,
        exportOptions: {
          columns: ':visible'
        }
      },
      {
        extend: 'colvis',
        className: 'btn-default',
        text: colvisButtonTrans,
        exportOptions: {
          columns: ':visible'
        }
     }
    ]
  });

  $.fn.dataTable.ext.classes.sPageButton = '';

});

Printing svg line have same stroke-width show different result on android and ios

I have a bug that the line have same stype on preview and on the actual print is different between android device and ios device. Specially the line on Android is thinner than the line on iOS

 .line {
     fill:#000000;
     fill-opacity:1;
     stroke:#000000;
     stroke-opacity:1; 
     stroke-width:0.1pt;
     shape-rendering:crispEdges; 
}

Can I ask why that happen? and are there anyway to fix so that every OS show and print the same?

Make square brackets also red in react js

In the given below code, it will search for the word with square brackets and replace the color of only that particular. I want to change the color of square brackets along with word.

 if (event.match(/([^[]+(?=]))/g)) {
      // event.match(/([^[]+(?=]))/g).style.backgroundColor = "#AA0000";
      // if (event.includes("[first name]") || event.includes("[insert ticket concern]")||event.includes("[insert information]")) {
      var newTxt = event.split('[');
      let sampleText = event;
      for (var i = 1; i < newTxt.length; i++) {
        let value = newTxt[i].split(']')[0];
        console.log(value, "matchhh");

        sampleText = this.replacecanned(sampleText, value, `<span style="color: red;">${value}</span>`);

      }

Thanks

If div has specific attribute, change text somewhere else on the page

How can I change text in a div if another div has a specific attribute, in my case data-value=flat?

What I mean is that if a div has an attribute data-value="flat" another div should have the text “Buy”.

In the specific if data-value="flat" I would like to change the text “1” into “Buy”

If data data-value="house" I would like to change the text “1” into “Rent”

Here the sample code

if (document.querySelector('div [data-value="flat"]')) {
  document.querySelectorAll('.label')
    .forEach(div => if(div.textContent=="1") div.textContent="Buy" );
}
<div data-value="flat">
Flat One
</div>
<div data-value="house">
House One
</div>
<div data-value="parking">
Parking One
</div>


<div class="label">1</div>

I tried this without any result.

Magento 2 cms backend javascript error Uncaught SyntaxError: Invalid or unexpected token

Suddenly I am having javascript error and cannot edit any cms page (cms/page/edit/page_id/45) or block. I have been trying to solve this for the past week with no success. I have also tried removing the modules that I have installed recently.

I did not touch any core files and I have updated file permissions but still get this error below in chrome console from the core static files

VM6148:68 Uncaught SyntaxError: Invalid or unexpected token
at template (template.js:79:36)
at render (template.js:140:24)
at iterate (template.js:236:33)
at Function._.each._.forEach (underscore.js:150:9)
at Object.template (template.js:206:15)
at UiClass.initConfig (class.js:89:28)
at UiClass._super (wrapper.js:106:35)
at UiClass.initConfig (abstract.js:123:18)
at UiClass.initConfig (wrapper.js:109:34)
at UiClass._super (wrapper.js:106:35)

Image showing spinner and javascript error