Ente

Übersetze ausgewählte englische Worte nach Deutsch mit dict.cc.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name        Ente
// @namespace   meyerk.com
// @match       *://*/*
// @grant       none
// @version     0.6
// @author      MeyerK
// @description Übersetze ausgewählte englische Worte nach Deutsch mit dict.cc.
// @noframes
// ==/UserScript==

class ente
{
  
  constructor()
  {
    this.rightAltKeyIsOn = false;
    this.isVisible = false;
    this.frame = document.createElement('iframe');      
    this.width = 300;
  }
  
  setup()
  {
    this.frame.id = 'enteFrame';
    this.frame.style.position = 'fixed';
    this.frame.style.top = '10px';
    this.frame.style.width = this.width+'px';
    this.frame.style.padding = '5px';
    this.frame.style.height = '100px';
    this.frame.style.border = '1px solid blue';
    this.frame.style.backgroundColor = 'aliceblue';
    this.frame.style.display = 'none';
    this.frame.style.borderRadius = '5px';
    this.frame.style.zIndex = '2147483646';
        
    document.getElementsByTagName('body')[0].appendChild(this.frame);
  }
  
  handleKeys(ev)
  {     
    if (this.rightAltKeyIsOn)
    {
      if (ev.code == 'KeyU')
      {
        let text = window.getSelection().toString();
        this.frame.src = "//syn.dict.cc/dcc-gadget.php?s=" + encodeURIComponent(text);
        this.show();
        
        return false;
      }
    }
    
    if (ev.code == 'AltRight')
    {
      this.rightAltKeyIsOn = (ev.type == 'keydown') ? true : false; 
    }    
  }

  handleMouse(ev)
  {
    if (this.isVisible)
    {      
      this.hide();    
      
      ev.preventDefault();
      return false;
    }    
  }
  
  show()
  {
    let leftPos = parseInt(window.innerWidth / 2) - parseInt(this.width / 2);    
    this.frame.style.left = leftPos+'px';    
    this.frame.style.display = 'block';
    this.isVisible = true;    
  }
  
  hide()
  {
    this.frame.style.display = 'none';
    this.isVisible = false;
  }
    
}

var en2de = new ente();
en2de.setup();
document.addEventListener('keydown', en2de.handleKeys.bind(en2de));
document.addEventListener('keyup',   en2de.handleKeys.bind(en2de));
document.addEventListener('click',   en2de.handleMouse.bind(en2de));