Javascript to capture input from a Firestick controller and turn a single button press into two different button presses

I need html / javascript that will capture the input of a Firestick controller and have it do something else. Specifically I need the “Play/Pause” on the controller aka “Next” on the soft keyboard to minimize the keyboard. Since there is no Key ID for the “Back” button, I would like to have the click of next make the selector go left once then press enter.

So far I have the below but this just reloads the page. When I hit next.

Please be aware javascript is new to me so if you assist, please know I know nothing (John Snow) 🙂

<script>
function checkKey(e){
    if(e.keyCode == 179) {
        //Play-Pause Button
e.key = "37";
e.key = "13";
    }
}
  </script>

//Later in the form brackets

<form action="#" onkeydown="checkKey(event);" id="custom-data" _lpchecked="1">
onkeydown="checkKey(event);"

https://developer.amazon.com/docs/fire-tv/supporting-controllers-in-web-apps.html

Slash command permissions

I used this code to do slash command and everything worked fine but when I use permissions I get error I don’t know where to add permissions
………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………..
Permissions code I used :

const permissions = [ { id: '969008290208051201', type: 'ROLE', permission: true, }, ]; await command.permissions.add({ permissions })

The code :

client.on('ready', async () => {

 
    console.log(`Logged in as: ${client.user?.tag}`)
    
    const gulidId = '904512141283975179' 

const gulid = client.guilds.cache.get(gulidId)
const permissions = [
    {
        id: '969008290208051201',
        type: 'ROLE',
        permission: true,
    },
];

    await command.permissions.add({ permissions })
    
  
let commands

if (gulid) {
  
  commands = gulid.commands
 
}else {
    
    commands = bot.appliction?.commands
    
  }
  commands?.create({
    
    name: 'say', 
    description: 'say something you wanna me to repeat',
   options: [
      
      {
        name: 'channel', 
        description : 'the channel you wanna me send the message in', 
        required: true, 
        type: discord_js_1.Constants.ApplicationCommandOptionTypes.CHANNEL
        
      }, 
      {
        name: 'message', 
        description: 'the message', 
        required: true, 
        type: discord_js_1.Constants.ApplicationCommandOptionTypes.STRING
      }
      
      
      
      ], 
      defaultPermission: false,
      
      
  })
   

    
});
 

client.on('interactionCreate', async (interaction) => {
  
  if (!interaction.isCommand()) {
    return 
  }
  
  const { commandName, options} = interaction
  
  if (commandName === 'say') {
    

    const channel = options.getChannel('channel')
    const message = options.getString('message')
  channel.send(message)
    interaction.reply({
      content: `announcement has been sent to ${channel}`, 
      ephemeral: true, 
    }) 
    
    
  }
  
})

Javascript table header not showing

When I run my code, only the caption shows but the table header isn’t showing. Can someone tell me what I’m doing wrong and how I can fix it? Thank you!

let tableHTML = "<table>" + "<caption>My Store</caption>" +
                "<tr><th>Product</th><th>Price</th></tr>";

tableHTML += "</table>";

How can react quiz maker work with question array

I’m using the react native quiz maker (https://github.com/jtalz/react-native-quiz-maker) to make a quiz, and I currently have an array that has all questions in the specified format. However, when I use the below code to display the quiz, I get empty space where the quiz should been. I have a feeling it may be because they require questions = {[{question 1}{question 2}]} where the array is in curly brackets, whereas I simply try to use an array. However, when I tried questions = {{questionList}} I get Uncaught TypeError: Invalid attempt to spread non-iterable instance. Any workaround for this?

Here’s my code currently, where I have a list of objects, and I put them in into the required question format with a for loop. So, I have questionList, which is an array of objects, where each one is formatted according to quiz maker’s format (this part works perfectly, when I try to console.log, I get the output I want)

function Home ({route}) {
  let questionList = [];
  for (let x = 0; x < subset.length; x++) {
    if (route.params.name == 'StoE') {
      let question = {
        questionType: 'Writing',
        question: `What is '${subset[x].spanish}' in English?`,
        answer: subset[x].english
      }
      questionList.push(question)
    } else {
      let question = {
        questionType: 'Writing',
        question: `What is '${subset[x].english}' in Spanish?`,
        answer: subset[x].spanish
      }
      questionList.push(question)
    }
  }
  return (
    <View style={global.container}>
      <Text>{route.params.name}</Text>
      <QuizContainer
        questions={{questionList}}
        onSubmit={(isCorrect) => console.log(isCorrect)}
        onComplete={(progress) => console.log('score: ', progress)} 
      />
      {console.log(questionList)}
    </View>
  );
}

WebSocket data cannot be converted to array from the buffer

I simply send an array from client to server. When I try to log this array from the client-side it gives me random values in the array.

Client-Side Code

let ws = new WebSocket("ws://localhost:4000");
ws.send([1,2,3]);

Server-Side Code

wss.on("connection", (ws) => {
  ws.on("message", m => {
    //I searched a little and learnt a way to convert buffer to array with a simple ES6 feature but it doesn't work properly
    console.log([...m]);
  });
});

The output is: [ 49, 44, 50, 44, 51 ]

Please post how can I fix it, and explain the reason for it so I and other people can understand the logic behind it.

getPastEvents() not returning for plygon

I have a perfectly working code on Ethereum (Ropsten Testnet). I recently migrated to Polygon Testnet (mumbai). Deployment went smooth (See Deployment on Polyscan)

I can play with my SmartContract using Remix. Events are getting fired (See the Events Log).

I have the following code in my Dapp, whuch get the events successfully from Ropsten, but is not returning anything for Polygon-Testnet (the contract address is correct). What am I doing wrong here? Does Polygon use the same JS Web3 APIs (web3 ^1.3.6)?

  debugger;
  let pastEventsAdded = await AccountsContract.getPastEvents(
    "AccountAdded",
    ev
  );
  debugger;

Keep draggable box from going outside of window

Hey guys I’m trying to keep draggable boxes from going outside of the window browser. This is the code I am using I have tried to do a containment div but that didn’t seem to work. Not sure what I am doing wrong. Thank you a million to anyone that can help me I have spent several days on this and a girl is tired.

html/css

      .dragme{
        position:relative;
        cursor: move;
      }

javascript

 
 <script>
    function startDrag(e) {
 
      // determine event object
      if (!e) {
        var e = window.event;
      }
              if(e.preventDefault) e.preventDefault();

      // IE uses srcElement, others use target
      targ = e.target ? e.target : e.srcElement;

      if (targ.className != 'dragme') {return};
      // calculate event X, Y coordinates
        offsetX = e.clientX;
        offsetY = e.clientY;

      // assign default values for top and left properties
      if(!targ.style.left) { targ.style.left='0px'};
      if (!targ.style.top) { targ.style.top='0px'};

      // calculate integer values for top and left 
      // properties
      coordX = parseInt(targ.style.left);
      coordY = parseInt(targ.style.top);
      drag = true;

      // move div element
        document.onmousemove=dragDiv;
              return false;

      
    }
    function dragDiv(e) {
      if (!drag) {return};
      if (!e) { var e= window.event};
      // var targ=e.target?e.target:e.srcElement;
      // move div element
      targ.style.left=coordX+e.clientX-offsetX+'px';
      targ.style.top=coordY+e.clientY-offsetY+'px';
      return false;
    }
    function stopDrag() {
      drag=false;
    }
    window.onload = function() {
      document.onmousedown = startDrag;
      document.onmouseup = stopDrag;
    }

      </script>

Is injecting a JS app in WordPress through a shortcode a good idea?

I want to create a SAAS using WordPress and a JavaScript Framework (Angular, React, or Vue).
To be honest I am embarking on this without having the proper skillset nor a clear idea about how to do it, but learning is one of my goals too.

And I have a few questions:

Would it be a good idea to create the whole app and embed it through a shortcode in a regular WordPress page ?

What is the best JS library to use considering that the app is of medium complexity? and what is the best way to inject the app in WordPress?

What should I think about from the get go?

I would really appreciate any input and I hope that I asked this properly and in the right place, if not, please advise me in the comments.

How can make my React.js project downloadable on Desktop? [duplicate]

Good afternoon all,

I am a new programmer and I recently started following a music-player tutorial, and am experiencing a couple of issues with it.

Project Overview:

As previously described, it is a music-player project made with create-react-app. The objective is to click the image of the song of your choosing, and for the song to be played for you.

The songs are saved as mp3’s in a folder named music. The music folder is located in the src directory. Each song is assigned to its given song image (as you’ll see on the code I provided below). Then the songs/images are wrapped in an list element.

Now that I’ve got the project details out the way I wanted know how I can make a React.Js application downloadable on the desktop. Is there any way?

How to POST data to iframe src inside a modal?

I have bootstrap 3 modal that has iFrame in it, from which I would like to show page embed_player.php, but it requires POST data.

How to do so?

I have tried this explanation topic but unsucessfully:

<form action="action" method="post" target="output_frame">
    <!-- input elements here --> 
</form>
<iframe name="output_frame" src="" id="output_frame" width="XX" height="YY">
</iframe>        

This is my code:

HTML

            <button class="btn btn-success btn-lg video" data-video="embed_player.php" data-toggle="modal" data-target="#videoModal">Play Video 1</button>

            <div class="modal fade" id="videoModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <iframe width="100%" height="350" src="" frameborder="0" allowfullscreen></iframe>
                    </div>
                </div>
                </div>
            </div>

JS

    <script>
        $(function() {
            $(".video").click(function () {
            var theModal = $(this).data("target"),
            videoSRC = $(this).attr("data-video");
            $(theModal + ' iframe').attr('src', videoSRC);
            $(theModal + ' button.close').click(function () {
                $(theModal + ' iframe').attr('src', videoSRC);
            });
            });
        });
    </script>

map function not showing elements on screen

i have this part of code the map function did not show any element of the array, if i console.log the variable it shows me the elements but for some reasons i can’t show the elements on the screen.

Code



function Solution({list}){
  const data = list
    console.log(data);
    return(
        <div>
            {
                data?.map((item) => {
            
                    return (
                        <div>
                            <p> {item.title} </p>
                        </div>
                    )
                })
            }
        </div>
    )

}

export default Solution;


const list = [
    {
       
         title: "Home"
    },
    {
      
        title: "Service",
        subItem: ["Clean", "Cook"]
    },
    {
   
        title: "Kitchen",
        subItem: ["Wash", "Dish"]
    },
];


Solution({list})

how to make text appearing like you are typing?

when I saw a question on stackoverflow, how to make text appearing like you are typing?, I clicked it because I didn’t know how to make text appearing like you are typing(dont remember question). then I released I need it.

so this is what I remember:

{0 sec: h}

{1 sec: hi}

but what I want is typing like you are hacking:

{0.25 sec: “n”}

{0.50 sec: “nu”}

{1 sec: “Nul”}

{1.25 sec: “null”}

{1.50 sec: “null;”}

so 1 letter appears per 0.25s. so hello will be imputed in 1.25s.

how did you do it?

Error in my react app file – Please Help module not found cant resolve

Compiled with problems:X

ERROR in ./src/App.js 8:0-63

Module not found: Error: Can’t resolve ‘.src/components/NewsCards/NewsCards.js’ in ‘/Users/admin/Desktop/ALAN_AI_NEWS APP/myaiproject/src’

ERROR

src/App.js
Line 7:45: ‘useState’ is not defined no-undef

Search for the keywords to learn more about each error.

import React, { useEffect } from 'react';
import alanBtn from '@alan-ai/alan-sdk-web';
import NewsCards from '.src/components/NewsCards/NewsCards.js';
const alanKey = '0f881486602df260f78c6dd18ef0cc6e2e956eca572e1d8b807a3e2338fdd0dc/stage';

const App = () => {
    const [newsArticles, setNewsArticles] = useState ([]);

    
    useEffect(() => {
      alanBtn({
            key: alanKey,
            onCommand: ({ command, articles}) => {
                if(command === 'newHeadlines') {
                   setNewsArticles(articles);
                 // Call the client code that will react to the received command
                }
            }
        })
    }, [])
   

    return (
        <div>
            <h1>Alan AI News Application</h1>
            <NewsCards articles={newsArticles} />
        </div>
    );
}

export default App;



Attached code above, pelase help solve this error

Set Length of TIme for Slides to Move

I am using this JS code I found to make a slideshow work:

<script>
    var slideIndex = 1;
    showDivs(slideIndex);
    
    function plusDivs(n) {
      showDivs(slideIndex += n);
    }

    function showDivs(n) {
      var i;
      var x = document.getElementsByClassName("hp-slides");
      if (n > x.length) {slideIndex = 1}
      if (n < 1) {slideIndex = x.length}
      for (i = 0; i < x.length; i++) {
        x[i].style.display = "none";  
      }
      x[slideIndex-1].style.display = "block";  
    }
    </script>

But the images move right as I click = too fast/ not elegant.

I saw this other code in other JS slider examples, which made the slides move slower (Those other codes didn’t work for me for other reasons (couldn’t be resized, needed complicated/hidden jQuery, etc.))

setInterval(function() {
    showDivs()
    }, 5000);

But I don’t know where to place it. I changed the name to be one of the function names (showDivs) and tried sticking it in between functions, but it didn’t work.

I’m already on 3-4 days looking for a simple slider with arrows that will scale with the page and losing my mind.
Thank you!