Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

339
Visualizações
Get position of cursor when highlight the text

I need to create a Chrome Extension which people can use to look up words. And I have found that I use double-click method like when I want to find meaning of a word I just double click and then the notification will appear. (The image below is my Chrome Extension.)

enter image description here.

  • However, I find it is difficult for user to find meaning of pharsal verb, collocation and sentence.
  • So come up with an idea that I can get the position of cursor when user select text and to the last letter of this text I get the position.

enter image description here

  • In addition, I also have found many other Chrome extensions support this feature and they are so great!. One of them is "Edge Translate". When I higlight a text and then I release the mouse it appears a little popup ball then I click to this ball it appears panel. This is their extension: https://chrome.google.com/webstore/detail/edge-translate/bocbaocobfecmglnmeaeppambideimao?hl=en

enter image description here

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

To get the text selected you could use this function, then remove the dots, and other characters you are not interested in and split the selected text by spaces to get the last word. (also you don't need the cursor coordinates for it, so you could remove this piece. of the code)

  let hasSelection = false;
  function showCoordsForMouseUp(event) {
      const selection = window.getSelection().toString()
      hasSelection = selection.length;
      if (hasSelection) {
          const x = event.clientX;
          const y = event.clientY;
          const coords = `X coords: ${x} , Y coords: ${y}`;
          console.log(`${coords} - ${selection}`)
      } else {
          console.log('No text selected')
      }
  }

  document.onmouseup = showCoordsForMouseUp;
about 4 years ago · Juan Pablo Isaza Relatório

0

Thanks for your contribution, I have found the solution with onMouseUp Event.

document.onmouseup = function F(e) {
  x = e.pageX;
  y = e.pageY;
  if (window.getSelection().toString() != "") {
    console.log("X: " + x + "Y: " + y);
  }
}
<p>
  Flower, flowers.
</p>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda