Ente

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==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));