<commit_before>"use strict";

/********************************************************
 * Gag Reflex main class
 * @constructor
 */
var GagFacebook = function ( config )
{
    //this.self = this;

    //this.ARTICLE_CLASS = "div[aria-label=\"Story\"] div._1dwg";
    this.ARTICLE_CLASS = "div[role=\"article\"]";
    //this.ARTICLE_CLASS = "div._5pcr";
    this.ARTICLE_LINK_SELECTOR = "a._6kt, a._52c6, div._6m6>a, userContent a";

    this.REFRESH_DELAY = 1000;

    this._config = config;

    this.start = function()
    {
        //setTimeout( this.runHighlighting.bind( this ), this.REFRESH_DELAY );
        this.runHighlighting();
    }

    /**
     *
     * @param link
     * @return {string}
     */
    function deShimFacebookLink( link )
    {
        var href_match = link.href.match( /\?u=(.*)&/ );
        if ( href_match[1] ) {
            var url = decodeURIComponent( href_match[1] );
            var host = url.match( /http[s?]:\/\/(.*)\// );
            if (host) return host[1];
        }
        return null;
    }

    /***************************************
     * Callback to do highlighting on page
     */
    this.runHighlighting = function ()
    {
        var gag = this;
        $( gag.ARTICLE_CLASS ).each(
                function ()
                {
                    var article = this;

                    $( gag.ARTICLE_LINK_SELECTOR, article ).each( function ()
                    {
                        var href = this.host;

                        if ( href != null ) {
                            if ( href.indexOf( "facebook.com" ) > -1 ) {
                                href = deShimFacebookLink( this );
                                if ( href == null ) {
                                    return;
                                }
                            }
                            for ( var gi in gag._config.groups ) {
                                if ( gag._config.groups[gi].is_enabled ) {
                                    if ( parse( gag._config.groups[gi], href, article ) ) {
                                        break;<commit_msg>More robust pattern matching on Facebook hostname deshimming<commit_after>"use strict";

/********************************************************
 * Gag Reflex main class
 * @constructor
 */
var GagFacebook = function ( config )
{
    //this.self = this;

    //this.ARTICLE_CLASS = "div[aria-label=\"Story\"] div._1dwg";
    this.ARTICLE_CLASS = "div[role=\"article\"]";
    //this.ARTICLE_CLASS = "div._5pcr";
    this.ARTICLE_LINK_SELECTOR = "a._6kt, a._52c6, div._6m6>a, userContent a";

    this.REFRESH_DELAY = 1000;

    this._config = config;

    this.start = function()
    {
        //setTimeout( this.runHighlighting.bind( this ), this.REFRESH_DELAY );
        this.runHighlighting();
    }

    /**
     *
     * @param link
     * @return {string}
     */
    function deShimFacebookLink( link )
    {
        var href_match = link.href.match( /\?u=(.*)&/ );
        if ( href_match[1] ) {
            var url = decodeURIComponent( href_match[1] );
            var host = url.match( /^((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/ );
            if ( host ) {
                return host[3];
            }
        }
        console.warn( "Could not deshim ", link );
        return null;
    }

    /***************************************
     * Callback to do highlighting on page
     */
    this.runHighlighting = function ()
    {
        var gag = this;
        $( gag.ARTICLE_CLASS ).each(
                function ()
                {
                    var article = this;

                    $( gag.ARTICLE_LINK_SELECTOR, article ).each( function ()
                    {
                        var href = this.host;

                        if ( href != null ) {
                            if ( href.indexOf( "facebook.com" ) > -1 ) {
                                href = deShimFacebookLink( this );
                                if ( href == null ) {
                                    return;
                                }
                            }
                            for ( var gi in gag._config.groups ) {
                                if ( gag._config.groups[gi].is_enabled ) {
                                    if ( parse( gag._config.groups[gi], href, article ) ) {
                                        break;
{'fraction_non_alphanumeric': 0.17276422764227642, 'fraction_numerical': 0.007226738934056007, 'mean_word_length': 1.2794647452393206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6931713', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1215, 'n_words': 241}