Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking another approach #10

Open
jrmgx opened this issue Jul 14, 2018 · 5 comments
Open

Checking another approach #10

jrmgx opened this issue Jul 14, 2018 · 5 comments

Comments

@jrmgx
Copy link

jrmgx commented Jul 14, 2018

That's funny I have the same problem as you – need a link for a given email – and I found you on stackoverflow then, your chrome extension here.

Anyway I wanted to improve a little bit this extension and while doing it I found another working approach, let me explain:

  • I use the content script too
  • I hijack the "Show original" button in inbox email menu
  • When that page open the script kicks-in and get the message id from that email
  • It builds a valid inbox search url and copy it to the clipboard
  • Finally auto close the "show original" page

Advantages:

  • This gives you a google inbox link to that email
  • It seems to be quite resilient to inbox markup changes

Inconvenients:

  • Open/close a page
  • Not so well integrated into inbox

Evolution:

  • Instead of opening the page, the extension could intercept it and do the job without messing up tabs
  • It could be nice to change the "Show original" entry to reflect the new action or add an entry to that menu

I join the code here as a fork does not have sense (code 100% new)

/* content.js */
function parseParams() {
    var query = location.search.substr(1);
    var result = {};
    query.split("&").forEach(function(part) {
        var item = part.split("=");
        result[item[0]] = decodeURIComponent(item[1]);
    });
    return result;
}

function copyTextToClipboard(text) {
    var copyFrom = document.createElement("textarea");
    copyFrom.textContent = text;
    document.body.appendChild(copyFrom);
    copyFrom.select();
    document.execCommand('copy');
    copyFrom.blur();
    document.body.removeChild(copyFrom);
}

var params = parseParams();
if (params.view && params.view == "om" && params.ik && params.permmsgid) {
    var d = document.querySelectorAll('td.message_id');
    if (d && d.length >= 1) {
        var id = d[0].innerText;
        copyTextToClipboard("https://inbox.google.com/search/rfc822msgid%3A" + id);
        window.close();
    }
}

manifest need a new permission: clipboardWrite

@adrienjoly
Copy link
Owner

adrienjoly commented Jul 15, 2018

Hello Jérôme ! ^^

Your approach is interesting.

Once you extracted the email-id, how do you build the "valid inbox search url"?

E.g. the message id I found in the notification email triggered by this issue that you posted was <adrienjoly/chrome-inbox-permalinks/issues/[email protected]>, but the URL https://inbox.google.com/search/rfc822msgid%3A%3Cadrienjoly/chrome-inbox-permalinks/issues/[email protected]%3E is a 404. 🤔

Does this code work as expected? If so I'd love to see a short screencast that shows it in action, and way to install this extension without having to create it myself from your code snippet ^^

@jrmgx
Copy link
Author

jrmgx commented Jul 15, 2018

see https://github.com/jrmgx/chrome-inbox-permalinks for a working version
Install the extension, reload inbox, then use the "Show original" option of any email and you'll have the link for that email copied in your clipboard.
Tested with last chrome and last vivaldi.
Other comments from my first message still apply (need polishing)

@adrienjoly
Copy link
Owner

I just tried it. Unfortunately the URL that was generated from one of my emails (the one I mentioned on a previous comment above) does not work: https://inbox.google.com/u/0/search/rfc822msgid%3A%3Cadrienjoly/chrome-inbox-permalinks/issues/[email protected]%3E

image

@jrmgx
Copy link
Author

jrmgx commented Jul 17, 2018

It gives me:

https://inbox.google.com/search/rfc822msgid%3A<5b4cb04db515d_42ab24a1853181235c4%40fb84a5df-efc0-4488-bc94-828ee2552c83.mail>

a little bit different from the one you have, note the /u/0 part and also < and > not escaped on my side but @ is ... it seems that the escaping behave differently. Weird.

I confirm it works with a like like this one,
maybe you could forge one to test and then we could check what is wrong with the escaping?

@adrienjoly
Copy link
Owner

adrienjoly commented Jul 17, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants