+𝚒𧴄 - WTF? Who needs this? ( sorta α-working "better likes" for NodeBB )...


  • BINNED

    @Tsaukpaetra said in WTF Bites:

    @zecc said in WTF Bites:

    @tsaukpaetra 0_1511658106968_d4979900-c927-4b45-8ee3-34c67420e4b3-image.png

    👏

    𝚒𧴄

    Yay?

    Moved by request of @zecc...

    Yay! works for you too!


  • Notification Spam Recipient

    @m_adams said in WTF Bites:

    **ENONAME**

    I see....


  • BINNED

    @tsaukpaetra said in WTF Bites:

    I see....

    Yeah just funning around:

    //==UserScript==
    // @name                    MAA∷ Better Unicode Likes (NodeBB)
    // @author                  M_Adams (https://what.thedailywtf.com/user/m_adams)
    // @icon                    https://unicode-table.com/favicon.ico
    // @namespace               NPZY4MVHPXSYU5CAPAZHEMVBF3YU62MENFYZG
    // @version                 20170910.15.25
    // @description             Produce +Unicode 'Like's for NodeBB by turning thread/post/user ids into 2 Unicode glyphs.
    // @include                 https://what.thedailywtf.com/*
    // @include                 http://what.thedailywtf.com/*
    // @copyright               http://www.wtfpl.net/about/
    //                          // @require                 https://code.jquery.com/jquery-3.2.1.min.js
    // @require                 https://cdnjs.cloudflare.com/ajax/libs/punycode/1.4.1/punycode.min.js
    // @require                 https://cdnjs.cloudflare.com/ajax/libs/bignumber.js/4.0.4/bignumber.min.js
    // @require                 https://cdnjs.cloudflare.com/ajax/libs/xregexp/3.2.0/xregexp-all.min.js
    // @resource    UnicodeData https://www.unicode.org/Public/11.0.0/ucd/UnicodeData-11.0.0d1.txt
    //                          // @grant                   none
    // @grant                   GM_registerMenuCommand
    // @grant                   GM_getResourceText
    // @grant                   GM_getValue
    // @grant                   GM_setValue
    // @grant                   GM_listValues
    // @grant                   GM_info
    // @grant                   GM_deleteValue
    // @grant                   GM_log
    // @grant                   unsafeWindow
    //==/UserScript==
    
    /* Based off of Discourse "Better Likes"
     * by Accalia (https://what.thedailywtf.com/user/accalia) in (https://what.thedailywtf.com/post/12733)
     *
     */
    
    /* jshint undef:true, unused:true, trailingcomma:true verbose:true, -W032:true */
    
    /* globals alert, app, BigNumber, console, jQuery, JSON, punycode, unsafeWindow, XRegExp,
    GM_registerMenuCommand, GM_getResourceText, GM_getValue, GM_log,
     GM_setValue, GM_listValues, GM_info, GM_deleteValue */
    
    // ; jQuery.noConflict() ;
    
    ( function ( $ ) {
    
             // FIXME: why u no trigger?? :
             $(window)[0].addEventListener( 'action:posts.loaded',
                                            function( event, data ) {
             	                                    alert ( 'action:posts.loaded' ) ;  // to inspect what is passed back by NodeBB
                                                    GM_log( 'action:posts.loaded' ) ;
                                            },
                                            true
                         )
             ;
    
        
              var big2         = new BigNumber( 2 ) ,
                  isUnassigned = XRegExp( '\\p{Unassigned}', 'A' ) ,
                  isAssigned   = XRegExp( '\\P{Unassigned}', 'A' ) ,
                  
                  uniData      = ( function () {
                                            var temp ,
                                                text ,
                                                vCheck = GM_info.script.resources[0].url ; // url of UnicodeData resource
                                            
                                            // check to see if uniData value is set:
                                            if ( ( temp = GM_getValue( 'uniData' ) ) ) { //
                                            
                                                 temp = JSON.parse( temp ) ;
                                                 
                                                 //check to see if uniData value's url (its *version*) matches the UnicodeData resource's url:
                                                 if ( temp.url === vCheck ) {
                                                      return temp ;
                                                 }
                                            }
                                            
                                            temp = {} ;
                                            
                                            // UnicodeData resource has never been processed, or has been up/down-graded
                                            // set uniData.url to UnicodeData.url
                                            temp.url = vCheck ;
                                            
                                            
                                            // pull UnicodeData resource as array of lines
                                            text = GM_getResourceText( 'UnicodeData' ).split( '\n' ) ;
                                            
                                            // split UnicodeData resource into lines, split each line on ';' returning only first 2 splits:   
                                            // set [ uniData.[ split[0] ] : split[1] ]
                                            text.forEach( function( line ) {
                                                                  var hex, name;
                                                                  [ hex, name ] = line.split( ';', 2 ) ;
                                                                  temp[ hex.toString(16).toUpperCase() ]   = name ;
                                                          }
                                                 );
                                                 
                                            // save uniData as JSON
                                            GM_setValue( 'uniData', JSON.stringify( temp ) ) ;
                                            
                                            return temp;
                                 } ) ()
              ;
        
              var uniTable = { min       :     0x21, // trying to stay in the non surrogate range for glyphs. 0x20 and below are ASCII control codes
                               max       :  0x2FA1F, // 0x2FA20 + are tags and variation selectors supplement.
                               ws        :   0x2423, // this will be used to replace any non glyph or ws code points ( ␣ ).
                               poop      :  0x1F4A9, // we'll use this glyph as an error glyph
                               zwj       :   0x200D, // zero width joiner
                               // I tried to find all the non glyph / ws code points: 
                               badList   : [   0x85,   0xA0, 0x1680, 0x180E, 0x2028,
                                             0x2029, 0x202F, 0x205F, 0x2060, 0x3000,
                                             0xFEFF,
                                           ],
                               badRanges : [
                                             // Min  , Max
                                                          // misc ws, Cs, and unassigned ranges
                                             [   0x870,   0x89F ] ,
                                             [  0x1C90,  0x1CBF ] ,
                                             [  0x2000,  0x200D ] ,
                                             [  0x2FE0,  0x2FEF ] ,
                                             [  0xD800,  0xF8FF ] ,
                                             [  0xFE00,  0xFE0F ] , 
                                             [  0xFFF0,  0xFFFF ] ,
                                             [ 0x10200, 0x1027F ] ,
                                             [ 0x103E0, 0x103FF ] ,
                                             [ 0x10570, 0x105FF ] ,
                                             [ 0x10780, 0x107FF ] ,
                                             [ 0x108B0, 0x108DF ] ,
                                             [ 0x10940, 0x1097F ] ,
                                             [ 0x10AA0, 0x10ABF ] ,
                                             [ 0x10BB0, 0x10BFF ] ,
                                             [ 0x10C50, 0x10C7F ] ,
                                             [ 0x10D00, 0x10E5F ] ,
                                             [ 0x10E80, 0x10FFF ] ,
                                             [ 0x11250, 0x1127F ] ,
                                             [ 0x11380, 0x113FF ] ,
                                             [ 0x114E0, 0x1157F ] ,
                                             [ 0x116D0, 0x116FF ] ,
                                             [ 0x11740, 0x1189F ] ,
                                             [ 0x11900, 0x119FF ] ,
                                             [ 0x11AB0, 0x11ABF ] ,
                                             [ 0x11B00, 0x11BFF ] ,
                                             [ 0x11CC0, 0x11C6F ] ,
                                             [ 0x11CC0, 0x11FFF ] ,
                                             [ 0x12550, 0x12FFF ] ,
                                             [ 0x13430, 0x143FF ] ,
                                             [ 0x14680, 0x167FF ] ,
                                             [ 0x16A70, 0x16ACF ] ,
                                             [ 0x16B90, 0x16EFF ] ,
                                             [ 0x16FA0, 0x16FDF ] ,
                                             [ 0x17000, 0x187FF ] ,
                                             [ 0x18B00, 0x1AFFF ] ,
                                             [ 0x1B130, 0x1B16F ] ,
                                             [ 0x1B300, 0x1BBFF ] ,
                                             [ 0x1BCB0, 0x1CFFF ] ,
                                             [ 0x1D250, 0x1D2FF ] ,
                                             [ 0x1D380, 0x1D3FF ] ,
                                             [ 0x1DAB0, 0x1DFFF ] ,
                                             [ 0x1E030, 0x1E7FF ] ,
                                             [ 0x1E8E0, 0x1E8FF ] ,
                                             [ 0x1E960, 0x1EDFF ] ,
                                             [ 0x1EF00, 0x1EFFF ] ,
                                             [ 0x1FA00, 0x1FFFF ] ,
                                             [ 0x2A6E0, 0x2A6FF ] ,
                                             [ 0x2CEB0, 0x2F7FF ] ,
                                           ],
                           } ;
              var rangeSize = uniTable.max - uniTable.min + 1 ;
              
              function reBase ( nbr ) {
                       // make sure we keep nbr in range:
                       var new_nbr   = ( nbr % rangeSize ) + uniTable.min ;
                  
                       // replace badList numbers
                       new_nbr = uniTable.badList.indexOf( new_nbr ) === -1 ? new_nbr : uniTable.ws ;
                  
                       // promote "out of zones":
                       uniTable.badRanges.forEach( function ( zone ) {
                                                         var min = zone[0], max = zone[1];
                                                         if ( ( new_nbr >= min ) && ( new_nbr <= max ) ) {
                                                              new_nbr = max + new_nbr - min + 1 ;
                                                         }
                                                }
                                          );
                       
                       return new_nbr ;
              }
        
              function bigReBase ( bigNbr ) {
                       // make sure we keep nbr in range:
                       var new_nbr   = bigNbr.mod( rangeSize ).toNumber() + uniTable.min ;
                  
                       return reBase( new_nbr ) ;
              }    
              
              function getGlyph ( candidate ) {
                       // try to work our way past unassigned code points stuck in the middle of assigned ranges
                       var temp = punycode.ucs2.encode( [ candidate ] ) ;
                       if ( isAssigned.test( temp ) ) {
                           return [ temp, candidate ] ;
                       }
                       while ( isUnassigned.test( temp ) ) {
                              candidate = reBase( bigReBase( candidate + 1 ) ) ;
                              temp      = punycode.ucs2.encode( [ candidate ] ) ;
                       }
                       return [ temp, candidate ];                          
              }
    
    /*
              next 2 functions are based on «Enumerated path functions from "Trees and Hierarchies in SQL for Smarties" (Celko 2004)»
              translated to perl and then to javascript.
              I believe Celko adapted the SQL from «Nested Intervals Tree Encoding in SQL — Vadim Tropashko»
        
              the perl functions are :
                                      Tuple_isValid      : # a "good tuple" should be an array ref containing 2 and only 2 numbers !
                                      isSame_Tuple       : # null != null, and null != anything else either...
                                      Tuple_2_String_Rep : # returns string representation of a [numer,denom] ref as "numer/denom" .
                                      Find_X             : # returns the "X" coordinate of the node map as:     [ numerator, denominator ] .
                                      Find_Y             : # returns the "Y" coordinate of the node map as:     [ numerator, denominator ] .
                                      Find_Parent        : # given a node map, return its parent's node map .
                                      Find_Root          : # given a node map, return the "top level" node map for the path
                                      Find_Sibling_Nbr   : # given a node map, return it's path "sibling number" e.g.: '7/8' = '2.1', the "sibling number" is '1' .
                                      Mapping_2_Path_Str : # given a node map, return it's "path string" e.g.: '7/8' -> '2.1' .
                                      Find_Distance      : # given two node maps, return the "distance" between them.  Interface/set-up/controller routine...
                                                           # if only one node map is given, we find its "root" node and use that in place of the right arg,
                                                           # essentially making this a "Find Depth" routine in that case...
                                      __fd_start         : # !!!!!!!!!!!!!!  helper function for Find_Distance() see all its notes above !!!!!
                                      __fd_recurse       : # !!!!!!!!!!!!!!!!!!  work horse for __fd_start() see all its notes above !!!!!
                                      Find_Child         : # helper for Path_Str_2_Mapping(), computes the numerator and denominator of the new new node.
                                      Path_Str_2_Mapping : # given an enumerated path like '1.2.3.4.5' return its node map. '1.3' -> '19/16' .
                                      Find_LeftInterval  : # return left interval boundary helper function for cmp_*()
                                      Find_RightInterval : # return right interval boundary helper function for cmp_*()
                                      and finally        : comparison functions cmp_inc() and cmp_dec() w/ caching
              we only need the Find_Child() and Path_Str_2_Mapping() functions and the Path...() function I reworked as we won't be actually passing path as strings.
    */    
              function Find_Child ( node, child ){
                       // helper for Path_Array_2_Mapping(), computes the numerator and denominator of the new new node.
                       // nodes are dyadic fractions!
            
                       var [ numerator, denominator ] = node ;
                       var ch_pow_of_2                = big2.pow( child ) ;
                   
                       numerator  =  ch_pow_of_2.times( numerator ).plus( 3 ).minus( ch_pow_of_2 ) ; 
                                                                                                     
                       denominator = ch_pow_of_2.times( denominator ) ;                              
                                                                                                                
                       return [ numerator, denominator ] ;
              }
        
              function Path_Array_2_Mapping ( path ){
                       // given an enumerated path like '1.2.3.4.5' split to an array [ 1, 2, 3, 4, 5 ] return its node map.
                       // '1.3' -> [ 1, 3 ] -> [ 19, 16 ] .
                       
                       var node = [ 1, 1 ] ;
                       path.forEach( function ( step ) {
                                              node = Find_Child( node, step ) ;
                       } ) ;
                   
                       return node ;
              }
     
              function Number2Unicode (){
                       /* TODO - add a button to the left of [Reply] and automate everything:
                        * click [^] to do the upvote and:
                        * if unsafeWindow.getSelection is:
                        *                          !null then click [Quote];
                        *                           null then click [Reply];
                        * then "do the needful :)" below:
                        */
                  
                       var tempVal, $composer,
                           tagline, postIdx,    topic,
                  
                           X          = {} ,
                           Y          = {} ,
                           codePoints = [] ,
                           whoAmI     = parseInt( app.user.uid ) ,
                           ids        = unsafeWindow.location.href.match( /\/topic\/(\d+)\/.+\/(\d+)\??/ )                       
                       ;
                  
                       topic         = parseInt( ids[ 1 ] ) ;
                       postIdx       = parseInt( ids[ 2 ] ) ;
                       var range     = unsafeWindow.getSelection().getRangeAt( 0 ) ;
                  
                       codePoints[0]    = Number.isInteger( topic )   ?  reBase( topic )   : uniTable.poop ;
                       codePoints[1]    = Number.isInteger( postIdx ) ?  reBase( postIdx ) : uniTable.poop ;
                       codePoints[2]    = Number.isInteger( whoAmI )  ?  reBase( whoAmI )  : uniTable.poop ;
                  
                       [ X.raw  , Y.raw  ] = Path_Array_2_Mapping( codePoints ) ;
                       [ X.code , Y.code ] = [ reBase( bigReBase( X.raw ) ), reBase( bigReBase( Y.raw ) ) ] ;
                  
                       [ X.glyph, X.code ] = getGlyph( X.code ) ; // we may get "re-mapped"
                       [ Y.glyph, Y.code ] = getGlyph( Y.code ) ;
                       [ X.HEX  , Y.HEX  ] = [ X.code.toString(16).toUpperCase(), Y.code.toString(16).toUpperCase() ] ;
                       [ X.name , Y.name ] = [ ( uniData[ X.HEX ] || '**ENONAME**' ), ( uniData[ Y.HEX ] || '**ENONAME**' ) ] ;
                  
                       tagline             = [
                                              '\n<span title = "(', topic, '|', postIdx, '|', whoAmI, ') → \n',
                                                               '( U+', X.HEX, ' | U+', Y.HEX, ' ) → \n',
                                                               '( ', X.name, ' | ', Y.name, ' )\n',
                                                               'Produced by a alpha version userscript by @&#', uniTable.zwj, 'M_Adams...">', 
                                                               '<sup>:fa_plus:</sup><big><big><big><big><big>',
                                                                                    X.glyph, Y.glyph,
                                                                                   '</big></big></big></big></big>',
                                              '</span>\n',
                                             ].join('')
                                            ;
                  
                       if ( window.location.hostname === 'what.thedailywtf.com' ) {
         
                           $.valHooks.textarea =
                                     {
                                      get: function( elem ) {
                                                   return elem.value.replace( /\r?\n/g, "\r\n" ) ;
                                           }
                                     } ;
                                     
                           $composer = $( 'div.write-container > textarea' ) ;
                           tempVal = $composer.val() ;
                           $composer.val( tempVal + tagline ) ;
                       }
         
         
                       else {
         
                             range.deleteContents() ;
                             range.insertNode( document.createTextNode( tagline ) ) ;
                       }
              }
              
              function cleanData () {
                       var keys = GM_listValues() ;
                       for ( var i = 0, key = null; ( key = keys[ i ] ); i++ ) {
                              GM_deleteValue( key ) ;
                       }
              }
        
              GM_registerMenuCommand( "↔ Produce a +Unicode 'Like'", Number2Unicode ) ;
              GM_registerMenuCommand( "Unicode 'Like' Data reset",   cleanData      ) ;
              
    
    } ) ( jQuery ) ;

  • Notification Spam Recipient

    @m_adams Tampermonkey doesn't seem to like. :( Oh well...


  • BINNED

    @tsaukpaetra said in WTF Bites:

    Tampermonkey

    WFM :)... (chrome)
    0_1511491104226_a884bfd2-b134-4981-b455-1fddc973e130-image.png ..

    Edit... could be the markdown fuckery changing bi-directional arrow to the "↔" icon...
    Really just fuckin' leave code as written markdown...


  • Notification Spam Recipient

    @m_adams said in WTF Bites:

    @tsaukpaetra said in WTF Bites:

    Tampermonkey

    WFM :)... (chrome)
    0_1511491104226_a884bfd2-b134-4981-b455-1fddc973e130-image.png ..

    Yeah, it complains about "verbose" not being a thing and a few unused variables, but other than that IDK it doesn't seem to do anything...


  • BINNED

    @tsaukpaetra said in WTF Bites:

    IDK it doesn't seem to do anything...

    It's not yet automated*. Check your tampermonkey menu:
    0_1511491440806_f0e44081-5fd6-4426-b053-0348c8852f23-image.png

    click the first one (...Produce...) while the editor is open and then hit "↲"...

    *EDIT:

    /* TODO - add a button to the left of [Reply] and automate 
     * click [^] to do the upvote and:
     * if unsafeWindow.getSelection is:
     *                          !null then click [Quote];
     *                           null then click [Reply];
     * then "do the needful :)" below:
     */
    var tempVal, $composer, ....

  • BINNED

    @tsaukpaetra said in WTF Bites:

    "verbose" not being a thing

    verbose
    Default true, if true then show the JSHint error code for each issue

    a few unused variables. (event and data):

    // FIXME: why u no trigger?? :
    $(window)[0].addEventListener( 'action:posts.loaded',
                                   function( event, data ) {
    	                                    alert ( 'action:posts.loaded' ) ;  // to inspect what is passed back by NodeB
                                           GM_log( 'action:posts.loaded' ) ;
                                   },
                                   true
                )
    ;

  • Notification Spam Recipient

    @m_adams said in WTF Bites:

    @tsaukpaetra said in WTF Bites:

    IDK it doesn't seem to do anything...

    It's not yet automated*. Check your tampermonkey menu:
    0_1511491440806_f0e44081-5fd6-4426-b053-0348c8852f23-image.png

    click the first one (...Produce...) while the editor is open and then hit "↲"...

    *EDIT:

    /* TODO - add a button to the left of [Reply] and automate 
     * click [^] to do the upvote and:
     * if unsafeWindow.getSelection is:
     *                          !null then click [Quote];
     *                           null then click [Reply];
     * then "do the needful :)" below:
     */
    var tempVal, $composer, ....
    

    0_1511496259579_e8640457-6750-4fac-b437-b63bd0afc7d0-image.png

    🤷


  • BINNED

    @tsaukpaetra hmmmm.... why no menu entries... are you inifiniscrolling?

    Maybe try
    0_1511497195705_0b7071d0-bcae-4dd0-9a6b-8b5331aa603f-image.png


  • Notification Spam Recipient

    @m_adams said in WTF Bites:

    @tsaukpaetra hmmmm.... why no menu entries... are you inifiniscrolling?

    Maybe try
    0_1511497195705_0b7071d0-bcae-4dd0-9a6b-8b5331aa603f-image.png

    Yes. An no dice with the different injection point.


  • BINNED

    @m_adams said in WTF Bites:

    Maybe try

    And be sure line 334 looks like:
    0_1511497399259_cdde7a9b-689a-409c-a091-cfecff5470f8-image.png
    The compiler could just die if the double ended arrow is emotified...


  • BINNED

    @tsaukpaetra said in WTF Bites:

    Yes.

    Try going w/out infiniscroll... (I think it's a stupid thing but I'm old :belt_onion: )


  • Notification Spam Recipient

    @m_adams said in WTF Bites:

    @tsaukpaetra said in WTF Bites:

    Yes.

    Try going w/out infiniscroll... (I think it's a stupid thing but I'm old :belt_onion: )

    enabled pages, refreshed, still no go. 🤷♂ Oh well.

    I do get this though:

    0_1511507872577_92699104-6fae-4492-856e-00597e78820d-image.png


  • 🚽 Regular

    @m_adams said in WTF Bites:

    poop : 0x1F4A9, // we'll use this glyph as an error glyph

    💩


  • BINNED

    @tsaukpaetra said in WTF Bites:

    I do get this though:0_1511657478315_8af1901c-38c6-4a3e-8d55-ab8bb949a846-image.png

    Okay! - try version 20171125.17.45:

    1. trying to fix TSAUKPAETRA's issue in (https://what.thedailywtf.com/post/1270066)
      and discovered that resource UnicodeData was pointing at a moving target
      (https://www.unicode.org/Public/11.0.0/ucd/UnicodeData-11.0.0d1.txt)...
      That file is now replaced by ...-11.0.0d7.txt ! ! ! Changed the resource to point to the finalized 10.0.0
      version 'UnicodeData.txt', as '11.0.0' is β/RFC status.
    2. added some t/c and logging to try and cover more bases...

  • Notification Spam Recipient

    @m_adams said in WTF Bites:

    Okay! - try version 20171125.17.45:

    Attempting...

    🁑𛲋

    It... did something? I got to squares. Hopefully that's meaningful on some other device.


  • 🚽 Regular

    @tsaukpaetra 0_1511658106968_d4979900-c927-4b45-8ee3-34c67420e4b3-image.png

    Edit: maybe consider moving this discussion elsewhere? Too lazy to flag atm.


  • Notification Spam Recipient

    @zecc said in WTF Bites:

    @tsaukpaetra 0_1511658106968_d4979900-c927-4b45-8ee3-34c67420e4b3-image.png

    👏

    𝚒𧴄

    Yay?