Created
May 24, 2016 17:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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;"> </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); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To do: Add support for inline replies. Currently this only works in the popup box.