Click here to Skip to main content
15,887,683 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: 8yr JS now giving me console error in FF and CHROME Pin
Member 1514660812-Apr-21 3:00
Member 1514660812-Apr-21 3:00 
GeneralRe: 8yr JS now giving me console error in FF and CHROME Pin
Richard Deeming12-Apr-21 3:09
mveRichard Deeming12-Apr-21 3:09 
GeneralRe: 8yr JS now giving me console error in FF and CHROME Pin
Member 1514660812-Apr-21 3:14
Member 1514660812-Apr-21 3:14 
GeneralRe: 8yr JS now giving me console error in FF and CHROME Pin
Richard Deeming12-Apr-21 3:39
mveRichard Deeming12-Apr-21 3:39 
GeneralRe: 8yr JS now giving me console error in FF and CHROME Pin
Member 1514660812-Apr-21 4:00
Member 1514660812-Apr-21 4:00 
QuestionKendo UI for jQuery Combobox noDataTemplate Not Loading Pin
Hypermommy5-Apr-21 9:35
Hypermommy5-Apr-21 9:35 
Questionquirks with use of Audio() Pin
Derell Licht31-Mar-21 16:03
professionalDerell Licht31-Mar-21 16:03 
QuestionBizarre JSON parse problem Pin
intoittendenz28-Mar-21 23:27
intoittendenz28-Mar-21 23:27 
AnswerRe: Bizarre JSON parse problem Pin
Richard Deeming29-Mar-21 0:36
mveRichard Deeming29-Mar-21 0:36 
QuestionCreating a JSON body payload in plain JavaScript Pin
jkirkerx27-Mar-21 9:46
professionaljkirkerx27-Mar-21 9:46 
AnswerRe: Creating a JSON body payload in plain JavaScript [solved] Pin
jkirkerx27-Mar-21 10:52
professionaljkirkerx27-Mar-21 10:52 
GeneralRe: Creating a JSON body payload in plain JavaScript [solved] Pin
intoittendenz29-Mar-21 1:01
intoittendenz29-Mar-21 1:01 
QuestionCannot figure out what code lines does mean ... Pin
Member 1501261727-Mar-21 0:01
Member 1501261727-Mar-21 0:01 
AnswerRe: Cannot figure out what code lines does mean ... Pin
Member 1501261727-Mar-21 0:03
Member 1501261727-Mar-21 0:03 
AnswerRe: Cannot figure out what code lines does mean ... Pin
Peter_in_278027-Mar-21 0:54
professionalPeter_in_278027-Mar-21 0:54 
GeneralRe: Cannot figure out what code lines does mean ... Pin
Member 1501261727-Mar-21 21:40
Member 1501261727-Mar-21 21:40 
GeneralRe: Cannot figure out what code lines does mean ... Pin
Member 150126178-Apr-21 22:49
Member 150126178-Apr-21 22:49 
AnswerRe: Cannot figure out what code lines does mean ... Pin
Richard Deeming28-Mar-21 22:29
mveRichard Deeming28-Mar-21 22:29 
GeneralRe: Cannot figure out what code lines does mean ... Pin
Member 150126178-Apr-21 22:49
Member 150126178-Apr-21 22:49 
QuestionRedirect with (Page Visibility API) Pin
ab smine19-Mar-21 10:38
ab smine19-Mar-21 10:38 
QuestionNode-Schedule Module Can't Cron Job Scheduled Long Time Pin
Barış KAHRAMAN19-Mar-21 10:02
Barış KAHRAMAN19-Mar-21 10:02 
I used node-schedule module to cron a job executed only once at particular time. I also use callable function to trigger Cloud Function and to get client-side data. The big trouble is that all things are fine to cron a single task until 15 minutes. But, on the other hand it doesn't do the task scheduled further time more than 15 minutes. What may occur after 15 minutes to cancel task? I used Firebase Quickstart code and I add only schedule-job module into the code. I didn't changed anything other than getting scheduling time values from client-side. I really need help for this issue. The cloud function script is below.

Thank you.

<pre>/* eslint-disable max-len */
"use strict";

const functions = require("firebase-functions");
const sanitizer = require("./sanitizer");
const admin = require("firebase-admin");
const schedule = require("node-schedule");
admin.initializeApp();
// [START messageFunctionTrigger]
// Saves a message to the Firebase Realtime Database but sanitizes the text by removing swearwords.
exports.addMessage = functions.https.onCall((data, context) => {
  // [START_EXCLUDE]
  // [START readMessageData]
  // Message text passed from the client.
  const text = data.text;
  // [END readMessageData]
  // [START messageHttpsErrors]
  // Checking attribute.
  if (!(typeof text === "string") || text.length === 0) {
    // Throwing an HttpsError so that the client gets the error details.
    throw new functions.https.HttpsError("invalid-argument", "The function must be called with " +
        "one arguments \"text\" containing the message text to add.");
  }
  // Checking that the user is authenticated.
  if (!context.auth) {
    // Throwing an HttpsError so that the client gets the error details.
    throw new functions.https.HttpsError("failed-precondition", "The function must be called " +
        "while authenticated.");
  }
  // [END messageHttpsErrors]

  // [START authIntegration]
  // Authentication / user information is automatically added to the request.
  const uid = context.auth.uid;
  const name = context.auth.token.name || null;
  const picture = context.auth.token.picture || null;
  const email = context.auth.token.email || null;
  // [END authIntegration]

  // [START returnMessageAsync]
  // Saving the new message to the Realtime Database.

  const dateWithTimeZone = (timeZone, year, month, day, hour, minute, second) => {
    const date = new Date(Date.UTC(year, month, day, hour, minute, second));

    const utcDate = new Date(date.toLocaleString("en-US", {timeZone: "UTC"}));
    const tzDate = new Date(date.toLocaleString("en-US", {timeZone: timeZone}));
    const offset = utcDate.getTime() - tzDate.getTime();

    date.setTime( date.getTime() + offset );

    return date;
  };

  const sanitizedMessage = sanitizer.sanitizeText(text); // Sanitize the message.

  const dataFuture = [uid, name, picture, email, sanitizedMessage];

  new Promise(function() {
    schedule.scheduleJob(dateWithTimeZone("Europe/Istanbul",
        data.year, data.month, data.day, data.hour,
        data.minute, data.second), function(data) {
      const theuid = data[0];
      const thename = data[1];
      const thepicture = data[2];
      const theemail = data[3];
      return admin.database().ref("/messages").push({
        text: data[4],
        author: {theuid, thename, thepicture, theemail},
      }).then(() => {
        console.log("New Message written");
        // Returning the sanitized message to the client.
        return {text: data[4]};
      })
      // [END returnMessageAsync]
          .catch((error) => {
            // Re-throwing the error as an HttpsError so that the client gets the error details.
            throw new functions.https.HttpsError("unknown", error.message, error);
          });
    }.bind(null, dataFuture));

  // [END_EXCLUDE]
  });

  return {text: "done"};
// [END messageFunctionTrigger]
});

QuestionCalculation in javascript Pin
Krasimir Dermendzhiev16-Mar-21 3:31
Krasimir Dermendzhiev16-Mar-21 3:31 
AnswerRe: Calculation in javascript Pin
Richard Deeming16-Mar-21 4:39
mveRichard Deeming16-Mar-21 4:39 
GeneralRe: Calculation in javascript Pin
Krasimir Dermendzhiev16-Mar-21 21:36
Krasimir Dermendzhiev16-Mar-21 21:36 
GeneralRe: Calculation in javascript Pin
Krasimir Dermendzhiev30-Mar-21 4:22
Krasimir Dermendzhiev30-Mar-21 4:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.