// ==UserScript==
// @name           Delegate to Todoist
// @namespace      icr@delegate-to-todoist.com
// @description    Adds a "Delegate to Todoist" button to Gmail.
// @include        http://mail.google.com/mail/*
// @include        https://mail.google.com/mail/*
// ==/UserScript==
window.addEventListener('load', function() {
  var replyOrForwardLink = document.getElementById("sm_2") || document.getElementById("sm_4");
  if (replyOrForwardLink != null) {
    var td = document.createElement("td");
    td.setAttribute("class", "ilc");
    td.setAttribute("onclick", "javascript: (function() { var doc = top.document; if(top.js && top.js.document) doc = top.js.document; var script = doc.createElement('script'); doc.todoist_script = script; script.type = 'text/javascript'; script.src = 'http://todoist.com/getGmailJavaScript'; doc.getElementsByTagName('head')[0].appendChild(script); })(); void(0);");
    var text = document.createTextNode("Delegate to Todoist");
    td.appendChild(text);

    replyOrForwardLink.parentNode.appendChild(td);
  }
}, true);