Skip to content

Instantly share code, notes, and snippets.

@andresbravog
Last active December 30, 2015 00:19
Show Gist options
  • Save andresbravog/7748533 to your computer and use it in GitHub Desktop.
Save andresbravog/7748533 to your computer and use it in GitHub Desktop.
[Tampermonkey] Teambox helpdesk helper
// ==UserScript==
// @name Teambox Helpdesk Script
// @namespace http://redbooth.com/helpdesk
// @version 0.2.1
// @description enter something useful
// @match http://localhost:8000/a/index.html
// @match http://teambox.com/a*
// @match https://teambox.com/a*
// @match http://redbooth.com/a*
// @match https://redbooth.com/a*
// @copyright 2012+, You
// ==/UserScript==
Teambox.addInitializer(function () {
var List = Teambox.Views.Comments.List.prototype;
var original_render = Teambox.Views.Comments.List.prototype.onRender || $.noop;
var regex = /(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/g;
var original_template = Templates['comments.cmenu-content'] || function () { return ''; };
List.onRender = function () {
// TODO: This should be based on an event, not a defer.
// I used the defer because I need the comment list to be attached to the task when we process the support helper
var self = this;
_.delay(function () {
self.renderSupportHelper();
});
return original_render.apply(this, _.toArray(arguments));
};
List.renderSupportHelper = function () {
var $task = this.$el.parents(".cb")
, $header = $task.find(".js-element")
, $comments = $task.find(".js-list");
$header.find(".js-support-helper").remove();
_.each($comments.text().match(regex), function (email) {
var $p = $("<p class='js-support-helper'></p>")
, $profile = $("<a class='mention' href='/reports/users/" + email + "'>" + email + "</a> ");
// This opens the /reports/users/[email protected] iframe inside a dialog
$profile.click(function (e) {
e.preventDefault();
var dialog = new Teambox.Views.Dialogs.Dialog({ header: "User profile" });
dialog.render().open();
dialog.$(".js-dialog-body").html(
"<iframe src='https://teambox.com/reports/users/" + email +
"' style='border:none;width:100%; height: 500px'></iframe>"
);
});
$p.append($profile);
// This opens the SFDC search
// This opens the Intercom search. In the future, we'll move it to the /reports/users/123 view
$p.append(" <a class='mention' target='_blank' href='https://eu1.salesforce.com/_ui/search/ui/UnifiedSearchResults?searchType=2&sen=00Q&sen=001&sen=003&str=" + email + "'>SFDC</a> ");
// This opens the Intercom search. In the future, we'll move it to the /reports/users/123 view
$p.append(" <a class='mention' target='_blank' href='https://www.intercom.io/apps/66617f249a288e3091c68c031a46349ffcf65dbf/users?utf8=%E2%9C%93&search=" + email + "'>Intercom</a> ");
// Searches on Teambox for other tasks who mention this user's email. If there are 2 or more, display a link to search.
$.get("/api/2/search?q=" + email, function (related) {
if (related.total_entries > 1) {
$p.append(" <a href='#!/search?query=" + email + "' class='mention mention-icon mention_task'>See <strong>" + (related.total_entries - 1) + " more tasks</strong></a> ");
}
});
$header.after($p);
});
};
Templates['comments.cmenu-content'] = function (locals) {
var base = original_template.apply(this, _.toArray(arguments));
return '<a href="/reports/emails?comment_id=' + locals.model.id + '" class="js-item tb-cmenu-list-item" target="_new">'+
jade.escape( '[' + locals.model.id + '] see emails report' ) +
'</a>' +
base;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment