User:Ruakh/CodePointRedirects.js

/* If you enable this script, then when you visit a URL such as * , you will automatically be redirected * to the entry for the character identified by the code-point (in this example, * to ). It respects the same * sorts of restrictions as the standard auto-redirects (such as that from *  to * ): it will not redirect if * there actually exists an entry U+0041, or if it sees ?redirect=no or the * like in the URL, or in various other such cases. * * To enable this script for yourself, add the following code: * *   importScript('User:Ruakh/CodePointRedirects.js'); * * to your user JavaScript (either Special:MyPage/monobook.js or * Special:MyPage/vector.js or similar, depending on the skin you're using). */

addOnloadHook (  function    {      if(wgArticleId != 0 || wgAction != 'view')         return;      if(! /^U\+[0-9a-fA-F]{4,6}$/.test(wgPageName))        return;      if(/[?&]redirect=no(&|$)/.test(window.location.href))         return;      if(/\bWiktionaryDisableAutoRedirect=true\b/.test(document.cookie))         return;      var x = wgPageName; // e.g. 'U+FFFD'      x = '0x' + x.substr(2); // e.g. '0xFFFD'      x = eval(x); // the character code (as a number)      if(x < 0x10000) // basic multilingual plane         x = String.fromCharCode(x); // the character itself      else         x = // the character itself (as a pair of surrogates)         (  String.fromCharCode ( 0xD800 + (((x - 0x10000) >> 10) & 0x3FF),               0xDC00 +  ((x - 0x10000) & 0x3FF)            ) );     x = encodeURIComponent(x); // e.g. '%EF%BF%BD'

// redirect: window.location.href = (        'http://en.wiktionary.org/wiki/' + x +         '?rdfrom=U+' + wgPageName.substr(2)      ); } );