Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ function documentInformationAgent () {
setTimeout(EICheck, 500);
}else{
var locationInfo = location.href.match(/\/(\w+?)$/);

if(locationInfo && locationInfo[1]){
var threadIdElement = document.querySelector("h2[data-legacy-thread-id]")

if(threadIdElement && threadIdElement.dataset){

var auth = window.GLOBALS[9],
emailId = locationInfo[1];
threadId = threadIdElement.dataset.legacyThreadId

window.EIxhr = new XMLHttpRequest();
EIxhr.onreadystatechange = function () {
Expand All @@ -19,18 +20,18 @@ function documentInformationAgent () {
}
};

EIxhr.open("GET", document.location.origin + document.location.pathname + "?view=om&ui=2&ik=" + auth + "&th=" + emailId, true);
EIxhr.open("GET", document.location.origin + document.location.pathname + "?view=om&ui=2&ik=" + auth + "&th=" + threadId, true);

EIxhr.send();

}
}
} catch (e) {}
}

window.onpopstate = EICheck;

// A bad way to try to check on initial page load
document.onload = setTimeout(EICheck, 2000);
document.onload = setTimeout(EICheck, 3000);
}

// Inject Information Agent
Expand All @@ -39,14 +40,13 @@ informationAgentScript.appendChild(document.createTextNode('('+ documentInformat
(document.body || document.head || document.documentElement).appendChild(informationAgentScript);

window.addEventListener("message", function(event) {

// Only accept messages from the window
if (event.source != window)
return;

// Make sure it's the right message
if (event.data.type && (event.data.type == "ei-mail-raw")) {

var rawEmail = event.data.raw,
service = {};

Expand Down Expand Up @@ -91,7 +91,7 @@ window.addEventListener("message", function(event) {
}

// ExactTarget
if( rawEmail.match(/^x-job: \d{3,}_\d{3,}$/m) && rawEmail.match(/mta[\d]*\.[\w-\.]+\.[a-z]{2,}/i) ) { // Two checks as x-job is not proprietary
if( rawEmail.match(/^x-job: \d{3,}_\d{3,}$/m) && rawEmail.match(/mta[\d]*\.[\w-\.]+\.[a-z]{2,}/i) ) { // Two checks as x-job is not proprietary
service = {name: "ExactTarget", url: "http://www.exacttarget.com/"};
}

Expand Down Expand Up @@ -129,12 +129,12 @@ window.addEventListener("message", function(event) {
if( rawEmail.match(/^X-MC-User:/m) ) {
service = {name: "MailChimp", url: "https://mailchimp.com/"};
}

// MailerLite
if( rawEmail.match(/d=ml.mailersend.com;/) ) {
service = {name: "MailerLite", url: "https://www.mailerlite.com/"};
}

// Mailgun
if( rawEmail.match(/^X-Mailgun-Sid:/m) ) {
service = {name: "Mailgun", url: "https://www.mailgun.com/"};
Expand Down Expand Up @@ -221,6 +221,7 @@ window.addEventListener("message", function(event) {

// Attempt to find the place to put the icon in the gmail interface
var has = document.getElementsByClassName("ha");

for (var i = has.length - 1; i >= 0; i--) {
if(has[i].getElementsByTagName("span")){

Expand All @@ -235,9 +236,11 @@ window.addEventListener("message", function(event) {
serviceIcon.setAttribute("style", "top:1px");

serviceLink.appendChild(serviceIcon);

has[i].getElementsByTagName("span")[0].appendChild(serviceLink);
return;


has[i].getElementsByTagName("span")[0].insertAdjacentElement("afterend", serviceLink);

return false;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"name": "Email Intelligence",
"description": "Email Intelligence displays which email infrastructure provider sent an email to your gmail account.",
"version": "1.0.6",
"version": "1.0.7",

"content_scripts": [
{
Expand Down