1

Quisiera que pongan un botón de buscar... Es que quiero usar solo el ratón y pegar lo que quiero buscar mediante click derecho y luego la opción pegar.

introducir la descripción de la imagen aquí

Mi teclado está teniendo una serie de inconvenientes últimamente y además en ese momento no tenía ganas de usar el teclado, y mi sistema no tiene teclado en pantalla.

Solo tenía el ratón, y no pude buscar una pregunta porque no había un botón de buscar, de modo que la única manera era buscarla desde Google, que sí tiene ese botón... Pero me desanimé y ya no lo hice.

¿Qué les parece la idea?

Bueno... Con la idea que me dejó lois6b en los comentarios, ya terminé de programarle el userscript, lo dejo aquí al código por si quieren mirar... Se trata de un teclado en pantalla.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf8" />
        <title>Teclado en pantalla</title>
    </head>
    <body>
        <input id="search" />
        <script>
// ==UserScript==
// @name     Botón de buscar en SO
// @version    0.1
// @description  Para buscar con el ratón.
// @author     Eslacuare
// @match    *://*.stackoverflow.com/*
// @grant    none
// ==/UserScript==

var so_us = {}
window.so_us = so_us

so_us.escribir = function(){
  var e = this.textContent.toLocaleLowerCase()
  var n = so_us.entrada_seleccionada
  var u = 0, v = 0
  var estilo_teclado = so_us && so_us.teclado && so_us.teclado.style
  var arr = null, num = null, cambiar_atributo = null, sel = null
  var inicio = 0
  var fin = 0
  var buscar = document.querySelector("#search")
  estilo_teclado && (
    cambiar_atributo = (u,f,e,estilo,vector,relativo)=>{
      var r = new RegExp(`(^\\(${f}\\)$)`,"i").test(e)
      var valor = null
      r && (
        u = 7,
        arr = estilo_teclado[vector].match(/(\d|\.)+/),
        num = arr && + arr[0] || 0,
        valor = (num + relativo).toString(),
        vector=="opacity" && (
          valor = valor<0.1?0.1:valor>1?1:valor,
          so_us.opacidad = valor
        ) || (
          valor = valor.concat("px")
        ),
        estilo[vector] = valor
      )
      return u==6?u:u
    },
    u = cambiar_atributo(u,"←",e,estilo_teclado,"left",-10),
    u = cambiar_atributo(u,"→",e,estilo_teclado,"left", 10),
    u = cambiar_atributo(u,"↑",e,estilo_teclado,"top", -10),
    u = cambiar_atributo(u,"↓",e,estilo_teclado,"top" , 10),
    u = cambiar_atributo(u," \\+ ",e,estilo_teclado,"opacity", 0.1),
    u = cambiar_atributo(u," - ", e,estilo_teclado, "opacity",-0.1)
  )
  n && u<5 && (
    n.value==undefined && (n = n.target),
    buscar && /(^↵intro$)/i.test(e) && (
      u = 6,
      buscar.submit && buscar.submit() ||
      alert("Se ejecuta la búsqueda: " + n.value)
    ),
    e = e=="╙╌╌╜" ? "\x20" : e,
    e=="←" && (u = -1) && (v = 1),
    e=="↑" && (u = 2) && (v = 1),
    e=="↓" && (u = 3) && (v = 1),
    e=="→" && (u = 1) && (v = 1),
    so_us.inicio_seleccion = n.selectionStart,
    so_us.fin_selección = n.selectionEnd,
    so_us.inicio_seleccion != so_us.fin_selección && (v = 2),
    inicio = n.value.slice(0,so_us.inicio_seleccion),
    fin = n.value.slice(so_us.fin_selección),
    /(^[0-9a-zñ\[\]\x20áéíóú+-]$)/i.test(e) && (
      u = 4, v = 1,
      n.value = inicio + e + fin
    ),
    /(^↩$)/.test(e) && (
      (v != 2) && (inicio = inicio.slice(0,-1)),
      u = 4,
      v = v==2?v=0:v=-1,
      n.value = inicio + fin
    ),
    /(^supr)/i.test(e) && (
      (v != 2) && (fin = fin.slice(1)),
      u = 4, v = 0,
      n.value = inicio + fin
    ),
    ( u==-1 || u==1 ) && (
      v==2 && u==-1 && (v=0),
      v==2 && u== 1 && (
        v = so_us.fin_selección - so_us.inicio_seleccion
      ),
      v = v==1 ? u : v,
      n.selectionStart=so_us.inicio_seleccion + v,
      n.selectionEnd = so_us.inicio_seleccion + v
    )
  ),
  u==2 && (
    n.selectionStart = 0,
    n.selectionEnd = 0
  ),
  u==3 && (
    n.selectionStart = n.value.length,
    n.selectionEnd = n.value.length
  ),
  u==4 && (
    n.selectionStart = so_us.inicio_seleccion + v,
    n.selectionEnd = so_us.inicio_seleccion + v
  ),
  u<=5 && (
    so_us.entrada_seleccionada.focus==undefined && (
      sel = so_us.entrada_seleccionada.target
    )|| (
      sel = so_us.entrada_seleccionada
    ),
    sel.focus()
  )
}
so_us.seleccionar_entrada = function(x){
  so_us.entrada_seleccionada = x?x:this
}
so_us.es_entrada = function(x){
  return x && /(^input$)|(^textarea$)/i.test(x.tagName)
}
so_us.es_teclado = function(x){
  return x.classList.contains("teclado")
}
so_us.desaparecer = function(x){
  var b = 0
  if(x!=undefined){
    !so_us.es_entrada(x.target) && (b = so_us.opacidad)
    x==2 && (so_us.teclado.style.display = "none")
  }else{
    b = so_us.opacidad
  }
  b && so_us.teclado.style.opacity!==0 &&
    (so_us.teclado.style.opacity = 0)
}
so_us.aparecer = function(x){
  so_us.es_entrada(x.target) && (
    x.target.focus(),
    so_us.seleccionar_entrada(x.target)
  )
  so_us.es_entrada(document.activeElement) &&
    so_us.teclado.style.opacity!==so_us.opacidad &&
    (so_us.teclado.style.opacity = so_us.opacidad)
  if(so_us.teclado.style.display != "block"){
    so_us.teclado.style.display = "block"
  }
}
so_us.crear_teclado = function(){
  var t = document.createElement("table")
  var r = document.createElement("tr")
  var d = document.createElement("td")
  r.appendChild(d)
  t.appendChild(r)
  document.querySelector("body").appendChild(t)
  so_us.teclado = t
  t.border = "1"
  t.style.display = "none"
  t.style.position = "fixed"
  t.style["z-index"] = 6000
  try{$ && (
    t.style.left = "230px",
    t.style.top = "140px"
  )}catch(e){
    t.style.left = "10px"
    t.style.top = "50px"
  }
  d.style["background-color"] = "#ff800040"
  d.addEventListener("mouseleave",so_us.desaparecer)
  d.addEventListener("mouseenter",so_us.aparecer)
  var regex = /(^[0-9a-zñ\[\]+-←↑↓→↩]$)|(^╙╌╌╜$)|(^supr$)|(^↵intro)/i
  var teclas = "1234567890 qweértyuúiíoóp aásdfghjklñ zxcvbnm"
    .split(" ").map(x=>{
      var i = document.createElement("div")
      var y = x.split("")
      y[0]=="1" && y.push(..."←↑↓→↩".split(""),"supr")
      y[0]=="q" && y.push("(↑)")
      y[0]=="a" && y.push("↵intro","(←)","(→)")
      y[0]=="z" && y.push(
        ..."[]+-".split(""),"( + )","( - )","(↓)","╙╌╌╜"
      )
      y.map(x=>{
        var o = document.createElement("button")
        var b = document.createElement("b")
        b.style.fontSize = "10px";
        var r = (regex.test(x)) && (
          o.style["background-color"] = "#80ff00a0"
        ) || (/[áéíóú]/i.test(x)) && (
          o.style["background-color"] = "#ff9010a0"
        ) || (o.style["background-color"] = "#20b0ffa0")
        o.classList.add("teclado")
        b.innerHTML = x.toUpperCase()
        o.addEventListener("click",so_us.escribir)
        o.appendChild(b)
        i.appendChild(o)
      })
      d.appendChild(i)
    })
  so_us.opacidad = 1
}

so_us.agregar_teclado_en_pantalla = function(){
  var entradas = [
    ...document.querySelectorAll("textarea,input")
  ].map(x=>{
    x.addEventListener("click",so_us.seleccionar_entrada)
    x.addEventListener("mouseleave",so_us.desaparecer)
    x.addEventListener("mouseenter",so_us.aparecer)
    x.autofocus = true
    !so_us.es_entrada(document.activeElement) &&
      !so_us.es_teclado(document.activeElement) &&
      so_us.desaparecer(2)
  })
}

so_us.crear_teclado()

setInterval(so_us.agregar_teclado_en_pantalla,100)
        </script>
    </body>
</html>

2
  • 2
    Si no existe en SO en inglés, no lo van a poner en otros sitios primero. Podrías hacerte una extensión que añada un botón :P O puedes usar la URL con el parametro de busqueda: "es.stackoverflow.com/search?q=sfasdfad"
    – lois6b
    el 26 may. 2021 a las 7:38
  • @lois6b Gracias, buena idea, me haré un userscript.
    – user13558
    el 26 may. 2021 a las 8:03

0

Debes iniciar sesión para responder a esta pregunta.