Skip to content

Commit

Permalink
tweak js
Browse files Browse the repository at this point in the history
  • Loading branch information
tillkruss committed Feb 24, 2019
1 parent fb37721 commit 9c08dc7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions includes/email-detector.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
( function () {
var fetchPageSource = function () {
if ( ! document.getElementById( "wpadminbar" ) ) {
if ( ! document.getElementById( "wp-admin-bar-root-default" ) ) {
return;
}

Expand All @@ -17,7 +17,7 @@
} ).then( function ( response ) {
return response.text();
} ).then( function ( pageSource ) {
findEmails( pageSource );
appendToAdminbar( findEmails( pageSource ) );
} ).catch( function () {
//
} );
Expand All @@ -36,29 +36,31 @@
emails.push( match[ 0 ] );
}

var adminbar = document.getElementById( "wp-admin-bar-root-default" );
return emails;
};

if ( ! adminbar || ! emails.length ) {
var appendToAdminbar = function ( emails ) {
if ( ! emails.length ) {
return;
}

var url = encodeURIComponent( window.location.href );
var scannerUrl = "https://encoder.till.im/scanner?utm_source=wp-plugin&utm_medium=adminbar";

var text = emails.length === 1
? eaeDetectorL10n.one_email
: eaeDetectorL10n.many_emails.replace( "{number}", emails.length );

var a = document.createElement( "a" );
a.setAttribute( "class", "ab-item" );
a.setAttribute( "href", "https://encoder.till.im/scanner?utm_source=wp-plugin&utm_medium=adminbar&url=" + url );
a.setAttribute( "href", scannerUrl + "&url=" + encodeURIComponent( window.location.href ) );
a.appendChild( document.createTextNode( text ) );

var li = document.createElement( "li" );
li.setAttribute( "id", "wp-admin-bar-eae" );
li.setAttribute( "class", "" );
li.appendChild( a );

adminbar.appendChild( li );
document.getElementById( "wp-admin-bar-root-default" ).appendChild( li );
};

if ( document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading" ) {
Expand Down

0 comments on commit 9c08dc7

Please sign in to comment.