1. Martin van Es
  2. MdePolska

Overview

HTTPS SSH

Popolsku (formerly MDE Polska)

DEPRECATED: Work on this bookmarklet has been suspended, because there is a Chrome plugin that uses the Google Keyboard.

A bookmarklet to attach a Polish keyboard to all textareas on the current page.

This used to be a Drupal module, but now is a self-contained bookmarklet.

Usage

Make a bookmark with this as the location:

javascript:(function(){!function(a)%7B%22use%20strict%22;a.loadScript=function(a,b)%7Bvar%20c=document.createElement(%22script%22);c.src=a;var%20d=document.getElementsByTagName(%22head%22)%5B0%5D,e=!1;c.onload=c.onreadystatechange=function()%7Be%7C%7Cthis.readyState&&%22loaded%22!==this.readyState&&%22complete%22!==this.readyState%7C%7C(e=!0,b(),c.onload=c.onreadystatechange=null)%7D,d.appendChild(c)%7D,window.mdepolska=a%7D(window.mdepolska%7C%7C%7B%7D),function(a,b)%7B%22use%20strict%22;b.globals=%7BtildaModKeyCode:192,asteriskModKeyCode:56,diacriticChars:%22AaCcEeLlNnOoSsZz%22,hasInitialized:!1%7D;var%20c=function(a,c)%7Bc=c%7C%7C%7B%7D,new%20b.classes.Typer(a),c.blinkenlichten?new%20b.classes.Blinkenlichten(a):new%20b.classes.Decoration(a)%7D,d=function(d)%7Bb.globals.hasInitialized%7C%7C(b.globals.hasInitialized=!0,void%200!==window.console?(a(%22textarea.polska%22).each(function()%7Ba(this).is(%22:not(.initialized)%22)&&c(this,d)%7D),a(document).on(%22focus%22,%22textarea,%20input%22,function()%7Ba(this).is(%22:not(.initialized)%22)&&c(this,d)%7D)):d.oldbrowser&&b.util.oldBrowser())%7D;b.init=function(c)%7B%22undefined%22==typeof%20a?b.loadScript(%22https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js?%22,function()%7Ba=window.jQuery,d(c)%7D):d(c)%7D,b.classes=%7B%7D,b.classes.Typer=function(a)%7Bthis.prevChar=null,this.elem=a,this.init()%7D,b.classes.Typer.prototype=%7Binit:function()%7Bvar%20c=this;a(this.elem).keydown(function(a)%7Breturn(b.globals.tildaModKeyCode===a.keyCode&&a.shiftKey%7C%7Cb.globals.asteriskModKeyCode===a.keyCode&&a.shiftKey)&&(c.prevChar=c.getPrevChar(),b.globals.diacriticChars.indexOf(c.prevChar)%3E-1)?(c.replaceChar(a),!1):void%200%7D),a(this.elem).addClass(%22initialized%22)%7D,getPrevChar:function()%7Bvar%20b=a(this.elem).val();return%20b.length%3E0?b.substr(this.elem.selectionStart-1,1):null%7D,replaceChar:function(b)%7Bvar%20c=this.mapChar(b.keyCode);a(this.elem).val(a(this.elem).val().substring(0,this.elem.selectionStart-1)+c)%7D,mapChar:function(a)%7Bvar%20c=this.prevChar;if(b.globals.tildaModKeyCode===a)switch(c)%7Bcase%22A%22:return%22%C4%84%22;case%22a%22:return%22%C4%85%22;case%22C%22:return%22%C4%86%22;case%22c%22:return%22%C4%87%22;case%22E%22:return%22%C4%98%22;case%22e%22:return%22%C4%99%22;case%22L%22:return%22%C5%81%22;case%22l%22:return%22%C5%82%22;case%22N%22:return%22%C5%83%22;case%22n%22:return%22%C5%84%22;case%22O%22:return%22%C3%93%22;case%22o%22:return%22%C3%B3%22;case%22S%22:return%22%C5%9A%22;case%22s%22:return%22%C5%9B%22;case%22Z%22:return%22%C5%B9%22;case%22z%22:return%22%C5%BA%22;default:return%20c%7Delse%20if(b.globals.asteriskModKeyCode===a)switch(c)%7Bcase%22Z%22:return%22%C5%BB%22;case%22z%22:return%22%C5%BC%22;default:return%20c%7D%7D%7D,b.classes.Blinkenlichten=function(a)%7Bthis.elem=a,this.init()%7D,b.classes.Blinkenlichten.prototype=%7Binit:function()%7Bthis.createHtml();var%20b=this;a(this.elem).keydown(function(a)%7Bvar%20c=b.getLicht(a);b.down(c)%7D).keyup(function()%7Ba(%22#blinkenlichten%20ul%20li%22).removeClass(%22active%22)%7D)%7D,createHtml:function()%7Ba(this.elem).after('%3Cdiv%20id=%22blinkenlichten%22%3E%3Cul%20class=%22meta%22%3E%20%20%3Cli%20id=%22tilda%22%3E~%3C/li%3E%20%20%3Cli%20id=%22asterisk%22%3E*%3C/li%3E%3C/ul%3E%3Cul%3E%20%20%3Cli%20id=%22a%22%3EA%3C/li%3E%20%20%3Cli%20id=%22c%22%3EC%3C/li%3E%20%20%3Cli%20id=%22e%22%3EE%3C/li%3E%20%20%3Cli%20id=%22l%22%3EL%3C/li%3E%20%20%3Cli%20id=%22n%22%3EN%3C/li%3E%20%20%3Cli%20id=%22o%22%3EO%3C/li%3E%20%20%3Cli%20id=%22s%22%3ES%3C/li%3E%20%20%3Cli%20id=%22z%22%3EZ%3C/li%3E%3C/ul%3E%3C/div%3E')%7D,getLicht:function(c)%7Bvar%20d=null,e=String.fromCharCode(c.keyCode);if(b.globals.tildaModKeyCode===c.keyCode&&c.shiftKey)d=a(%22#blinkenlichten%20ul%20li#tilda%22);else%20if(b.globals.asteriskModKeyCode===c.keyCode&&c.shiftKey)d=a(%22#blinkenlichten%20ul%20li#asterisk%22);else%7Bif(!(b.globals.diacriticChars.indexOf(e)%3E-1))return;var%20f=e.toLowerCase();d=a(%22#blinkenlichten%20ul%20li#%22+f)%7Dreturn%20d%7D,down:function(a)%7Bvoid%200!==a&&a.addClass(%22active%22)%7D%7D,b.classes.Decoration=function(a)%7Bthis.elem=a,this.bgColor=%22#8DB11F%22,this.init()%7D,b.classes.Decoration.prototype=%7Binit:function()%7Ba(this.elem).css(%22border%22,%221px%20solid%20%22+this.bgColor);var%20b=a(this.elem).offset().top,c=a(this.elem).offset().left+a(this.elem).width()+1;this.createTab(b,c)%7D,createTab:function(b,c)%7Ba(this.elem).before('%3Cdiv%20class=%22polska-decoration%22%20style=%22position:%20absolute;background:%20'+this.bgColor+%22;border:%201px%20solid%20%22+this.bgColor+%22;border-top-right-radius:%205px;border-bottom-right-radius:%205px;color:%20white;cursor:%20pointer;font-weight:%20bold;font-family:%20sans-serif;left:%20%22+c+%22px;padding:%202px;top:%20%22+b+'px;%22%20title=%22MDE%20Polska!%22%3E%3Ca%20href=%22http://mdworld.nl/cms/content/polska%22%20style=%22text-decoration:%20none;%20color:%20white;%22%3EP%3C/a%3E%3C/div%3E')%7D%7D,b.util=%7B%7D,b.util.oldBrowser=function()%7Ba(%22textarea.polska%22).attr(%22disabled%22,%22disabled%22).addClass(%22readonly%22).addClass(%22initialized%22).val(%22THIS%20IS%20AN%20OLD%20BROWSER,%20TYPER%20IS%20DISABLED.%22)%7D,window.mdepolska=b%7D(window.jQuery,window.mdepolska%7C%7C%7B%7D);(function(mdepolska)%20%7B%0D%0A%20%20%20%20'use%20strict';%0D%0A%0D%0A%20%20%20%20mdepolska.init();%0D%0A%7D)(window.mdepolska);})();

Click the bookmark on a page that has a textarea. Type e.g. a~. It will be converted to ą.

I use this for the Polish course on Duolingo.

Development

To update example-bookmarklet.html, run grunt build and manually update the bookmarklet in the source of example-bookmarklet.html and in this README.

TODO

  • change order of ~ and special character to be conform Google keyboard
  • abandon * as a special character and use ~X for Z with ' and ~Z for Z with . (like Google keyboard)

  • fix bug: "~" is intercepted as deadkey and user needs to type spacebar to make it visible. Only then e.g. "a" can be typed to be converted.

  • convert to TypeScript
  • don't bind on textarea, but on all typing on a page