Skip to content

Instantly share code, notes, and snippets.

@balazs-endresz
Last active August 23, 2016 09:43
Show Gist options
  • Save balazs-endresz/41b1287f79578a3bba39 to your computer and use it in GitHub Desktop.
Save balazs-endresz/41b1287f79578a3bba39 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name projects.torchbox.com tweaks
// @namespace https://projects.torchbox.com/
// @version 2
// @match https://torchbox.codebasehq.com/*
// @match https://projects.torchbox.com/*
// @grant none
// @noframes
// ==/UserScript==
/* jshint -W097 */
'use strict';
/*
Remove codebasehq urls from the Chrome browser history:
chrome://history-frame/#q=codebasehq.com
open dev console
$$('.search-results input').forEach(function(e){ e.checked = true; e.setAttribute('checked', 'checked'); }); $('remove-selected').removeAttribute('disabled'); $('remove-selected').click();
*/
// redirect to projects.torchbox.com
if(location.hostname == 'torchbox.codebasehq.com'){
$('body').text('Redirecting to projects.torchbox.com ...').css({fontSize: '2em', padding: '2em'});
location.hostname = 'projects.torchbox.com';
}
$(function(){
// fix links: torchbox.codebasehq.com -> projects.torchbox.com
$('a[href*="torchbox.codebasehq.com"]').each(function(){
var $this = $(this);
var href = $this.attr('href');
href = href.replace('torchbox.codebasehq.com', 'projects.torchbox.com');
$this.attr('href', href);
});
// remove redirects from links that point to another comment on the same page
// e.g. https://projects.torchbox.com/redirect?https://projects.torchbox.com/projects/project/tickets/4364#update-28433324
$('a[href^="https://projects.torchbox.com/redirect?https://projects.torchbox.com"]').each(function(){
var $this = $(this);
var href = $this.attr('href');
href = href.replace('https://projects.torchbox.com/redirect?', '');
$this.attr('href', href);
$this.removeAttr('target');
});
// show url when hovering over external links
$('a[href^="https://projects.torchbox.com/redirect?"]').each(function(){
var $this = $(this);
var url = $this.attr('href').replace('https://projects.torchbox.com/redirect?', '');
$this.attr('title', url);
});
// fix "Tickets" link in breadcrumbs: sometimes it points to https://projects.torchbox.com/tickets/
// instead of the project specific ticket list
if(location.href.indexOf('/projects/') != -1){
var href = 'https://projects.torchbox.com/projects/' + Codebase.currentProject + '/tickets/';
$('a[href="/tickets"]').attr('href', href);
}
// add red border for private posts
$('.Post--full.is-private .box--medium').css({borderColor: '#FFC1C1'});
// When adding a private post remove all fields but the comment area.
// This ensures no changes will be made that would result in
// an email sent to the client with a post that they can't see.
var $tabs;
$('#tickets_update_updates_private').change(function(){
if($(this).is(':checked')){
$tabs = $('#new_tickets_update .PostForm__content + .js-tabs').detach();
$('#new_tickets_update > .box--medium, .Thread__header .TicketProperties, .Thread__header .ThreadMeta').css({borderColor: '#FFC1C1'});
$('.Thread__header .ThreadMeta').css({backgroundColor: '#fff0f4'});
}else{
$('#new_tickets_update .PostForm__content').after($tabs);
$('html, body').scrollTop($('body').scrollTop() + $tabs.height());
$('#new_tickets_update > .box--medium, .Thread__header .TicketProperties, .Thread__header .ThreadMeta').css({borderColor: '#d7d7d7'});
$('.Thread__header .ThreadMeta').css({backgroundColor: '#fff'});
}
});
// Focus on textarea when clicking on preview, and also show warning.
$('.preview').click(function(){
$(this).prev('textarea').focus();
var bgColour = $(document.body).css('backgroundColor');
$(this).animate({backgroundColor:'#F44336'}, 100, function(){ $(this).animate({backgroundColor: bgColour}, 100) });
});
// Disable keyboard shortcuts: most annoying one is the D key (without Ctrl!), which takes you to the homapage
$([window, document, document.body]).off('keypress keyup keydown');
// Add custom keyboard shortcuts
// N.B. this loads jquery.hotkeys.js from a third-party site (https://rawgit.com/), and not from Github.
$.getScript('https://cdn.rawgit.com/jeresig/jquery.hotkeys/master/jquery.hotkeys.js', function(){
// Ctrl+Alt+P opens the project selector
$(document).on('keyup', null, 'alt+ctrl+p', function(){
$('.js-ps-button').click();
$('html, body').animate({ scrollTop: 0 }, 'fast');
});
// start tabindex with overview/repos/tickets/etc + trigger click on pressing enter
$('.main-menu__item').each(function(i){
$(this).attr('tabindex', i + 1);
$(this).on('keyup', null, 'return', function(){
$('a', this)[0].click();
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment