Last active
August 29, 2015 14:08
-
-
Save BenjaminRH/edc12916cd788bdb6df9 to your computer and use it in GitHub Desktop.
Gmail Github Issue userscript. Adds a "+Issue" link at the top of Gmail email threads that will create a new Github issue from all expanded emails in that thread. Substitute the desired issue repository for the default one at the top of the file.
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== | |
// @id gmailgithubissuescript@userscripts.org | |
// @name Gmail GitHub Issue | |
// @version 1.2 | |
// @release 2014-10-29 | |
// @author Benjamin Harris | |
// @namespace gmailgithubissuescript@userscripts.org | |
// @description Create a GitHub issue from Gmail | |
// @include https://mail.google.com/mail/u/* | |
// @match https://mail.google.com/mail/u/* | |
// ==/UserScript== | |
var repository = 'totango/main'; | |
// INSERT BUTTON | |
function insertButton() { | |
var $container = document.getElementsByClassName('ade')[0]; | |
var $button = document.createElement('span'); | |
$button.class = 'hk J-J5-Ji'; | |
$button.innerHTML = '<span class="hk J-J5-Ji">' + | |
'<div class="T-I J-J5-Ji T-I-JN L3" role="button" data-tooltip="Create a GitHub Issue" aria-label="Create a GitHub Issue">' + | |
'<span class="SD"><a id="create-github-issue" href="#" target="_blank">+Issue</a></span>' + | |
'</div>' + | |
'</span>'; | |
$container.appendChild($button); | |
document.getElementById('create-github-issue').onclick = function() { | |
var email = getEmail(); | |
this.href = 'https://github.com/' + repository + '/issues/new' + '?title=' + encodeURIComponent(email.title) + '&body=' + encodeURIComponent(email.body); | |
}; | |
} | |
// GET EMAIL INFO | |
function getEmail() { | |
var email = {}; | |
email.title = document.getElementsByClassName('ha')[0].getElementsByTagName('h2')[0].innerText; | |
email.body = ''; | |
var $notes = document.getElementsByClassName('ii gt'); | |
var $note, author; | |
for (var i = 0; i < $notes.length; i++) { | |
$note = $notes[i]; | |
if ($note.style.display !== 'none') { | |
author = $note.parentElement.getElementsByClassName('iw')[0].innerText; | |
email.body += '\n' + Array(20 + 1).join('=') + '\n' + author + '\n' + Array(10 + 1).join('-') + '\n'; | |
email.body += $note.innerText; | |
email.body += '\n\n'; | |
} | |
} | |
email.body = email.body.replace(/\n{3,}/img, '\n\n\n').trim(); | |
return email; | |
} | |
// HANDLE INSERTION LOGIC | |
function setupScript() { | |
if (document.getElementsByClassName('ade').length > 0) { | |
insertButton(); | |
} | |
} | |
// :::::BEGIN APPLICATION::::: | |
(function() { | |
console.log('Running Gmail Github Issue userscript!'); | |
window.onhashchange = setupScript; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment