changed gmail and outlook, now open new tab

This commit is contained in:
Matteo Manzinello 2019-05-20 17:54:45 +02:00
parent 7f6879bfd6
commit 2a34df709f
3 changed files with 118 additions and 22 deletions

60
dist/mailgo.js vendored
View File

@ -84,6 +84,7 @@ var mailgoInit = function mailgoInit() {
var gmail = document.createElement("a");
gmail.id = "mailgo-gmail";
gmail.href = "#mailgo-gmail";
gmail.classList.add("mailgo-open");
gmail.classList.add("mailgo-gmail");
var gmailContent = document.createTextNode("open in ");
@ -97,6 +98,7 @@ var mailgoInit = function mailgoInit() {
var outlook = document.createElement("a");
outlook.id = "mailgo-outlook";
outlook.href = "#mailgo-outlook";
outlook.classList.add("mailgo-open");
outlook.classList.add("mailgo-outlook");
var outlookContent = document.createTextNode("open in ");
@ -214,21 +216,42 @@ var mailgoRender = function mailgoRender(mailgo) {
subject ? (subjectEl.style.display = "block", subjectValueEl.textContent = subject) : subjectEl.style.display = "none";
bodyMail ? (bodyEl.style.display = "block", bodyValueEl.textContent = bodyMail) : bodyEl.style.display = "none"; // add the actions
gmailButton.href = "https://mail.google.com/mail?extsrc=mailto&url=" + encodeURIComponent(mailtoHref);
outlookButton.href = "https://outlook.office.com/owa/?rru=compose&to=" + encodeURIComponent(mail) + url.search.replace(/^[$]/, "&");
gmailButton.addEventListener("click", function () {
openGmailAction(mailtoHref);
}, false);
outlookButton.addEventListener("click", function () {
openOutlookAction(mail, url);
}, false);
var encEmail = encodeEmail(mail);
openButton.addEventListener("click", function () {
mailToEncoded(encEmail);
openDefaultAction(encEmail);
}, false);
copyButton.addEventListener("click", function (event) {
copyToClipboard(mail);
copyButton.textContent = "copied";
setTimeout(function () {
copyButton.textContent = "copy";
}, 999);
copyAction(mail, copyButton);
}, false); // show the mailgo
showMailgo();
}; // actions
var openGmailAction = function openGmailAction(mailtoHref) {
window.open("https://mail.google.com/mail?extsrc=mailto&url=" + encodeURIComponent(mailtoHref), "_blank");
};
var openOutlookAction = function openOutlookAction(mail, url) {
window.open("https://outlook.office.com/owa/?rru=compose&to=" + encodeURIComponent(mail) + url.search.replace(/^[$]/, "&"), "_blank");
};
var openDefaultAction = function openDefaultAction(encEmail) {
mailToEncoded(encEmail);
};
var copyAction = function copyAction(mail, copyButton) {
copyToClipboard(mail);
copyButton.textContent = "copied";
var timeout = setTimeout(function () {
copyButton.textContent = "copy";
}, 999);
};
/**
* mailgoCheckRender
@ -269,6 +292,27 @@ var mailgoKeydown = function mailgoKeydown(event) {
hideMailgo();
break;
case 71:
// g -> open GMail
hideMailgo();
break;
case 79:
// o -> open Outlook
hideMailgo();
break;
case 32:
case 13:
// spacebar or enter -> open default
hideMailgo();
break;
case 67:
// c -> copy
hideMailgo();
break;
default:
return;
}

2
dist/mailgo.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -93,6 +93,7 @@ const mailgoInit = () => {
// Gmail
let gmail = document.createElement("a");
gmail.id = "mailgo-gmail";
gmail.href = "#mailgo-gmail";
gmail.classList.add("mailgo-open");
gmail.classList.add("mailgo-gmail");
let gmailContent = document.createTextNode("open in ");
@ -108,6 +109,7 @@ const mailgoInit = () => {
// Outlook
let outlook = document.createElement("a");
outlook.id = "mailgo-outlook";
outlook.href = "#mailgo-outlook";
outlook.classList.add("mailgo-open");
outlook.classList.add("mailgo-outlook");
let outlookContent = document.createTextNode("open in ");
@ -272,20 +274,27 @@ const mailgoRender = mailgo => {
: (bodyEl.style.display = "none");
// add the actions
gmailButton.href =
"https://mail.google.com/mail?extsrc=mailto&url=" +
encodeURIComponent(mailtoHref);
gmailButton.addEventListener(
"click",
() => {
openGmailAction(mailtoHref);
},
false
);
outlookButton.href =
"https://outlook.office.com/owa/?rru=compose&to=" +
encodeURIComponent(mail) +
url.search.replace(/^[$]/, "&");
outlookButton.addEventListener(
"click",
() => {
openOutlookAction(mail, url);
},
false
);
let encEmail = encodeEmail(mail);
openButton.addEventListener(
"click",
() => {
mailToEncoded(encEmail);
openDefaultAction(encEmail);
},
false
);
@ -293,11 +302,7 @@ const mailgoRender = mailgo => {
copyButton.addEventListener(
"click",
event => {
copyToClipboard(mail);
copyButton.textContent = "copied";
setTimeout(() => {
copyButton.textContent = "copy";
}, 999);
copyAction(mail, copyButton);
},
false
);
@ -306,6 +311,36 @@ const mailgoRender = mailgo => {
showMailgo();
};
// actions
let openGmailAction = mailtoHref => {
window.open(
"https://mail.google.com/mail?extsrc=mailto&url=" +
encodeURIComponent(mailtoHref),
"_blank"
);
};
let openOutlookAction = (mail, url) => {
window.open(
"https://outlook.office.com/owa/?rru=compose&to=" +
encodeURIComponent(mail) +
url.search.replace(/^[$]/, "&"),
"_blank"
);
};
let openDefaultAction = encEmail => {
mailToEncoded(encEmail);
};
let copyAction = (mail, copyButton) => {
copyToClipboard(mail);
copyButton.textContent = "copied";
let timeout = setTimeout(() => {
copyButton.textContent = "copy";
}, 999);
};
/**
* mailgoCheckRender
* function to check if an element is mailgo-enabled or not referencing to the old
@ -350,6 +385,23 @@ const mailgoKeydown = event => {
// Escape
hideMailgo();
break;
case 71:
// g -> open GMail
hideMailgo();
break;
case 79:
// o -> open Outlook
hideMailgo();
break;
case 32:
case 13:
// spacebar or enter -> open default
hideMailgo();
break;
case 67:
// c -> copy
hideMailgo();
break;
default:
return;
}