1jQuery( $ => { 2 // console.log( 'Broken Link Notifier JS Loaded...' ); 3 4 // Which elements to check 5 const elements = blnotifier_front_end.elements; 6 7 /** 8 * Highlight broken link on page 9 */ 10 11 // Get the url query strings 12 const queryString = window.location.search; 13 const urlParams = new URLSearchParams( queryString ); 14 15 // Only continue if a broken link is being searched 16 if ( urlParams.has( 'blink' ) ) { 17 console.log( 'Looking for highlights; checking for broken links paused.' ); 18 const blink = urlParams.get( 'blink' ); 19 $.each( elements, function( tag, attr ) { 20 $( tag ).not( '#wpadminbar ' + tag ).each( function( index ) { 21 const link = $( this ).attr( attr ); 22 if ( link !== undefined && link.includes( blink ) ) { 23 $( this ).addClass( 'glowText' ); 24 if ( $( this ).is( ':hidden' ) ) { 25 var msg = 'It looks like one or more of the links are hidden. To find them, try searching for it in your browser\'s Developer console.'; 26 console.log( msg ); 27 alert( msg ); 28 } else { 29 console.log( 'The element should glow yellow if it is visible on the page. If you do not see it on the page, then it is hidden somewhere. Check any JavaScript elements, too. You can try searching for it in your browser\'s Developer console.' ); 30 } 31 } 32 } ) 33 } ); 34 35 36 /** 37 * Or find broken links on page after load (we don't want to notify if we're looking into it already) 38 */ 39 } else { 40 41 // Notice 42 if ( blnotifier_front_end.show_in_console ) { 43 console.log( '%c Fetching links using the Broken Link Notifier Plugin... ', 'background: #2570AC; color: white' ); 44 } 45 46 // Fetch the links 47 var headerLinks = []; 48 var contentLinks = []; 49 var footerLinks = []; 50 51 $.each( elements, function( tag, attr ) { 52 $( tag ).each( function( index ) { 53 const link = $( this ).attr( attr ); 54 const inAdminBar = $( this ).parents( '#wpadminbar' ).length; 55 const inHeader = $( this ).parents( 'header' ).length; 56 const inFooter = $( this ).parents( 'footer' ).length; 57 if ( link !== undefined && !inAdminBar ) { 58 if ( blnotifier_front_end.scan_header && inHeader ) { 59 headerLinks.push( link ); 60 } else if ( blnotifier_front_end.scan_footer && inFooter ) { 61 footerLinks.push( link ); 62 } else if ( !inHeader && !inFooter ) { 63 contentLinks.push( link ); 64 } 65 } 66 } ) 67 } ); 68 69 // Console log 70 if ( blnotifier_front_end.show_in_console ) { 71 if ( blnotifier_front_end.scan_header ) { 72 console.log( '%c Header links found: ', 'background: #222; color: #bada55' ); 73 console.log( headerLinks ); 74 } 75 console.log( '%c Content links found: ', 'background: #222; color: #bada55' ); 76 console.log( contentLinks ); 77 if ( blnotifier_front_end.scan_header ) { 78 console.log( '%c Footer links found: ', 'background: #222; color: #bada55' ); 79 console.log( footerLinks ); 80 } 81 console.log( '%c Scanning for broken links... please wait. This may take a few minutes if there are a lot of links.', 'background: #2570AC; color: white' ); 82 } 83 84 // Nonce 85 var nonce = blnotifier_front_end.nonce; 86 87 // Start the ajax 88 $.ajax( { 89 type : 'post', 90 dataType : 'json', 91 url : blnotifier_front_end.ajaxurl, 92 data : { 93 action: 'blnotifier_blinks', 94 nonce: nonce, 95 scan_header: blnotifier_front_end.scan_header,
96 scan_footer: blnotifier_front_end.scan_footer, 97 source_url: window.location.href, 98 header_links: headerLinks, 99 content_links: contentLinks, 100 footer_links: footerLinks, 101 }, 102 success: function( response ) { 103 // Success 104 if ( response.type == 'success' ) { 105 if ( blnotifier_front_end.show_in_console ) { 106 107 // Console 108 console.log( '%c Broken Link Scan Results: ', 'background: #2570AC; color: white' ); 109 if ( response.notify ) { 110 console.error( response.notify ); 111 } else { 112 console.info( 'No broken links found. :)' ); 113 } 114 console.log( `%c ${response.timing} `, 'background: #2570AC; color: white' ); 115 } 116 117 // Highlight all on page 118 if ( urlParams.has( 'blinks' ) && urlParams.get( 'blinks' ) == 'true' ) { 119 $.each( response.notify, function( s_index, section ) { 120 $.each( section, function( a_index, a ) { 121 $.each( elements, function( tag, attr ) { 122 $( tag ).each( function( el_index ) { 123 var href = $( this ).attr( attr ); 124 if ( a.link == href ) { 125 $( this ).addClass( 'glowText' ); 126 } 127 } ); 128 } ); 129 } ); 130 } ); 131 } 132 133 // Failure 134 } else if ( response.type == 'error' ) { 135 console.log( 'Scan failed. Please contact plugin developer.' ); 136 } 137 } 138 } ) 139 } 140} )
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.