Skip to content

Instantly share code, notes, and snippets.

@Gerrit0
Created May 24, 2016 17:33
Show Gist options
  • Save Gerrit0/9379138c30d159b4734a1db298284540 to your computer and use it in GitHub Desktop.
Save Gerrit0/9379138c30d159b4734a1db298284540 to your computer and use it in GitHub Desktop.
Adds a button to Inbox by Gmail's interface, allowing you to easily insert a signature at the current cursor position
// ==UserScript==
// @name Inbox Signatures
// @namespace http://gerritbirkeland.com/
// @version 1.0
// @description Adds a button to Inbox by Gmail's compose dialog to add a signature.
// @author Gerrit0
// @match https://inbox.google.com/*
// @grant none
// ==/UserScript==
/*jshint
esnext: true
*/
(function() {
let config = {
interval: 500,
signature: `Sincerely,<br><br>Gerrit<br><a href="mailto:gerrit@gerritbirkeland.com">gerrit@gerritbirkeland.com</a><br><br>`,
};
document.head.innerHTML += `<style>
.sig_pic:after { content: '✎'; }
.sig_pic { height: 20px; width: 20px; }
</style>`;
let addSig = (event) => {
console.log(event);
let range = document.getSelection().getRangeAt(0);
let nnode = document.createElement('span');
range.surroundContents(nnode);
nnode.innerHTML = config.signature;
event.stopPropagation();
};
let checkNeeded = () => {
Array.from(document.querySelectorAll('.h3')).forEach((bar) => {
if (bar.querySelector('.sig_pic') === null) {
bar.querySelector('.n').innerHTML += `<div class="g-W g-W-DKlKme" tabindex="-1" style="-webkit-user-select: none;">
<div class="g-W-Cw g-W-Cw-mD g-mu-sE" aria-disabled="true" role="separator" style="-webkit-user-select: none;">&nbsp;</div>
<div class="g-mu-sE g-W-K" title="Append signature" role="button" aria-pressed="false" id="+link" tabindex="0" style="-webkit-user-select: none;">
<div class="g-mu-sE g-W-K-Ig-lc" style="-webkit-user-select: none;">
<div class="g-mu-sE g-W-K-s1-lc" style="-webkit-user-select: none;">
<div class="sig_pic" style="-webkit-user-select: none;"></div>
</div>
</div>
</div>
</div>`;
bar.querySelector('.sig_pic').addEventListener('click', addSig);
}
});
};
setInterval(checkNeeded, config.interval);
}());
@Gerrit0
Copy link
Author

Gerrit0 commented May 24, 2016

To do: Add support for inline replies. Currently this only works in the popup box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment