Обговорення » Creation Requests

Parse [e]...[/e] tags

§
Опубліковано: 02.05.2017
Edited: 02.05.2017

Parse [e]...[/e] tags

Hi there,
Sometimes, I come across posts (typically in a forum where you can post from web-based interface or from an Android app) where 'smilies' or 'emojis' appear as a sequence of [e]...hex value...[/e] instead of the proper Unicode character.
Could it be possible to write a script that intercepts those sequences and convert them to the corresponding Unicode character before display? (maybe dependant of the browser/OS, I dunno)
Thanks in advance :)

§
Опубліковано: 05.05.2017
Edited: 05.05.2017

something like this:

// ==UserScript==
// @name        eehex
// @namespace   greasyforum
// @description replace [e]XXXX[/e] with &#xXXXX;
// @include https://greasyfork.org/*/forum/discussion/*
// @include file:///E:/RES/testo.htm
// @run-at document-end
// ==/UserScript==
var re=/\[e]([0-9a-fA-F].+?)\[\/e]/g;
function eehex(s){
  return s.replace(re,
         function(m, p1){ return '&#x'+p1+';'; }
        );
}
var  eeserver = new MutationObserver(function(muts) {
   var m, t, tc;
  for( var  i=0; i<muts.length ; i++){
   if( !(m=muts[i]) && !(t=m.target)) continue;
   var nn=m.addedNodes, n, nl=nn.length;
   for( var j=0;  j<nl  ; j++){
     if( (n=nn[j]) && (tc=n.innerHTML)  ){
      if ( re.test(tc) ) n.innerHTML=eehex(tc);
    }
  }}
});
if(document.body && ~document.body.innerHTML.indexOf('[/e]'))
 document.body.innerHTML=eehex(document.body.innerHTML);

eeserver.observe(document, { attributes: true, subtree:true, childList: true  } );

? ? ?

§
Опубліковано: 05.05.2017
Edited: 05.05.2017

? code updated [e]1f600[/e] [e]1F637[/e]

§
Опубліковано: 05.05.2017

now works as intended [e]1f60e[/e]

§
Опубліковано: 05.05.2017
Edited: 05.05.2017

✘✖✗ Alas, Chrome can't show unicode smiles ✙✝✞

§
Опубліковано: 05.05.2017
Edited: 05.05.2017

-

§
Опубліковано: 14.05.2017

Sorry for my late reply, I was away for some days ;)
Gonna try it asap! Thanks

§
Опубліковано: 14.05.2017

[e]1f609[/e]
Indeed :( probable some missing fonts in Chrome :(

Опублікувати відповідь

Sign in to post a reply.