Sampath Liyanage
Sampath Liyanage

Reputation: 4896

Detecting email in gmail inbox with chrome extention

I'm trying to develop a chrome extension to interact with an email inside gmail inbox. I want to detect if an email of gmail inbox is opened on chrome browser.

Currently what I'm doing is checking if the prefix of url is mail.google.com/mail and if the url contains the term inbox (assuming url always will be something like https://mail.google.com/mail/u/0/#inbox/14f045t34g66rc02). But I recently found that the term inbox is not always there when user opens an email inside gmail inbox. For an example if user has custom labels, that label goes to url instead of the term inbox. Also if user searches before opening the email the word search goes to the url instead of the term inbox.

Is there a standard way to do this? Or any stable way?

Upvotes: 1

Views: 252

Answers (1)

Sriram
Sriram

Reputation: 9494

One of the things that I have used to identify if the gmail page is email content is to look for the reply icon. Reply icon is a img tag with background property set to png sprite with -711px

no-repeat url(//ssl.gstatic.com/mail/sprites/general-38d583f1fd064eadd1975a8bdef3ef93.png) 0 -711px

you can use the jquery css selector like below given pseudo code

$('img').each(function() {
    var backgroundValue = $(this).css('background');
    if(backgroundValue.indexOf('//ssl.gstatic.com/mail/sprites/general-38d583f1fd064eadd1975a8bdef3ef93.png') > -1 && backgroundValue.indexOf('-711px') > -1) {
        //this is reply button, so page is email content
        break;
    }
});

Upvotes: 0

Related Questions