PageSourceSearch

https://www.reviewcollections.com/wp-content/plugins/thirstyaffiliates/js/app/ta.js

js reviewcollections.com collected 2026-09-26 07:32:22 UTC 11,200 bytes, 275 lines download raw bytes

1var thirstyFunctions;
2
3jQuery( document ).ready( function($) {
4
5    thirstyFunctions = {
6
7        /**
8         * Function that holds all of the necessary events to trigger a record link stat.
9         *
10         * @since 3.2.0
11         */
12        recordLinkStatEvents : function() {
13
14            // record link on normal click
15            if ( thirsty_global_vars.enable_record_stats == 'yes' )
16                $( 'body' ).on( 'click' , 'a' , thirstyFunctions.recordLinkStat );
17        },
18
19        /**
20         * Record link clicks AJAX event trigger.
21         *
22         * @since 3.0.0
23         * @since 3.2.0 Removed event trigger. Added keyword variable in the AJAX trigger.
24         * @since 3.3.0 Add javascript redirect feature.
25         * @since 3.3.1 Make sure the duplicate click prevention only works on affiliate links.
26         * @since 3.3.7 Add fail script for enhanced js redirect to still work on AJAX failure.
27         * @since 3.4.0 Make sure query strings are added back when enhanced js redirect is active.
28         */
29        recordLinkStat : function( e ) {
30
31            var $link   = $(this),
32                href    = $link.attr( 'href' ),
33                linkID  = $link.data( 'linkid' ),
34                keyword = $link[0].innerText,
35                qs      = href ? href.split('?')[1] : '', // get the url query strings
36                imgsrc,
37                newWindow,
38                monsterInsightsOnBeforeUnload;
39
40            if ( ! keyword ) keyword = $link.text();
41
42            // if link clicked is not an affiliate link, then skip.
43            if ( ! thirstyFunctions.isThirstyLink( href ) && ! linkID ) return;
44
45            // skip ThirstyPay links
46            if ( $link.data('thirstypay') ) {
47                return;
48            }
49
50            // prevent duplicate clicks.
51            if ( $link.data( "clicked" ) ) {
52                e.preventDefault();
53                return;
54            }
55            $link.data( "clicked"  , true );
56
57            // get image filename and use it as keyword.
58            if ( ! keyword && $link.find( 'img' ).length ) {
59
60                imgsrc  = $link.find( 'img' ).prop( 'src' ).split('/');
61                keyword = imgsrc[ imgsrc.length - 1 ];
62            }
63
64            if ( thirsty_global_vars.enable_js_redirect === 'yes' && $link.data( 'nojs' ) != true ) {
65
66                e.preventDefault();
67
68                if ( $link.prop( 'target' ) == '_blank' && ! thirstyFunctions.disableNewWindow() ) {
69                    newWindow = window.open( '', '_blank' );
70                } else if ( window.MonsterInsightsObject ) {
71                    setTimeout( function () {
72                        if ( typeof window.onbeforeunload === 'function' ) {
73                            monsterInsightsOnBeforeUnload = window.onbeforeunload;
74                        }
75                    }, 50 );
76                }
77            }
78
79            $.post( thirsty_global_vars.ajax_url , {
80                action  : 'ta_click_data_redirect',
81                href    : href,
82                page    : window.location.href,
83                link_id : linkID,
84                keyword : keyword,
85                qs      : qs
86            } , function( redirect_url ) {
87
88                $link.data( "clicked"  , false );
89
90                if ( thirsty_global_vars.enable_js_redirect !== 'yes' || $link.data( 'nojs' ) == true )
91                    return;
92
93                if ( newWindow ) {
94                    newWindow.location.href = redirect_url ? redirect_url : href;
95                } else {
96                    if ( typeof monsterInsightsOnBeforeUnload === 'function' && window.onbeforeunload === null ) {
97                        window.onbeforeunload = monsterInsightsOnBeforeUnload;
98                    }
99
100                    window.location.href = redirect_url ? redirect_url : href;
101                }
102
103            } ).fail( function() {
104
105                $link.data( "clicked"  , false );
106
107                if ( thirsty_global_vars.enable_js_redirect !== 'yes' || $link.data( 'nojs' ) == true )
108                    return;
109
110                if ( newWindow ) {
111                    newWindow.location.href = href;
112                } else {
113                    if ( typeof monsterInsightsOnBeforeUnload === 'function' && window.onbeforeunload === null ) {
114                        window.onbeforeunload = monsterInsightsOnBeforeUnload;
115                    }
116
117                    window.location.href = href;
118                }
119
120            } );
121        },
122
123        /**
124         * Check if we need to disable new window for enhanced javascript redirects.
125         * This is intended to fix issue on browsing sites with FB/Messenger webview browser on iPhones.
126         *
127         * @since 3.3.6
128         * @since 3.6 Add support for Instagram, Pinterest, Twitter, Electron and Steam.
129         */
130        disableNewWindow : function() {
131
132            var strings = [ 'FBAN' , 'MessengerForiOS' , 'FBAV' , 'Instagram' , 'Pinterest' , 'Twitter' , 'Electron' , '
132Steam' ];
133
134            for ( var x in strings ) {
135                if ( navigator.userAgent.indexOf( strings[x] ) >= 0 )
136                    return true;
137            }
138
139            return false;
140        },
141
142        /**
143         * Function to check if the loaded link is a ThirstyAffiliates link or not.
144         *
145         * @since 3.0.0
146         * @since 3.1.2 Make function detect root relative URLs.
147         */
148        isThirstyLink : function( href ) {
149
150            if ( ! href )
151                return;
152
153            href = href.replace( 'http:' , '{protocol}' ).replace( 'https:' , '{protocol}' );
154
155            var link_uri = href.replace( thirsty_global_vars.home_url , '' ).replace( '{protocol}' , '' ),
156                link_prefix, new_href;
157
158            link_uri    = link_uri.indexOf( '/' ) == 0 ? link_uri.replace( '/' , '' ) : link_uri;
159            link_prefix = link_uri.substr( 0 , link_uri.indexOf( '/' ) ),
160            new_href    = href.replace( '/' + link_prefix + '/' , '/' + thirsty_global_vars.link_prefix + '/' ).replace( '{protocol}' , window.location.protocol );
161
162            return ( link_prefix && $.inArray( link_prefix , link_prefixes ) > -1 ) ? new_href : false;
163        },
164
165        /**
166         * Function to check if the loaded link is a ThirstyAffiliates link or not.
167         *
168         * @since 3.0.0
169         * @since 3.3.0 Add data-nojs attribute support.
170         * @since 3.3.5 Make sure href property of links available before fetching the query strings.
171         */
172        linkFixer : function() {
173
174            if ( thirsty_global_vars.link_fixer_enabled !== 'yes' )
175                return;
176
177            var $allLinks = $( 'body a' ),
178                hrefs     = [],
179                href, linkClass, isShortcode, isImage , key;
180
181            // fetch all links that are thirstylinks
182            for ( key = 0; key < $allLinks.length; key++ ) {
183
184                href        = $( $allLinks[ key ] ).attr( 'href' );
185                linkClass   = $( $allLinks[ key ] ).attr( 'class' );
186                isShortcode = $( $allLinks[ key ] ).data( 'shortcode' );
187                isImage     = $( $allLinks[ key ] ).has( 'img' ).length;
188                href        = thirstyFunctions.isThirstyLink( href );
189
190                if ( href && ! isShortcode )
191                    hrefs.push({ key : key , class : linkClass , href : href , is_image : isImage });
192
193                $( $allLinks[ key ] ).removeAttr( 'data-shortcode' );
194            }
195
196            // skip if there are no affiliate links
197            if ( hrefs.length < 1 )
198                return;
199
200            $.post( thirsty_global_vars.ajax_url , {
201                action  : 'ta_link_fixer',
202                hrefs   : hrefs,
203                post_id : thirsty_global_vars.post_id
204            }, function( response ) {
205
206                if ( response.status == 'success' ) {
207
208                    for ( var x in response.data ) {
209
210                        // make sure response data is valid before proceeding.
211                        if ( typeof response.data[ x ] != 'object' ) continue;
212
213                        var key       = response.data[ x ][ 'key' ],
214                            hrefProp  = $( $allLinks[ key ] ).prop( 'href' ),
215                            qs        = hrefProp ? hrefProp.split('?')[1] : '', // get the url query strings
216                            href      = response.data[ x ][ 'href' ],
217                            title     = response.data[ x ][ 'title' ],
218                            className = response.data[ x ][ 'class' ],
219                            thirstypay = response.data[ x ][ 'thirstypay' ],
220                            connector;
221
222                        if ( qs && response.data[ x ][ 'pass_qs' ] ) {
223                            connector = href.indexOf( '?' ) < 0 ? '?' : '&';
224                            href      = href + connector + qs;
225                        }
226
227                        // update protocol to replace it with the one used on the site.
228                        href = href.replace( 'http:' , window.location.protocol ).replace( 'https:' , window.location.protocol );
229
230                        // add the title if present, if not then remove the attribute entirely.
231                        if ( title )
232                            $( $allLinks[ key ] ).prop( 'title' , title );
233                        else
234                            $( $allLinks[ key ] ).removeAttr( 'title' );
235
236                        // if disable_thirstylink_class is set to yes then remove the thirstylink and thirstylinkimg classes.
237                        if ( thirsty_global_vars.disable_thirstylink_class == 'yes' )
238                            className = className.replace( 'thirstylinkimg' , '' ).replace( 'thirstylink' , '' ).trim();
239
240                        if ( className )
241                            $( $allLinks[ key ] ).prop( 'class' , className );
242                        else
243                            $( $allLinks[ key ] ).removeAttr( 'class' );
244
245                        // map the other attributes.
246                        $( $allLinks[ key ] ).prop( 'href' , href )
247                          .prop( 'rel' , response.data[ x ][ 'rel' ] )
248                          .prop( 'target' , response.data[ x ][ 'target' ] )
249                          .attr( 'data-linkid' , response.data[ x ][ 'link_
249id' ] );
250
251                        // set thirstypay data attribute
252                        if ( thirstypay ) {
253                            $( $allLinks[key] ).attr( 'data-thirstypay', true );
254                        }
255
256                        // tag links as "nojs" to disable JS redirect for them.
257                        if ( thirsty_global_vars.enable_js_redirect === 'yes' )
258                            $( $allLinks[ key ] ).attr( 'data-nojs' , response.data[ x ][ 'nojs' ] );
259
260                    }
261                }
262            }, 'json' );
263        }
264    }
265
266    var link_prefixes = $.map( thirsty_global_vars.link_prefixes , function(value , index) {
267        return [value];
268    });
269
270    // Initiate record link click stat function
271    thirstyFunctions.recordLinkStatEvents();
272
273    // Initialize uncloak links function
274    thirstyFunctions.linkFixer();
275});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.